mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-26 17:54:54 +00:00
door sensor
This commit is contained in:
33
lib/features/devices/model/door_sensor_model.dart
Normal file
33
lib/features/devices/model/door_sensor_model.dart
Normal file
@ -0,0 +1,33 @@
|
||||
|
||||
|
||||
|
||||
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user