import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart'; import 'package:syncrow_web/utils/constants/const.dart'; class AcStatusModel { bool acSwitch; String modeString; int tempSet; int currentTemp; String fanSpeedsString; bool childLock; // late TempModes acMode; // late FanSpeeds acFanSpeed; AcStatusModel( {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(List 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( 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; } } }