Files
syncrow-app/lib/features/devices/model/water_leak_model.dart
2024-10-08 10:11:08 +03:00

29 lines
799 B
Dart

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