mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 01:35:23 +00:00
91 lines
2.6 KiB
Dart
91 lines
2.6 KiB
Dart
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
|
|
|
class AcStatusModel {
|
|
String uuid;
|
|
bool acSwitch;
|
|
String modeString;
|
|
int tempSet;
|
|
int currentTemp;
|
|
String fanSpeedsString;
|
|
bool childLock;
|
|
late TempModes acMode;
|
|
late FanSpeeds acFanSpeed;
|
|
int countdown1;
|
|
|
|
AcStatusModel(
|
|
{required this.uuid,
|
|
required this.acSwitch,
|
|
required this.modeString,
|
|
required this.tempSet,
|
|
required this.countdown1,
|
|
required this.currentTemp,
|
|
required this.fanSpeedsString,
|
|
required this.childLock}) {
|
|
acMode = getACMode(modeString);
|
|
acFanSpeed = getFanSpeed(fanSpeedsString);
|
|
}
|
|
|
|
factory AcStatusModel.fromJson(String id, List<StatusModel> jsonList) {
|
|
late bool _acSwitch;
|
|
late String _mode;
|
|
late int _tempSet;
|
|
late int _currentTemp;
|
|
late String _fanSpeeds;
|
|
late int _countdown1;
|
|
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;
|
|
} else if (jsonList[i].code == 'countdown_time') {
|
|
_countdown1 = jsonList[i].value ?? 0;
|
|
}
|
|
}
|
|
return AcStatusModel(
|
|
uuid: id,
|
|
acSwitch: _acSwitch,
|
|
modeString: _mode,
|
|
tempSet: _tempSet,
|
|
currentTemp: _currentTemp,
|
|
fanSpeedsString: _fanSpeeds,
|
|
countdown1: _countdown1,
|
|
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;
|
|
}
|
|
}
|
|
}
|