From adb42f95e85415ce520f63a55c31abf2a890ac3e Mon Sep 17 00:00:00 2001 From: mohammad Date: Sun, 11 May 2025 16:33:11 +0300 Subject: [PATCH] Implement Flush Mounted Presence Sensor Routine Control and change the device type logic --- assets/icons/Illuminance_icon.svg | 18 + assets/icons/current_distance_icon.svg | 17 + assets/icons/delay_icon.svg | 17 + assets/icons/distance_icon.svg | 17 + assets/icons/level_icon.svg | 23 + assets/icons/nobody_time.svg | 4 + assets/icons/presence_state.svg | 18 + .../device_manager_bloc.dart | 3 +- .../bloc/create_scene/create_scene_bloc.dart | 2 + .../smart_scene_select_dart_bloc.dart | 2 +- .../functions_per_device/ac_functions.dart | 11 + .../door_lock_functions.dart | 19 +- .../flush_functions_helper.dart | 247 ++++++++ .../gateway_functions.dart | 3 + .../human_presence_functions.dart | 9 + .../functions_per_device/presence_sensor.dart | 4 + .../tow_gang_helper_functions.dart | 8 + .../water_heater_functions.dart | 6 + .../scene/helper/scene_logic_helper.dart | 35 ++ .../helper/scene_operations_data_helper.dart | 550 +++++++++++++++--- .../scene/model/create_scene_model.dart | 8 + .../scene/model/scene_details_model.dart | 57 +- .../scene/model/scene_static_function.dart | 10 +- .../scene/view/device_functions_view.dart | 24 +- .../alert_dialog_slider_steps.dart | 134 ++--- lib/generated/assets.dart | 5 + 26 files changed, 1071 insertions(+), 180 deletions(-) create mode 100644 assets/icons/Illuminance_icon.svg create mode 100644 assets/icons/current_distance_icon.svg create mode 100644 assets/icons/delay_icon.svg create mode 100644 assets/icons/distance_icon.svg create mode 100644 assets/icons/level_icon.svg create mode 100644 assets/icons/nobody_time.svg create mode 100644 assets/icons/presence_state.svg create mode 100644 lib/features/scene/helper/functions_per_device/flush_functions_helper.dart diff --git a/assets/icons/Illuminance_icon.svg b/assets/icons/Illuminance_icon.svg new file mode 100644 index 0000000..379c45f --- /dev/null +++ b/assets/icons/Illuminance_icon.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/assets/icons/current_distance_icon.svg b/assets/icons/current_distance_icon.svg new file mode 100644 index 0000000..d4c8760 --- /dev/null +++ b/assets/icons/current_distance_icon.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/assets/icons/delay_icon.svg b/assets/icons/delay_icon.svg new file mode 100644 index 0000000..c65fc5a --- /dev/null +++ b/assets/icons/delay_icon.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/assets/icons/distance_icon.svg b/assets/icons/distance_icon.svg new file mode 100644 index 0000000..d4c8760 --- /dev/null +++ b/assets/icons/distance_icon.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/assets/icons/level_icon.svg b/assets/icons/level_icon.svg new file mode 100644 index 0000000..56e343e --- /dev/null +++ b/assets/icons/level_icon.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/icons/nobody_time.svg b/assets/icons/nobody_time.svg new file mode 100644 index 0000000..df80b51 --- /dev/null +++ b/assets/icons/nobody_time.svg @@ -0,0 +1,4 @@ + + + + diff --git a/assets/icons/presence_state.svg b/assets/icons/presence_state.svg new file mode 100644 index 0000000..d5de48e --- /dev/null +++ b/assets/icons/presence_state.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/lib/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart b/lib/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart index 9d6b95e..04f6e17 100644 --- a/lib/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart +++ b/lib/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart @@ -179,7 +179,8 @@ class DeviceManagerBloc extends Bloc { DeviceType.ThreeGang, DeviceType.OneGang, DeviceType.TwoGang, - DeviceType.WH + DeviceType.WH, + DeviceType.FlushMountedSensor, }; return devices diff --git a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart index a96c7ce..a09fcfd 100644 --- a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart +++ b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart @@ -107,6 +107,7 @@ class CreateSceneBloc extends Bloc for (var element in tempTasksList) { if (element.code == event.deviceControlModel.code) { var updatedElement = element.copyWith( + deviceType: event.deviceType, operationName: event.operation, deviceName: event.deviceName, icon: event.icon, @@ -134,6 +135,7 @@ class CreateSceneBloc extends Bloc if (element.deviceId == event.deviceControlModel.deviceId && element.code == event.deviceControlModel.code) { var updatedElement = element.copyWith( + deviceType: event.deviceType, operationName: event.operation, deviceName: event.deviceName, icon: event.icon, diff --git a/lib/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart b/lib/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart index e7e3179..89de3bf 100644 --- a/lib/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart +++ b/lib/features/scene/bloc/smart_scene/smart_scene_select_dart_bloc.dart @@ -41,7 +41,7 @@ class SmartSceneSelectBloc .read(); createSceneBloc.add(TempHoldSceneTasksEvent( - deviceType: '', + deviceType:smartSceneEnable!.type , deviceControlModel: DeviceControlModel( deviceId: smartSceneEnable?.entityId ?? '', code: CreateSceneEnum.smartSceneSelect.name, diff --git a/lib/features/scene/helper/functions_per_device/ac_functions.dart b/lib/features/scene/helper/functions_per_device/ac_functions.dart index 35b47bd..07a19d8 100644 --- a/lib/features/scene/helper/functions_per_device/ac_functions.dart +++ b/lib/features/scene/helper/functions_per_device/ac_functions.dart @@ -9,6 +9,7 @@ class ACFunctionsHelper { String deviceId, String deviceName, functionValue) { return [ SceneStaticFunction( + deviceType: 'AC', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsAcPower, @@ -30,6 +31,7 @@ class ACFunctionsHelper { ], ), SceneStaticFunction( + deviceType: 'AC', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsFreezing, @@ -56,6 +58,7 @@ class ACFunctionsHelper { ], ), SceneStaticFunction( + deviceType: 'AC', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsTempreture, @@ -72,6 +75,7 @@ class ACFunctionsHelper { ], ), SceneStaticFunction( + deviceType: 'AC', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsFanSpeed, @@ -103,6 +107,7 @@ class ACFunctionsHelper { ], ), SceneStaticFunction( + deviceType: 'AC', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsChildLock, @@ -130,6 +135,7 @@ class ACFunctionsHelper { String deviceId, String deviceName, functionValue) { return [ SceneStaticFunction( + deviceType: 'AC', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsAcPower, @@ -151,6 +157,7 @@ class ACFunctionsHelper { ], ), SceneStaticFunction( + deviceType: 'AC', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsFreezing, @@ -177,6 +184,7 @@ class ACFunctionsHelper { ], ), SceneStaticFunction( + deviceType: 'AC', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsTempreture, @@ -196,6 +204,7 @@ class ACFunctionsHelper { ], ), SceneStaticFunction( + deviceType: 'AC', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsCurrentTemp, @@ -215,6 +224,7 @@ class ACFunctionsHelper { ], ), SceneStaticFunction( + deviceType: 'AC', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsFanSpeed, @@ -246,6 +256,7 @@ class ACFunctionsHelper { ], ), SceneStaticFunction( + deviceType: 'AC', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsChildLock, diff --git a/lib/features/scene/helper/functions_per_device/door_lock_functions.dart b/lib/features/scene/helper/functions_per_device/door_lock_functions.dart index 501acb1..fa7ac37 100644 --- a/lib/features/scene/helper/functions_per_device/door_lock_functions.dart +++ b/lib/features/scene/helper/functions_per_device/door_lock_functions.dart @@ -8,6 +8,7 @@ class DoorLockHelperFunctions { String deviceId, String deviceName, functionValue) { return [ SceneStaticFunction( + deviceType: 'DL', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsIconsDoorLock, @@ -16,8 +17,10 @@ class DoorLockHelperFunctions { code: 'normal_open_switch', operationDialogType: OperationDialogType.onOff, operationalValues: [ - SceneOperationalValue(icon: Assets.assetsAcPower, description: "ON", value: true), - SceneOperationalValue(icon: Assets.assetsAcPowerOFF, description: "OFF", value: false), + SceneOperationalValue( + icon: Assets.assetsAcPower, description: "ON", value: true), + SceneOperationalValue( + icon: Assets.assetsAcPowerOFF, description: "OFF", value: false), ], ), ]; @@ -28,6 +31,7 @@ class DoorLockHelperFunctions { String deviceId, String deviceName, functionValue) { return [ SceneStaticFunction( + deviceType: 'DL', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsFingerprintUnlock, @@ -47,6 +51,7 @@ class DoorLockHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'DL', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsPasswordUnlock, @@ -66,6 +71,7 @@ class DoorLockHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'DL', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsCardUnlock, @@ -85,6 +91,7 @@ class DoorLockHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'DL', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsLockAlarm, @@ -101,6 +108,7 @@ class DoorLockHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'DL', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsRemoteUnlockReq, @@ -120,6 +128,7 @@ class DoorLockHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'DL', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsResidualElectricity, @@ -139,6 +148,7 @@ class DoorLockHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'DL', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsDoubleLock, @@ -160,6 +170,7 @@ class DoorLockHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'DL', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsRemoteUnlockViaApp, @@ -179,6 +190,7 @@ class DoorLockHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'DL', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsHijackAlarm, @@ -200,6 +212,7 @@ class DoorLockHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'DL', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsDoorlockNormalOpen, @@ -221,6 +234,7 @@ class DoorLockHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'DL', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsDoorlockNormalOpen, @@ -242,6 +256,7 @@ class DoorLockHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'DL', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsTempPasswordUnlock, diff --git a/lib/features/scene/helper/functions_per_device/flush_functions_helper.dart b/lib/features/scene/helper/functions_per_device/flush_functions_helper.dart new file mode 100644 index 0000000..7ff88c0 --- /dev/null +++ b/lib/features/scene/helper/functions_per_device/flush_functions_helper.dart @@ -0,0 +1,247 @@ +import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart'; +import 'package:syncrow_app/features/scene/model/scene_static_function.dart'; +import 'package:syncrow_app/generated/assets.dart'; + +class FlushFunctionsHelper { + static List flushSceneHelperFunctions( + String deviceId, String deviceName, functionValue) { + return [ + SceneStaticFunction( + deviceType: 'NCPS', + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.assetsPresenceState, + operationName: 'Presence State', + code: 'presence_state', + functionValue: functionValue, + operationDialogType: OperationDialogType.listOfOptions, + operationalValues: [ + SceneOperationalValue( + icon: Assets.nobodyTime, description: "None", value: 'none'), + SceneOperationalValue( + icon: Assets.nobodyTime, + description: "Presence", + value: 'presence', + ), + ], + ), + SceneStaticFunction( + deviceType: 'NCPS', + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.IlluminanceIcon, + operationName: 'Illuminance Value', + code: 'illum_value', + functionValue: functionValue, + operationDialogType: OperationDialogType.integerSteps, + operationalValues: [ + SceneOperationalValue( + icon: '', + value: 0.0, + description: "", + minValue: 0.0, + maxValue: 2000.0, + stepValue: 1.0, + ), + ], + ), + ]; + } + + static List flushAutomationFunctions( + String deviceId, String deviceName, functionValue) { + return [ + SceneStaticFunction( + deviceType: 'NCPS', + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.assetsSensitivityFunction, + operationName: 'Sensitivity', + code: 'sensitivity', + functionValue: functionValue, + operationDialogType: OperationDialogType.listOfOptions, + operationalValues: [ + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 1, + description: 1.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 2, + description: 2.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 3, + description: 3.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 4, + description: 4.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 5, + description: 5.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 6, + description: 6.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 7, + description: 7.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 8, + description: 8.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 9, + description: 9.toString(), + ), + ], + ), + SceneStaticFunction( + deviceType: 'NCPS', + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.currentDistanceIcon, + operationName: 'Min Detection Distance', + code: 'near_detection', + functionValue: functionValue, + operationDialogType: OperationDialogType.integerSteps, + operationalValues: [ + SceneOperationalValue( + icon: '', + value: 0.0, + description: "m", + minValue: 0.0, + maxValue: 9.5, + stepValue: 0.10, + ), + ], + ), + SceneStaticFunction( + deviceType: 'NCPS', + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.currentDistanceIcon, + operationName: 'Max Detection Distance', + code: 'far_detection', + functionValue: functionValue, + operationDialogType: OperationDialogType.integerSteps, + operationalValues: [ + SceneOperationalValue( + icon: '', + value: 0.0, + description: "m", + minValue: 0.0, + maxValue: 9.5, + stepValue: 0.10, + ), + ], + ), + SceneStaticFunction( + deviceType: 'NCPS', + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.levelIcon, + operationName: 'Trigger Level', + code: 'sensi_reduce', + functionValue: functionValue, + operationDialogType: OperationDialogType.listOfOptions, + operationalValues: [ + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 1, + description: 1.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 2, + description: 2.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 3, + description: 3.toString(), + ), + ], + ), + SceneStaticFunction( + deviceType: 'NCPS', + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.indentLevelIcon, + operationName: 'Indent Level', + code: 'occur_dist_reduce', + functionValue: functionValue, + operationDialogType: OperationDialogType.listOfOptions, + operationalValues: [ + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 1, + description: 1.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 2, + description: 2.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 3, + description: 3.toString(), + ), + ], + ), + SceneStaticFunction( + deviceType: 'NCPS', + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.targetConfirmTimeIcon, + operationName: 'Target Confirm Time', + code: 'presence_delay', + functionValue: functionValue, + operationDialogType: OperationDialogType.integerSteps, + operationalValues: [ + SceneOperationalValue( + icon: '', + value: 0.0, + description: "", + minValue: 0.0, + maxValue: 0.5, + stepValue: 0.1, + ), + ], + ), + SceneStaticFunction( + deviceType: 'NCPS', + deviceId: deviceId, + deviceName: deviceName, + icon: Assets.delayIcon, + operationName: 'Disappear Delay', + code: 'none_delay', + functionValue: functionValue, + operationDialogType: OperationDialogType.integerSteps, + operationalValues: [ + SceneOperationalValue( + icon: '', + value: 20.0, + description: "", + minValue: 20.0, + maxValue: 300.0, + stepValue: 1.0, + ), + ], + ), + ]; + } +} diff --git a/lib/features/scene/helper/functions_per_device/gateway_functions.dart b/lib/features/scene/helper/functions_per_device/gateway_functions.dart index 7a356a7..812c957 100644 --- a/lib/features/scene/helper/functions_per_device/gateway_functions.dart +++ b/lib/features/scene/helper/functions_per_device/gateway_functions.dart @@ -7,6 +7,7 @@ class GatewayHelperFunctions { String deviceId, String deviceName, functionValue) { return [ SceneStaticFunction( + deviceType: 'GW', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsSwitchAlarmSound, @@ -22,6 +23,7 @@ class GatewayHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'GW', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsMasterState, @@ -43,6 +45,7 @@ class GatewayHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'GW', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsFactoryReset, diff --git a/lib/features/scene/helper/functions_per_device/human_presence_functions.dart b/lib/features/scene/helper/functions_per_device/human_presence_functions.dart index d6f6070..ab043d2 100644 --- a/lib/features/scene/helper/functions_per_device/human_presence_functions.dart +++ b/lib/features/scene/helper/functions_per_device/human_presence_functions.dart @@ -7,6 +7,7 @@ class HumanPresenceHelperFunctions { String deviceId, String deviceName, functionValue) { return [ SceneStaticFunction( + deviceType: 'WPS', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsFarDetection, @@ -66,6 +67,7 @@ class HumanPresenceHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'WPS', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsMotionDetection, @@ -102,6 +104,7 @@ class HumanPresenceHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'WPS', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsMotionlessDetection, @@ -143,6 +146,7 @@ class HumanPresenceHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'WPS', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsIndicator, @@ -164,6 +168,7 @@ class HumanPresenceHelperFunctions { String deviceId, String deviceName, functionValue) { return [ SceneStaticFunction( + deviceType: 'WPS', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsPresenceState, @@ -185,6 +190,7 @@ class HumanPresenceHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'WPS', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsIconsPresenceSensorAssetsDistance, @@ -204,6 +210,7 @@ class HumanPresenceHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'WPS', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsIconsPresenceSensorAssetsIlluminanceValue, @@ -223,6 +230,7 @@ class HumanPresenceHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'WPS', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsIndicator, @@ -238,6 +246,7 @@ class HumanPresenceHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'WPS', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsIconsPresenceSensorAssetsTime, diff --git a/lib/features/scene/helper/functions_per_device/presence_sensor.dart b/lib/features/scene/helper/functions_per_device/presence_sensor.dart index 25354e6..af4939a 100644 --- a/lib/features/scene/helper/functions_per_device/presence_sensor.dart +++ b/lib/features/scene/helper/functions_per_device/presence_sensor.dart @@ -7,6 +7,7 @@ class PresenceSensorHelperFunctions { String deviceId, String deviceName, functionValue) { return [ SceneStaticFunction( + deviceType: 'CPS', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsSensitivityFunction, @@ -74,6 +75,7 @@ class PresenceSensorHelperFunctions { String deviceId, String deviceName, functionValue) { return [ SceneStaticFunction( + deviceType: 'CPS', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsIconsSensors, @@ -100,6 +102,7 @@ class PresenceSensorHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'CPS', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsSensitivityFunction, @@ -119,6 +122,7 @@ class PresenceSensorHelperFunctions { ], ), SceneStaticFunction( + deviceType: 'CPS', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsSelfTestResult, diff --git a/lib/features/scene/helper/functions_per_device/tow_gang_helper_functions.dart b/lib/features/scene/helper/functions_per_device/tow_gang_helper_functions.dart index 072338f..0823769 100644 --- a/lib/features/scene/helper/functions_per_device/tow_gang_helper_functions.dart +++ b/lib/features/scene/helper/functions_per_device/tow_gang_helper_functions.dart @@ -7,6 +7,7 @@ class TowGangHelperFunctions { String deviceId, String deviceName, functionValue) { return [ SceneStaticFunction( + deviceType: '2G', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsAcPower, @@ -22,6 +23,7 @@ class TowGangHelperFunctions { ], ), SceneStaticFunction( + deviceType: '2G', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsLightCountdown, @@ -34,6 +36,7 @@ class TowGangHelperFunctions { ], ), SceneStaticFunction( + deviceType: '2G', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsAcPower, @@ -49,6 +52,7 @@ class TowGangHelperFunctions { ], ), SceneStaticFunction( + deviceType: '2G', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsLightCountdown, @@ -67,6 +71,7 @@ class TowGangHelperFunctions { String deviceId, String deviceName, functionValue) { return [ SceneStaticFunction( + deviceType: '2G', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsAcPower, @@ -82,6 +87,7 @@ class TowGangHelperFunctions { ], ), SceneStaticFunction( + deviceType: '2G', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsLightCountdown, @@ -101,6 +107,7 @@ class TowGangHelperFunctions { ], ), SceneStaticFunction( + deviceType: '2G', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsAcPower, @@ -116,6 +123,7 @@ class TowGangHelperFunctions { ], ), SceneStaticFunction( + deviceType: '2G', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsLightCountdown, diff --git a/lib/features/scene/helper/functions_per_device/water_heater_functions.dart b/lib/features/scene/helper/functions_per_device/water_heater_functions.dart index 80cdd89..8a65eb1 100644 --- a/lib/features/scene/helper/functions_per_device/water_heater_functions.dart +++ b/lib/features/scene/helper/functions_per_device/water_heater_functions.dart @@ -7,6 +7,7 @@ class WaterHeaterFunctionsHelper { String deviceId, String deviceName, functionValue) { return [ SceneStaticFunction( + deviceType: 'WH', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsAcPower, @@ -27,6 +28,7 @@ class WaterHeaterFunctionsHelper { ], ), SceneStaticFunction( + deviceType: 'WH', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsLightCountdown, @@ -45,6 +47,7 @@ class WaterHeaterFunctionsHelper { String deviceId, String deviceName, functionValue) { return [ SceneStaticFunction( + deviceType: 'WH', deviceId: deviceId, deviceName: deviceName, icon: Assets.refreshStatusIcon, @@ -71,6 +74,7 @@ class WaterHeaterFunctionsHelper { ], ), SceneStaticFunction( + deviceType: 'WH', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsAcPower, @@ -86,6 +90,7 @@ class WaterHeaterFunctionsHelper { ], ), SceneStaticFunction( + deviceType: 'WH', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsLightCountdown, @@ -105,6 +110,7 @@ class WaterHeaterFunctionsHelper { ], ), SceneStaticFunction( + deviceType: 'WH', deviceId: deviceId, deviceName: deviceName, icon: Assets.assetsIndicator, diff --git a/lib/features/scene/helper/scene_logic_helper.dart b/lib/features/scene/helper/scene_logic_helper.dart index 2042c30..1c1d270 100644 --- a/lib/features/scene/helper/scene_logic_helper.dart +++ b/lib/features/scene/helper/scene_logic_helper.dart @@ -88,6 +88,7 @@ mixin SceneLogicHelper { final task = actions[index]; if (task.deviceId == 'delay') { return CreateSceneAction( + productType: task.deviceType, entityId: actions[index].deviceId, actionExecutor: 'delay', executorProperty: CreateSceneExecutorProperty( @@ -99,6 +100,7 @@ mixin SceneLogicHelper { } if (task.code == CreateSceneEnum.smartSceneSelect.name) { return CreateSceneAction( + productType: task.deviceType, actionType: task.operationName.toLowerCase() == 'automation' ? 'automation' : 'scene', @@ -107,6 +109,7 @@ mixin SceneLogicHelper { executorProperty: null); } return CreateSceneAction( + productType: task.deviceType, entityId: task.deviceId, actionExecutor: 'device_issue', executorProperty: CreateSceneExecutorProperty( @@ -119,6 +122,20 @@ mixin SceneLogicHelper { ), ], ); + for (var action in createAutomationModel.actions) { + if (action.productType == 'NCPS') { + if (action.executorProperty!.functionCode == 'near_detection' || + action.executorProperty!.functionCode == 'far_detection') { + action.executorProperty!.functionValue = + (action.executorProperty!.functionValue * 100).round(); + } else if (action.executorProperty!.functionCode == + 'presence_delay' || + action.executorProperty!.functionCode == 'none_delay') { + action.executorProperty!.functionValue = + action.executorProperty!.functionValue * 10; + } + } + } sceneBloc.add(CreateSceneWithTasksEvent( createSceneModel: null, updateScene: updateScene, @@ -139,6 +156,7 @@ mixin SceneLogicHelper { final task = actions[index]; if (task.deviceId == 'delay') { return CreateSceneAction( + productType: task.deviceType, entityId: actions[index].deviceId, actionExecutor: 'delay', executorProperty: CreateSceneExecutorProperty( @@ -150,11 +168,14 @@ mixin SceneLogicHelper { } if (task.code == CreateSceneEnum.smartSceneSelect.name) { return CreateSceneAction( + productType: task.deviceType, entityId: actions[index].deviceId, actionExecutor: actions[index].functionValue, executorProperty: null); } + return CreateSceneAction( + productType: task.deviceType, entityId: task.deviceId, actionExecutor: 'device_issue', executorProperty: CreateSceneExecutorProperty( @@ -167,6 +188,20 @@ mixin SceneLogicHelper { ), ], ); + for (var action in createSceneModel.actions) { + if (action.productType == 'NCPS') { + if (action.executorProperty!.functionCode == 'near_detection' || + action.executorProperty!.functionCode == 'far_detection') { + action.executorProperty!.functionValue = + action.executorProperty!.functionValue * 100; + } else if (action.executorProperty!.functionCode == + 'presence_delay' || + action.executorProperty!.functionCode == 'none_delay') { + action.executorProperty!.functionValue = + action.executorProperty!.functionValue * 10; + } + } + } sceneBloc.add(CreateSceneWithTasksEvent( createSceneModel: createSceneModel, createAutomationModel: null, diff --git a/lib/features/scene/helper/scene_operations_data_helper.dart b/lib/features/scene/helper/scene_operations_data_helper.dart index a259c4a..415a59b 100644 --- a/lib/features/scene/helper/scene_operations_data_helper.dart +++ b/lib/features/scene/helper/scene_operations_data_helper.dart @@ -4,6 +4,7 @@ import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart'; import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart'; import 'package:syncrow_app/features/scene/helper/functions_per_device/ac_functions.dart'; import 'package:syncrow_app/features/scene/helper/functions_per_device/door_lock_functions.dart'; +import 'package:syncrow_app/features/scene/helper/functions_per_device/flush_functions_helper.dart'; import 'package:syncrow_app/features/scene/helper/functions_per_device/gateway_functions.dart'; import 'package:syncrow_app/features/scene/helper/functions_per_device/human_presence_functions.dart'; import 'package:syncrow_app/features/scene/helper/functions_per_device/one_gang_functions.dart'; @@ -18,7 +19,7 @@ import 'package:syncrow_app/utils/resource_manager/constants.dart'; mixin SceneOperationsDataHelper { final Map, String, String, dynamic, bool)> + Function(List, String, String, dynamic, bool, String)> _functionMap = { DeviceType.LightBulb: lightBulbFunctions, DeviceType.CeilingSensor: ceilingSensorFunctions, @@ -31,6 +32,7 @@ mixin SceneOperationsDataHelper { DeviceType.OneGang: oneGangFunctions, DeviceType.TwoGang: towGangFunctions, DeviceType.WH: waterHeaterFunctions, + DeviceType.FlushMountedSensor: flushFunctions }; final Map _titleMap = { @@ -45,14 +47,33 @@ mixin SceneOperationsDataHelper { DeviceType.OneGang: '1G Light Switch Conditions', DeviceType.TwoGang: '2G Light Switch Conditions', DeviceType.WH: 'Water Heater Conditions', + DeviceType.FlushMountedSensor: 'Flush Presence Sensor Functions' }; + static List flushFunctions( + List functions, + String deviceId, + String deviceName, + dynamic functionValue, + bool isAutomation, + String productType, + ) { + if (isAutomation) { + return FlushFunctionsHelper.flushSceneHelperFunctions( + deviceId, deviceName, functionValue); + } + return FlushFunctionsHelper.flushAutomationFunctions( + deviceId, deviceName, functionValue); + } + static List waterHeaterFunctions( - List functions, - String deviceId, - String deviceName, - dynamic functionValue, - bool isAutomation) { + List functions, + String deviceId, + String deviceName, + dynamic functionValue, + bool isAutomation, + String productType, + ) { if (isAutomation) { return WaterHeaterFunctionsHelper.waterHeaterAutomationFunctions( deviceId, deviceName, functionValue); @@ -63,11 +84,13 @@ mixin SceneOperationsDataHelper { //one gang functions static List oneGangFunctions( - List functions, - String deviceId, - String deviceName, - dynamic functionValue, - bool isAutomation) { + List functions, + String deviceId, + String deviceName, + dynamic functionValue, + bool isAutomation, + String productType, + ) { if (isAutomation) { return OneGangHelperFunctions.oneGangAutomationFunctions( deviceId, deviceName, functionValue); @@ -77,11 +100,13 @@ mixin SceneOperationsDataHelper { } static List towGangFunctions( - List functions, - String deviceId, - String deviceName, - dynamic functionValue, - bool isAutomation) { + List functions, + String deviceId, + String deviceName, + dynamic functionValue, + bool isAutomation, + String productType, + ) { if (isAutomation) { return TowGangHelperFunctions.towGangAutomationFunctions( deviceId, deviceName, functionValue); @@ -95,13 +120,14 @@ mixin SceneOperationsDataHelper { required List functions, required String deviceId, required String deviceName, + required String productType, required bool isAutomation, }) { final functionValue = null; - return _functionMap[type]?.call( - functions, deviceId, deviceName, functionValue, isAutomation) ?? - lightBulbFunctions( - functions, deviceId, deviceName, functionValue, isAutomation); + return _functionMap[type]?.call(functions, deviceId, deviceName, + functionValue, isAutomation, productType) ?? + lightBulbFunctions(functions, deviceId, deviceName, functionValue, + isAutomation, productType); } String getTitle({DeviceType? type}) { @@ -109,11 +135,13 @@ mixin SceneOperationsDataHelper { } static List ceilingSensorFunctions( - List functions, - String deviceId, - String deviceName, - dynamic functionValue, - bool isAutomation) { + List functions, + String deviceId, + String deviceName, + dynamic functionValue, + bool isAutomation, + String productType, + ) { if (isAutomation) { return PresenceSensorHelperFunctions.automationPresenceSensorFunctions( deviceId, deviceName, functionValue); @@ -123,20 +151,24 @@ mixin SceneOperationsDataHelper { } static List curtainFunctions( - List functions, - String deviceId, - String deviceName, - dynamic functionValue, - bool isAutomation) { + List functions, + String deviceId, + String deviceName, + dynamic functionValue, + bool isAutomation, + String productType, + ) { return []; } static List doorLockFunctions( - List functions, - String deviceId, - String deviceName, - dynamic functionValue, - bool isAutomation) { + List functions, + String deviceId, + String deviceName, + dynamic functionValue, + bool isAutomation, + String productType, + ) { if (isAutomation) { return DoorLockHelperFunctions.doorLockAutomationFunctions( deviceId, deviceName, functionValue); @@ -146,11 +178,13 @@ mixin SceneOperationsDataHelper { } static List wallSensorFunctions( - List functions, - String deviceId, - String deviceName, - dynamic functionValue, - bool isAutomation) { + List functions, + String deviceId, + String deviceName, + dynamic functionValue, + bool isAutomation, + String productType, + ) { if (isAutomation) { return HumanPresenceHelperFunctions.automationHumanPresenceFunctions( deviceId, deviceName, functionValue); @@ -164,26 +198,31 @@ mixin SceneOperationsDataHelper { String deviceId, String deviceName, dynamic functionValue, - bool isAutomation) { + bool isAutomation, + String productType) { return []; } static List gatewayFunctions( - List functions, - String deviceId, - String deviceName, - dynamic functionValue, - bool isAutomation) { + List functions, + String deviceId, + String deviceName, + dynamic functionValue, + bool isAutomation, + String productType, + ) { return GatewayHelperFunctions.tabToRunGatewayFunctions( deviceId, deviceName, functionValue); } static List threeGangFunctions( - List functions, - String deviceId, - String deviceName, - dynamic functionValue, - bool isAutomation) { + List functions, + String deviceId, + String deviceName, + dynamic functionValue, + bool isAutomation, + String productType, + ) { if (isAutomation) { return ThreeGangHelperFunctions.threeGangAutomationFunctions( deviceId, deviceName, functionValue); @@ -193,11 +232,13 @@ mixin SceneOperationsDataHelper { } static List acFunctions( - List functions, - String deviceId, - String deviceName, - dynamic functionValue, - bool isAutomation) { + List functions, + String deviceId, + String deviceName, + dynamic functionValue, + bool isAutomation, + String productType, + ) { if (isAutomation) { return ACFunctionsHelper.automationAcFunctions( deviceId, deviceName, functionValue); @@ -212,7 +253,19 @@ mixin SceneOperationsDataHelper { List? conditions, }) { List functions = []; - + for (var action in actions) { + if (action.productType == "NCPS") { + if (action.executorProperty!.functionCode == 'near_detection' || + action.executorProperty!.functionCode == 'far_detection') { + action.executorProperty!.functionValue = + action.executorProperty!.functionValue / 100; + } else if (action.executorProperty!.functionCode == 'presence_delay' || + action.executorProperty!.functionCode == 'none_delay') { + action.executorProperty!.functionValue = + (action.executorProperty!.functionValue / 10); + } + } + } // Handle actions for (var action in actions) { if (action.entityId == 'delay') { @@ -306,11 +359,9 @@ mixin SceneOperationsDataHelper { String? uniqueCustomId, }) { final executorProperty = action.executorProperty; - final Map functionMap = { - 'sensitivity': _createSensitivityFunction, 'normal_open_switch': _createNormalOpenSwitchFunction, 'unlock_fingerprint': _createUnlockFingerprintFunction, 'unlock_password': _createUnlockPasswordFunction, @@ -323,12 +374,21 @@ mixin SceneOperationsDataHelper { 'hijack': _createHijackFunction, 'doorbell': _createDoorbellFunction, 'unlock_temporary': _createUnlockTemporaryFunction, - 'far_detection': _createFarDetectionFunction, + 'near_detection': _createNearDetectionOptions, + if (action.productType == 'NCPS') ...{ + 'far_detection': _createFarDetectionOptionsFlush, + 'presence_state': _createPresenceStateFunctionFlush, + 'illum_value': _createIlluminanceValueFunctionFlush, + 'sensitivity': _createSensitivityFunctionFlush, + } else ...{ + 'far_detection': _createFarDetectionFunction, + 'presence_state': _createPresenceStateFunction, + 'sensitivity': _createSensitivityFunction, + }, 'motion_sensitivity_value': _createMotionSensitivityFunction, 'motionless_sensitivity': _createMotionlessSensitivityFunction, 'indicator': _createIndicatorFunction, 'presence_time': _createPresenceTimeFunction, - 'presence_state': _createPresenceStateFunction, 'dis_current': _createDisCurrentFunction, 'illuminance_value': _createIlluminanceValueFunction, 'checking_result': _createCheckingResultFunction, @@ -349,6 +409,10 @@ mixin SceneOperationsDataHelper { 'factory_reset': _createFactoryResetFunction, 'switch_backlight': _createSwitchFunction, 'relay_status': _relayStatusSwitchFunction, + 'sensi_reduce': _createTriggerLevelOptions, + 'occur_dist_reduce': _createIndentLevelOptions, + 'presence_delay': _createTargetConfirmTime, + 'none_delay': _createDisappeDelay }; final functionCode = executorProperty?.functionCode ?? ''; @@ -372,7 +436,6 @@ mixin SceneOperationsDataHelper { String? uniqueCustomId, ]) { final productType = action.productType; - final functionValue = action.executorProperty?.functionValue; return SceneStaticFunction( deviceType: productType, @@ -765,17 +828,36 @@ mixin SceneOperationsDataHelper { SceneStaticFunction _createSwitchFunction(Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { - return _createSceneFunction( - action, - action.deviceName, - Assets.waterHeaterIcon, - 'Power', - OperationDialogType.onOff, - _createOnOffOptions(), - isAutomation, - comparator, - uniqueCustomId, - ); + switch (action.productType) { + case "AC": + return _createSceneFunction( + action, + action.deviceName, + Assets.assetsIconsAC, + 'Switch', + OperationDialogType.onOff, + _createOnOffOptions(), + isAutomation, + comparator, + uniqueCustomId, + ); + + case "WH": + return _createSceneFunction( + action, + action.deviceName, + Assets.waterHeaterIcon, + 'Power', + OperationDialogType.onOff, + _createOnOffOptions(), + isAutomation, + comparator, + uniqueCustomId, + ); + + default: + throw ArgumentError('Unsupported product type: ${action.productType}'); + } } SceneStaticFunction _relayStatusSwitchFunction(Action action, @@ -875,6 +957,19 @@ mixin SceneOperationsDataHelper { static SceneStaticFunction _createSwitch1Function(Action action, bool isAutomation, String? comparator, String? uniqueCustomId) { switch (action.productType) { + case "AC": + return _createSceneFunction( + action, + action.deviceName, + Assets.acSwitchIcon, + 'Switch', + OperationDialogType.onOff, + _createOnOffOptions(), + isAutomation, + comparator, + uniqueCustomId, + ); + case "WH": return _createSceneFunction( action, @@ -1349,6 +1444,21 @@ mixin SceneOperationsDataHelper { ]; } + List _createPresenceStateOptionsFlush() { + return [ + SceneOperationalValue( + icon: Assets.assetsIconsPresenceSensorAssetsEmpty, + value: 'none', + description: 'None', + ), + SceneOperationalValue( + icon: Assets.assetsPresence, + value: 'presence', + description: 'Presence', + ), + ]; + } + List _createPresenceStateOptions() { return [ SceneOperationalValue( @@ -1582,7 +1692,7 @@ mixin SceneOperationsDataHelper { return [ _mapExecutorPropertyToSceneFunction( Action( - deviceName: taskItem.deviceName, + deviceName: taskItem.deviceName!, productType: taskItem.deviceType!, entityId: deviceId, executorProperty: ExecutorProperty( @@ -1630,4 +1740,296 @@ mixin SceneOperationsDataHelper { ), ]; } + + SceneStaticFunction _createNearDetectionOptions(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { + return _createSceneFunction( + action, + action.deviceName, + Assets.flushIcon, + 'Min Detection distance', + OperationDialogType.integerSteps, + _createMinDetection(), + isAutomation, + comparator, + uniqueCustomId, + ); + } + + SceneStaticFunction _createFarDetectionOptionsFlush(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { + return _createSceneFunction( + action, + action.deviceName, + Assets.flushIcon, + 'Max Detection distance', + OperationDialogType.integerSteps, + _createFarDetection(), + isAutomation, + comparator, + uniqueCustomId, + ); + } + + SceneStaticFunction _createTriggerLevelOptions(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { + return _createSceneFunction( + action, + action.deviceName, + Assets.flushIcon, + "Trigger Level", + OperationDialogType.listOfOptions, + _createTriggerLevelFunction(), + isAutomation, + comparator, + uniqueCustomId, + ); + } + + List _createTriggerLevelFunction() { + return [ + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + description: "1", + value: 1, + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + description: "2", + value: 2, + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + description: "3", + value: 3, + ), + ]; + } + + SceneStaticFunction _createIndentLevelOptions(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { + return _createSceneFunction( + action, + action.deviceName, + Assets.flushIcon, + 'Indent Level', + OperationDialogType.listOfOptions, + _createIndentLevelFunction(), + isAutomation, + comparator, + uniqueCustomId, + ); + } + + List _createIndentLevelFunction() { + return [ + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + description: "1", + value: 1, + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + description: "2", + value: 2, + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + description: "3", + value: 3, + ), + ]; + } + + SceneStaticFunction _createTargetConfirmTime(Action action, bool isAutomation, + String? comparator, String? uniqueCustomId) { + return _createSceneFunction( + action, + action.deviceName, + Assets.flushIcon, + 'Target Confirm Time', + OperationDialogType.integerSteps, + _targetConfirmTimeFun(), + isAutomation, + comparator, + uniqueCustomId, + ); + } + + SceneStaticFunction _createDisappeDelay(Action action, bool isAutomation, + String? comparator, String? uniqueCustomId) { + return _createSceneFunction( + action, + action.deviceName, + Assets.flushIcon, + 'Disappe Delay', + OperationDialogType.integerSteps, + _targetDisappeDelayFun(), + isAutomation, + comparator, + uniqueCustomId, + ); + } + + List _targetDisappeDelayFun() { + return [ + SceneOperationalValue( + icon: Assets.flushIcon, + value: 0.0, + description: '', + minValue: 20, + maxValue: 300, + stepValue: 1, + ), + ]; + } + + List _createFarDetection() { + return [ + SceneOperationalValue( + icon: '', + description: "m", + value: 0.0, + minValue: 0.0, + maxValue: 9.5, + stepValue: 1, + ), + ]; + } + + List _createMinDetection() { + return [ + SceneOperationalValue( + icon: '', + description: "m", + value: 0.0, + minValue: 0.0, + maxValue: 9.5, + stepValue: 1, + ), + ]; + } + + List _targetConfirmTimeFun() { + return [ + SceneOperationalValue( + icon: Assets.assetsCelsiusDegrees, + value: 0.0, + description: '', + minValue: 0.0, + maxValue: 0.5, + stepValue: 0.1, + ), + ]; + } + + SceneStaticFunction _createPresenceStateFunctionFlush(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { + return _createSceneFunction( + action, + action.deviceName, + Assets.flushIcon, + 'Presence State', + OperationDialogType.listOfOptions, + _createPresenceStateOptionsFlush(), + isAutomation, + comparator, + uniqueCustomId, + ); + } + + SceneStaticFunction _createIlluminanceValueFunctionFlush(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { + return _createSceneFunction( + action, + action.deviceName, + Assets.flushIcon, + 'Illuminance Value', + OperationDialogType.integerSteps, + _createIlluminanceValueOptionsFlush(), + isAutomation, + comparator, + uniqueCustomId, + ); + } + + List _createIlluminanceValueOptionsFlush() { + return [ + SceneOperationalValue( + icon: '', + value: 0.0, + description: "Lux", + minValue: 0, + maxValue: 10000, + stepValue: 1, + ), + ]; + } + + SceneStaticFunction _createSensitivityFunctionFlush(Action action, + bool isAutomation, String? comparator, String? uniqueCustomId) { + return _createSceneFunction( + action, + action.deviceName, + Assets.flushIcon, + 'Sensitivity', + isAutomation + ? OperationDialogType.integerSteps + : OperationDialogType.listOfOptions, + _createIntegerStepsOptionsFlush(), + isAutomation, + comparator, + uniqueCustomId, + ); + } + + List _createIntegerStepsOptionsFlush() { + return [ + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 1, + description: 1.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 2, + description: 2.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 3, + description: 3.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 4, + description: 4.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 5, + description: 5.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 6, + description: 6.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 7, + description: 7.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 8, + description: 8.toString(), + ), + SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: 9, + description: 9.toString(), + ), + ]; + } } diff --git a/lib/features/scene/model/create_scene_model.dart b/lib/features/scene/model/create_scene_model.dart index 088e9e6..718abd0 100644 --- a/lib/features/scene/model/create_scene_model.dart +++ b/lib/features/scene/model/create_scene_model.dart @@ -94,6 +94,8 @@ class CreateSceneModel { } class CreateSceneAction { + final String? productType; + String entityId; String? actionType; String actionExecutor; @@ -104,15 +106,18 @@ class CreateSceneAction { required this.entityId, required this.actionExecutor, required this.executorProperty, + required this.productType, }); CreateSceneAction copyWith({ + String? productType, String? actionType, String? entityId, String? actionExecutor, CreateSceneExecutorProperty? executorProperty, }) { return CreateSceneAction( + productType: productType, actionType: actionType, entityId: entityId ?? this.entityId, actionExecutor: actionExecutor ?? this.actionExecutor, @@ -126,18 +131,21 @@ class CreateSceneAction { 'entityId': entityId, 'actionExecutor': actionExecutor, 'executorProperty': executorProperty?.toMap(actionExecutor), + // 'productType': productType, }; } else { return { "actionType": actionType, 'entityId': entityId, 'actionExecutor': actionExecutor, + // 'productType': productType, }; } } factory CreateSceneAction.fromMap(Map map) { return CreateSceneAction( + productType: map['productType'] ?? '', entityId: map['entityId'] ?? '', actionExecutor: map['actionExecutor'] ?? '', executorProperty: diff --git a/lib/features/scene/model/scene_details_model.dart b/lib/features/scene/model/scene_details_model.dart index aa035b6..7ad0e78 100644 --- a/lib/features/scene/model/scene_details_model.dart +++ b/lib/features/scene/model/scene_details_model.dart @@ -75,7 +75,6 @@ class Action { String? name; String? type; final String productType; - final String deviceName; Action({ @@ -91,39 +90,57 @@ class Action { String toRawJson() => json.encode(toJson()); static Action? fromJson(Map json) { - if (json['name'] != null && json['type'] != null) { - return Action( - actionExecutor: json["actionExecutor"] as String, - entityId: json["entityId"] as String, - name: json['name'] as String?, - type: json['type'] as String?, - productType: json['productType'] as String, - deviceName: json['deviceName'] as String, - ); - } - if (json["executorProperty"] == null) { + // Safely extract required fields with null checks + final String? actionExecutor = json["actionExecutor"] as String?; + final String? entityId = json["entityId"] as String?; + final String? productType = json['productType'] as String?; + final String? deviceName = json['deviceName'] as String?; + + // Skip invalid actions with missing required fields + if (actionExecutor == null || + entityId == null || + productType == null || + deviceName == null) { return null; } - return Action( - actionExecutor: json["actionExecutor"] as String, - entityId: json["entityId"] as String, - executorProperty: ExecutorProperty.fromJson(json["executorProperty"]), - productType: json['productType'] as String, - deviceName: json['deviceName'] as String, - ); + // Handle actions with 'name' and 'type' + if (json['name'] != null && json['type'] != null) { + return Action( + actionExecutor: actionExecutor, + entityId: entityId, + name: json['name'] as String?, + type: json['type'] as String?, + productType: productType, + deviceName: deviceName, + ); + } + + // Handle actions with 'executorProperty' + if (json["executorProperty"] != null) { + return Action( + actionExecutor: actionExecutor, + entityId: entityId, + executorProperty: ExecutorProperty.fromJson(json["executorProperty"]), + productType: productType, + deviceName: deviceName, + ); + } + + return null; // Skip invalid actions } Map toJson() => { "actionExecutor": actionExecutor, "entityId": entityId, "executorProperty": executorProperty?.toJson(), + // "productType": productType }; } class ExecutorProperty { final String? functionCode; - final dynamic functionValue; + dynamic functionValue; final dynamic delaySeconds; ExecutorProperty({ diff --git a/lib/features/scene/model/scene_static_function.dart b/lib/features/scene/model/scene_static_function.dart index 0c47e73..b174189 100644 --- a/lib/features/scene/model/scene_static_function.dart +++ b/lib/features/scene/model/scene_static_function.dart @@ -12,7 +12,7 @@ class SceneStaticFunction { final String deviceId; final String operationName; final String? uniqueCustomId; - final dynamic functionValue; + dynamic functionValue; final String? deviceIcon; final OperationDialogType operationDialogType; final String? comparator; @@ -29,7 +29,7 @@ class SceneStaticFunction { this.deviceIcon, required this.operationDialogType, this.comparator, - this.deviceType, + this.deviceType, String? uniqueCustomId, }) : uniqueCustomId = uniqueCustomId ?? const Uuid().v4(); @@ -127,7 +127,8 @@ class SceneStaticFunction { other.uniqueCustomId == uniqueCustomId && other.operationDialogType == operationDialogType && listEquals(other.operationalValues, operationalValues) && - other.deviceId == deviceId && other.deviceType == deviceType; + other.deviceId == deviceId && + other.deviceType == deviceType; } @override @@ -142,7 +143,8 @@ class SceneStaticFunction { comparator.hashCode ^ uniqueCustomId.hashCode ^ operationDialogType.hashCode ^ - operationalValues.hashCode ^ deviceType.hashCode; + operationalValues.hashCode ^ + deviceType.hashCode; } } diff --git a/lib/features/scene/view/device_functions_view.dart b/lib/features/scene/view/device_functions_view.dart index c857a7c..356a8fe 100644 --- a/lib/features/scene/view/device_functions_view.dart +++ b/lib/features/scene/view/device_functions_view.dart @@ -26,20 +26,20 @@ class DeviceFunctionsView extends StatelessWidget Widget build(BuildContext context) { final device = (ModalRoute.of(context)?.settings.arguments as Map)['device'] as DeviceModel; - final isAutomation = (ModalRoute.of(context)?.settings.arguments as Map)['isAutomationDeviceStatus'] as bool; List functions = []; - if (device.functions.isNotEmpty) { - functions = getFunctionsWithIcons( - type: device.productType, - functions: device.functions, - deviceId: device.uuid ?? '', - deviceName: device.name ?? '', - isAutomation: isAutomation, - ); - } + // if (device.functions.isNotEmpty) { + functions = getFunctionsWithIcons( + productType: device.type ?? '', + type: device.productType, + functions: device.functions, + deviceId: device.uuid ?? '', + deviceName: device.name ?? '', + isAutomation: isAutomation, + ); + // } return DefaultScaffold( title: getTitle(type: device.productType), @@ -257,7 +257,7 @@ class DeviceFunctionsView extends StatelessWidget deviceName: device.name ?? '', uniqueId: function.uniqueCustomId!, operationType: function.operationDialogType, - deviceType: '', + deviceType: function.deviceType!, )); Navigator.pop(context); }, @@ -298,7 +298,7 @@ class DeviceFunctionsView extends StatelessWidget return; } context.read().add(TempHoldSceneTasksEvent( - deviceType: device.productType!.name, + deviceType: function.deviceType!, deviceControlModel: DeviceControlModel( deviceId: device.uuid, code: function.code, diff --git a/lib/features/scene/widgets/alert_dialogs/alert_dialog_slider_steps.dart b/lib/features/scene/widgets/alert_dialogs/alert_dialog_slider_steps.dart index 3503e46..70509a2 100644 --- a/lib/features/scene/widgets/alert_dialogs/alert_dialog_slider_steps.dart +++ b/lib/features/scene/widgets/alert_dialogs/alert_dialog_slider_steps.dart @@ -7,12 +7,12 @@ import 'package:syncrow_app/utils/context_extension.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; class AlertDialogSliderSteps extends StatefulWidget { - const AlertDialogSliderSteps({ - super.key, - this.functionValue, - required this.taskItem, - required this.isAutomation, - }); + const AlertDialogSliderSteps( + {super.key, + this.functionValue, + required this.taskItem, + required this.isAutomation, + }); final dynamic functionValue; final SceneStaticFunction taskItem; @@ -108,67 +108,69 @@ class _AlertDialogSliderStepsState extends State { return Column( mainAxisSize: MainAxisSize.min, children: [ - ToggleButtons( - isSelected: [ - selectedToggleIndex == 0, - selectedToggleIndex == 1, - selectedToggleIndex == 2 - ], - onPressed: (index) { - setState(() { - selectedToggleIndex = index; - }); - context.read().add( - SelectedValueEvent( - value: _deNormalizeValue(groupValue), - code: widget.taskItem.code, - isAutomation: widget.isAutomation, - comparator: _indexToComparator(selectedToggleIndex), + widget.isAutomation + ? ToggleButtons( + isSelected: [ + selectedToggleIndex == 0, + selectedToggleIndex == 1, + selectedToggleIndex == 2 + ], + onPressed: (index) { + setState(() { + selectedToggleIndex = index; + }); + context.read().add( + SelectedValueEvent( + value: _deNormalizeValue(groupValue), + code: widget.taskItem.code, + isAutomation: widget.isAutomation, + comparator: _indexToComparator(selectedToggleIndex), + ), + ); + }, + borderRadius: BorderRadius.circular(30), + selectedColor: Colors.white, + color: ColorsManager.blackColor, + fillColor: ColorsManager.primaryColorWithOpacity, + borderColor: ColorsManager.greyColor, + constraints: BoxConstraints.tight(const Size(70, 30)), + children: [ + SizedBox( + width: 70, + height: 30, + child: Container( + color: selectedToggleIndex == 0 + ? ColorsManager.primaryColorWithOpacity + : ColorsManager.greyColor, + alignment: Alignment.center, + child: const Text("<"), + ), ), - ); - }, - borderRadius: BorderRadius.circular(30), - selectedColor: Colors.white, - color: ColorsManager.blackColor, - fillColor: ColorsManager.primaryColorWithOpacity, - borderColor: ColorsManager.greyColor, - constraints: BoxConstraints.tight(const Size(70, 30)), - children: [ - SizedBox( - width: 70, - height: 30, - child: Container( - color: selectedToggleIndex == 0 - ? ColorsManager.primaryColorWithOpacity - : ColorsManager.greyColor, - alignment: Alignment.center, - child: const Text("<"), - ), - ), - SizedBox( - width: 70, - height: 30, - child: Container( - color: selectedToggleIndex == 1 - ? ColorsManager.primaryColorWithOpacity - : ColorsManager.greyColor, - alignment: Alignment.center, - child: const Text("="), - ), - ), - SizedBox( - width: 70, - height: 30, - child: Container( - color: selectedToggleIndex == 2 - ? ColorsManager.primaryColorWithOpacity - : ColorsManager.greyColor, - alignment: Alignment.center, - child: const Text(">"), - ), - ), - ], - ), + SizedBox( + width: 70, + height: 30, + child: Container( + color: selectedToggleIndex == 1 + ? ColorsManager.primaryColorWithOpacity + : ColorsManager.greyColor, + alignment: Alignment.center, + child: const Text("="), + ), + ), + SizedBox( + width: 70, + height: 30, + child: Container( + color: selectedToggleIndex == 2 + ? ColorsManager.primaryColorWithOpacity + : ColorsManager.greyColor, + alignment: Alignment.center, + child: const Text(">"), + ), + ), + ], + ) + : SizedBox(), const SizedBox(height: 12), ...widget.taskItem.operationalValues.map( (operation) => BlocBuilder( diff --git a/lib/generated/assets.dart b/lib/generated/assets.dart index 700c631..9a3876e 100644 --- a/lib/generated/assets.dart +++ b/lib/generated/assets.dart @@ -1156,4 +1156,9 @@ class Assets { 'assets/icons/target_confirm_time_icon.svg'; static const String disappeDelayIcon = 'assets/icons/disappe_delay_icon.svg'; static const String flushIcon = 'assets/icons/flush_icon.svg'; + static const String IlluminanceIcon = 'assets/icons/Illuminance_icon.svg'; + static const String nobodyTime = "assets/icons/nobody_time.svg"; + static const String currentDistanceIcon = 'assets/icons/distance_icon.svg'; + static const String delayIcon = 'assets/icons/delay_icon.svg'; + static const String levelIcon = 'assets/icons/level_icon.svg'; }