mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 21:44:54 +00:00
Added three gang bloc, event, state, and model
This commit is contained in:
81
lib/features/devices/model/ac_model.dart
Normal file
81
lib/features/devices/model/ac_model.dart
Normal file
@ -0,0 +1,81 @@
|
||||
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.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<StatusModel> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,84 +1,3 @@
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.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<StatusModel> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class StatusModel {
|
||||
String? code;
|
||||
dynamic value;
|
||||
|
||||
50
lib/features/devices/model/three_gang_model.dart
Normal file
50
lib/features/devices/model/three_gang_model.dart
Normal file
@ -0,0 +1,50 @@
|
||||
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
||||
|
||||
class ThreeGangModel {
|
||||
bool firstSwitch;
|
||||
bool secondSwitch;
|
||||
bool thirdSwitch;
|
||||
int firstCountDown;
|
||||
int secondCountDown;
|
||||
int thirdCountDown;
|
||||
|
||||
ThreeGangModel(
|
||||
{required this.firstSwitch,
|
||||
required this.secondSwitch,
|
||||
required this.thirdSwitch,
|
||||
required this.firstCountDown,
|
||||
required this.secondCountDown,
|
||||
required this.thirdCountDown});
|
||||
|
||||
factory ThreeGangModel.fromJson(List<StatusModel> jsonList) {
|
||||
late bool _firstSwitch;
|
||||
late bool _secondSwitch;
|
||||
late bool _thirdSwitch;
|
||||
late int _firstCount;
|
||||
late int _secondCount;
|
||||
late int _thirdCount;
|
||||
|
||||
for (int i = 0; i < jsonList.length; i++) {
|
||||
if (jsonList[i].code == 'switch_1') {
|
||||
_firstSwitch = jsonList[i].value ?? false;
|
||||
} else if (jsonList[i].code == 'switch_2') {
|
||||
_secondSwitch = jsonList[i].value ?? false;
|
||||
} else if (jsonList[i].code == 'switch_3') {
|
||||
_thirdSwitch = jsonList[i].value ?? false;
|
||||
} else if (jsonList[i].code == 'countdown_1') {
|
||||
_firstCount = jsonList[i].value ?? 0;
|
||||
} else if (jsonList[i].code == 'countdown_2') {
|
||||
_secondCount = jsonList[i].value ?? 0;
|
||||
} else if (jsonList[i].code == 'countdown_3') {
|
||||
_thirdCount = jsonList[i].value ?? 0;
|
||||
}
|
||||
}
|
||||
return ThreeGangModel(
|
||||
firstSwitch: _firstSwitch,
|
||||
secondSwitch: _secondSwitch,
|
||||
thirdSwitch: _thirdSwitch,
|
||||
firstCountDown: _firstCount,
|
||||
secondCountDown: _secondCount,
|
||||
thirdCountDown: _thirdCount);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user