mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 01:35:23 +00:00
50 lines
1.5 KiB
Dart
50 lines
1.5 KiB
Dart
|
|
|
|
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
|
|
|
class OneTouchModel {
|
|
bool firstSwitch;
|
|
int firstCountDown;
|
|
status relay;
|
|
lightStatus light_mode;
|
|
status relay_status_1;
|
|
|
|
OneTouchModel(
|
|
{required this.firstSwitch,
|
|
required this.firstCountDown,
|
|
required this.light_mode,
|
|
required this.relay,
|
|
required this.relay_status_1});
|
|
|
|
factory OneTouchModel.fromJson(List<StatusModel> jsonList) {
|
|
late bool _switch;
|
|
late int _count;
|
|
late String _relay;
|
|
late String _light_mode;
|
|
late String relay_status_1;
|
|
|
|
for (int i = 0; i < jsonList.length; i++) {
|
|
if (jsonList[i].code == 'switch_1') {
|
|
_switch = jsonList[i].value ?? false;
|
|
} else if (jsonList[i].code == 'countdown_1') {
|
|
_count = jsonList[i].value ?? 0;
|
|
} else if (jsonList[i].code == 'relay_status') {
|
|
_relay = jsonList[i].value ?? 0;
|
|
} else if (jsonList[i].code == 'light_mode') {
|
|
_light_mode = jsonList[i].value ?? 0;
|
|
} else if (jsonList[i].code == 'relay_status_1') {
|
|
relay_status_1 = jsonList[i].value ?? 0;
|
|
}
|
|
}
|
|
return OneTouchModel(
|
|
firstSwitch: _switch,
|
|
firstCountDown: _count,
|
|
light_mode: lightStatusExtension.fromString(_light_mode) ,
|
|
relay: StatusExtension.fromString(_relay ) ,
|
|
relay_status_1: StatusExtension.fromString(relay_status_1 )
|
|
|
|
);
|
|
}
|
|
}
|