Files
syncrow-app/lib/features/devices/model/door_sensor_model.dart
2024-09-22 15:32:47 +03:00

34 lines
809 B
Dart

import 'package:syncrow_app/features/devices/model/status_model.dart';
class DoorSensorModel {
bool doorContactState;
int batteryPercentage;
DoorSensorModel(
{required this.doorContactState,
required this.batteryPercentage,
});
factory DoorSensorModel.fromJson(List<StatusModel> jsonList) {
late bool _doorContactState;
late int _batteryPercentage;
for (int i = 0; i < jsonList.length; i++) {
if (jsonList[i].code == 'doorcontact_state') {
_doorContactState = jsonList[i].value ?? false;
} else if (jsonList[i].code == 'battery_percentage') {
_batteryPercentage = jsonList[i].value ?? 0;
}
}
return DoorSensorModel(
doorContactState: _doorContactState,
batteryPercentage: _batteryPercentage,
);
}
}