From 8a244dcd239ac31763b8265b54812227341ff79f Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Tue, 8 Apr 2025 15:08:15 +0300 Subject: [PATCH] Created `GatewayModel`. --- .../gateway/model/gateway_model.dart | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 lib/pages/device_managment/gateway/model/gateway_model.dart 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, + ); + } +}