mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 18:17:56 +00:00
door sensor
This commit is contained in:
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// Record model
|
||||
class Record {
|
||||
final String status;
|
||||
final String time;
|
||||
final bool isOpen;
|
||||
|
||||
Record({
|
||||
required this.status,
|
||||
required this.time,
|
||||
required this.isOpen,
|
||||
});
|
||||
}
|
||||
|
||||
// RecordGroup model to group records by date
|
||||
class RecordGroup {
|
||||
final DateTime date;
|
||||
final List<Record> records;
|
||||
|
||||
RecordGroup({
|
||||
required this.date,
|
||||
required this.records,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user