Files
syncrow-app/lib/features/devices/model/three_gang_model.dart
2024-05-21 01:51:53 +03:00

51 lines
1.6 KiB
Dart

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);
}
}