diff --git a/lib/pages/device_managment/gateway/model/gateway_model.dart b/lib/pages/device_managment/gateway/model/gateway_model.dart new file mode 100644 index 00000000..8e8d00f9 --- /dev/null +++ b/lib/pages/device_managment/gateway/model/gateway_model.dart @@ -0,0 +1,40 @@ +class GatewayModel { + final String uuid; + final bool switchAlarmSound; + final String masterState; + final bool factoryReset; + final String alarmActive; + + GatewayModel({ + required this.uuid, + required this.switchAlarmSound, + required this.masterState, + required this.factoryReset, + required this.alarmActive, + }); + + factory GatewayModel.fromJson(Map json) { + final status = json['status'] as List; + + final switchAlarmSound = status.firstWhere( + (item) => item['code'] == 'switch_alarm_sound', + )['value'] as bool; + final masterState = status.firstWhere( + (item) => item['code'] == 'master_state', + )['value'] as String; + final factoryReset = status.firstWhere( + (item) => item['code'] == 'factory_reset', + )['value'] as bool; + final alarmActive = status.firstWhere( + (item) => item['code'] == 'alarm_active', + )['value'] as String; + + return GatewayModel( + uuid: json['uuid'] as String, + switchAlarmSound: switchAlarmSound, + masterState: masterState, + factoryReset: factoryReset, + alarmActive: alarmActive, + ); + } +}