mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 01:35:23 +00:00
69 lines
2.3 KiB
Dart
69 lines
2.3 KiB
Dart
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
|
|
|
class WallSensorModel {
|
|
String presenceState;
|
|
int farDetection;
|
|
int presenceTime;
|
|
int motionSensitivity;
|
|
int motionlessSensitivity;
|
|
int currentDistance;
|
|
int illuminance;
|
|
bool indicator;
|
|
int noOneTime;
|
|
|
|
WallSensorModel(
|
|
{required this.presenceState,
|
|
required this.farDetection,
|
|
required this.presenceTime,
|
|
required this.motionSensitivity,
|
|
required this.motionlessSensitivity,
|
|
required this.currentDistance,
|
|
required this.illuminance,
|
|
required this.indicator,
|
|
required this.noOneTime});
|
|
|
|
factory WallSensorModel.fromJson(List<StatusModel> jsonList) {
|
|
late String _presenceState;
|
|
late int _farDetection;
|
|
late int _presenceTime;
|
|
late int _motionSensitivity;
|
|
late int _motionlessSensitivity;
|
|
late int _currentDistance;
|
|
late int _illuminance;
|
|
late bool _indicator;
|
|
late int _noOneTime;
|
|
|
|
for (int i = 0; i < jsonList.length; i++) {
|
|
if (jsonList[i].code == 'presence_state') {
|
|
_presenceState = jsonList[i].value ?? 'none';
|
|
} else if (jsonList[i].code == 'far_detection') {
|
|
_farDetection = jsonList[i].value ?? 0;
|
|
} else if (jsonList[i].code == 'presence_time') {
|
|
_presenceTime = jsonList[i].value ?? 0;
|
|
} else if (jsonList[i].code == 'motion_sensitivity_value') {
|
|
_motionSensitivity = jsonList[i].value ?? 0;
|
|
} else if (jsonList[i].code == 'motionless_sensitivity') {
|
|
_motionlessSensitivity = jsonList[i].value ?? 0;
|
|
} else if (jsonList[i].code == 'dis_current') {
|
|
_currentDistance = jsonList[i].value ?? 0;
|
|
} else if (jsonList[i].code == 'illuminance_value') {
|
|
_illuminance = jsonList[i].value ?? 0;
|
|
} else if (jsonList[i].code == 'indicator') {
|
|
_indicator = jsonList[i].value ?? false;
|
|
} else if (jsonList[i].code == 'no_one_time') {
|
|
_noOneTime = jsonList[i].value ?? 0;
|
|
}
|
|
}
|
|
return WallSensorModel(
|
|
presenceState: _presenceState,
|
|
farDetection: _farDetection,
|
|
presenceTime: _presenceTime,
|
|
motionSensitivity: _motionSensitivity,
|
|
motionlessSensitivity: _motionlessSensitivity,
|
|
currentDistance: _currentDistance,
|
|
illuminance: _illuminance,
|
|
indicator: _indicator,
|
|
noOneTime: _noOneTime);
|
|
}
|
|
}
|