Files
syncrow-web/lib/pages/device_managment/ac/model/ac_model.dart
ashrafzarkanisala d94ec25003 changing ac bloc
2024-08-26 00:48:29 +03:00

88 lines
2.4 KiB
Dart

import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
enum TempModes { hot, cold, wind }
enum FanSpeeds { auto, low, middle, high }
class AcStatusModel {
String uuid;
bool acSwitch;
String modeString;
int tempSet;
int currentTemp;
String fanSpeedsString;
bool childLock;
late TempModes acMode;
late FanSpeeds acFanSpeed;
AcStatusModel(
{required this.uuid,
required this.acSwitch,
required this.modeString,
required this.tempSet,
required this.currentTemp,
required this.fanSpeedsString,
required this.childLock}) {
acMode = getACMode(modeString);
acFanSpeed = getFanSpeed(fanSpeedsString);
}
factory AcStatusModel.fromJson(String id, List<Status> jsonList) {
late bool _acSwitch;
late String _mode;
late int _tempSet;
late int _currentTemp;
late String _fanSpeeds;
late bool _childLock;
for (int i = 0; i < jsonList.length; i++) {
if (jsonList[i].code == 'switch') {
_acSwitch = jsonList[i].value ?? false;
} else if (jsonList[i].code == 'mode') {
_mode = jsonList[i].value ?? TempModes.cold;
} else if (jsonList[i].code == 'temp_set') {
_tempSet = jsonList[i].value ?? 210;
} else if (jsonList[i].code == 'temp_current') {
_currentTemp = jsonList[i].value ?? 210;
} else if (jsonList[i].code == 'level') {
_fanSpeeds = jsonList[i].value ?? 210;
} else if (jsonList[i].code == 'child_lock') {
_childLock = jsonList[i].value ?? false;
}
}
return AcStatusModel(
uuid: id,
acSwitch: _acSwitch,
modeString: _mode,
tempSet: _tempSet,
currentTemp: _currentTemp,
fanSpeedsString: _fanSpeeds,
childLock: _childLock);
}
static TempModes getACMode(String value) {
if (value == 'cold') {
return TempModes.cold;
} else if (value == 'hot') {
return TempModes.hot;
} else if (value == 'wind') {
return TempModes.wind;
} else {
return TempModes.cold;
}
}
static FanSpeeds getFanSpeed(String value) {
if (value == 'low') {
return FanSpeeds.low;
} else if (value == 'middle') {
return FanSpeeds.middle;
} else if (value == 'high') {
return FanSpeeds.high;
} else if (value == 'auto') {
return FanSpeeds.auto;
} else {
return FanSpeeds.auto;
}
}
}