mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 01:35:23 +00:00
64 lines
2.2 KiB
Dart
64 lines
2.2 KiB
Dart
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
|
|
|
class TwoTouchModel {
|
|
bool firstSwitch;
|
|
bool secondSwitch;
|
|
int firstCountDown;
|
|
int secondCountDown;
|
|
status relay;
|
|
lightStatus light_mode;
|
|
status relay_status_1;
|
|
status relay_status_2;
|
|
|
|
TwoTouchModel(
|
|
{required this.firstSwitch,
|
|
required this.secondSwitch,
|
|
required this.firstCountDown,
|
|
required this.secondCountDown,
|
|
required this.light_mode,
|
|
required this.relay,
|
|
required this.relay_status_1,
|
|
required this.relay_status_2});
|
|
|
|
factory TwoTouchModel.fromJson(List<StatusModel> jsonList) {
|
|
late bool _firstSwitch;
|
|
late bool _secondSwitch;
|
|
late int _firstCount;
|
|
late int _secondCount;
|
|
late String _relay;
|
|
late String _light_mode;
|
|
late String _relay_status_1;
|
|
late String _relay_status_2;
|
|
|
|
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 == 'countdown_1') {
|
|
_firstCount = jsonList[i].value ?? 0;
|
|
} else if (jsonList[i].code == 'countdown_2') {
|
|
_secondCount = 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;
|
|
} else if (jsonList[i].code == 'relay_status_2') {
|
|
_relay_status_2 = jsonList[i].value ?? 0;
|
|
}
|
|
}
|
|
return TwoTouchModel(
|
|
firstSwitch: _firstSwitch,
|
|
secondSwitch: _secondSwitch,
|
|
firstCountDown: _firstCount,
|
|
secondCountDown: _secondCount,
|
|
light_mode: lightStatusExtension.fromString(_light_mode),
|
|
relay: StatusExtension.fromString(_relay),
|
|
relay_status_1: StatusExtension.fromString(_relay_status_1),
|
|
relay_status_2: StatusExtension.fromString(_relay_status_2));
|
|
}
|
|
}
|