diff --git a/lib/features/devices/model/device_model.dart b/lib/features/devices/model/device_model.dart index 24cd95e..4109397 100644 --- a/lib/features/devices/model/device_model.dart +++ b/lib/features/devices/model/device_model.dart @@ -44,7 +44,8 @@ class DeviceModel { if (type == DeviceType.LightBulb) { tempIcon = Assets.assetsIconsLight; - } else if (type == DeviceType.CeilingSensor || type == DeviceType.WallSensor) { + } else if (type == DeviceType.CeilingSensor || + type == DeviceType.WallSensor) { tempIcon = Assets.assetsIconsSensors; } else if (type == DeviceType.AC) { tempIcon = Assets.assetsIconsAC; @@ -93,5 +94,6 @@ class DeviceModel { }; } - List getFunctions(DeviceType type) => devicesFunctionsMap[productType] ?? []; + List getFunctions(DeviceType type) => + devicesFunctionsMap[productType] ?? []; } 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 4e95171..9033d6d 100644 --- a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart +++ b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart @@ -40,19 +40,25 @@ class CreateSceneBloc extends Bloc FutureOr _onAddSceneTask( AddTaskEvent event, Emitter emit) { + emit(CreateSceneLoading()); if (event.isAutomation == true) { final copyList = List.from(automationTempTasksList); automationTasksList.addAll(copyList); automationTempTasksList.clear(); automationSelectedValues.clear(); emit(AddSceneTask( - tasksList: tasksList, automationTasksList: automationTasksList)); + automationTasksList: automationTasksList, + tasksList: tasksList, + )); } else { final copyList = List.from(tempTasksList); tasksList.addAll(copyList); tempTasksList.clear(); selectedValues.clear(); - emit(AddSceneTask(tasksList: tasksList)); + emit(AddSceneTask( + tasksList: tasksList, + automationTasksList: automationTasksList, + )); } } @@ -111,198 +117,9 @@ class CreateSceneBloc extends Bloc tempTasksList.add(newElement); selectedValues[newElement.code] = event.deviceControlModel.value; } - emit(TempHoldSceneTask(tempTasksList: tempTasksList)); - emit(AddSceneTask(tasksList: tasksList)); - } - FutureOr _selectedValue( - SelectedValueEvent event, Emitter emit) { - if (event.isAutomation == true) { - automationSelectedValues[event.code] = event.value; - emit(SelectedTaskValueState(value: event.value)); - emit(AddSceneTask( - tasksList: tasksList, automationTasksList: automationTasksList)); - } else { - selectedValues[event.code] = event.value; - emit(SelectedTaskValueState(value: event.value)); - emit(AddSceneTask(tasksList: tasksList)); - } - } - - FutureOr _removeTaskById( - RemoveTaskByIdEvent event, Emitter emit) { - emit(CreateSceneLoading()); - if (event.isAutomation == true) { - for (var element in automationTasksList) { - if (element.uniqueCustomId == event.taskId) { - automationTasksList.remove(element); - emit(AddSceneTask( - tasksList: tasksList, automationTasksList: automationTasksList)); - break; - } - } - } else { - for (var element in tasksList) { - if (element.uniqueCustomId == event.taskId) { - tasksList.remove(element); - - emit(AddSceneTask(tasksList: tasksList)); - break; - } - } - } - } - - FutureOr _removeTempTaskById( - RemoveTempTaskByIdEvent event, Emitter emit) { - if (event.isAutomation == true) { - for (var element in automationTempTasksList) { - if (element.uniqueCustomId == event.code) { - automationTempTasksList.remove(element); - emit(AddSceneTask( - tasksList: tasksList, automationTasksList: automationTasksList)); - break; - } - } - } else { - for (var element in tempTasksList) { - if (element.code == event.code) { - tempTasksList.remove(element); - - emit(AddSceneTask(tasksList: tasksList)); - - break; - } - } - } - } - - FutureOr _createSceneWithTasks( - CreateSceneWithTasksEvent event, Emitter emit) async { - emit(CreateSceneLoading()); - try { - final response = event.updateScene - ? await SceneApi.updateScene(event.createSceneModel, event.sceneId) - : await SceneApi.createScene(event.createSceneModel); - if (response['success'] == true) { - tasksList.clear(); - tempTasksList.clear(); - selectedValues.clear(); - emit(const CreateSceneWithTasks(success: true)); - } else { - emit(const CreateSceneError(message: 'Something went wrong')); - } - } catch (e) { - emit(const CreateSceneError(message: 'Something went wrong')); - emit(AddSceneTask(tasksList: tasksList)); - } - } - - FutureOr _clearTaskList( - ClearTaskListEvent event, Emitter emit) { - if (event.isAutomation == true) { - automationTasksList.clear(); - emit(AddSceneTask( - tasksList: tasksList, automationTasksList: automationTasksList)); - } else { - tasksList.clear(); - emit(AddSceneTask(tasksList: tasksList)); - } - } - - FutureOr _fetchSceneTasks( - FetchSceneTasksEvent event, Emitter emit) async { - emit(CreateSceneLoading()); - - try { - final response = await SceneApi.getSceneDetails(event.sceneId); - if (response.id.isNotEmpty) { - tasksList = List.from( - getTaskListFunctionsFromApi(actions: response.actions)); - emit(AddSceneTask( - tasksList: tasksList, - )); - } else { - emit(const CreateSceneError(message: 'Something went wrong')); - } - } catch (e) { - emit(const CreateSceneError(message: 'Something went wrong')); - } - } - - FutureOr _clearTempTaskList( - ClearTempTaskListEvent event, Emitter emit) { - if (event.isAutomation == true) { - automationTempTasksList.clear(); - automationSelectedValues.clear(); - emit(AddSceneTask( - tasksList: tasksList, automationTasksList: automationTasksList)); - } else { - tempTasksList.clear(); - selectedValues.clear(); - emit(AddSceneTask(tasksList: tempTasksList)); - } - } - - FutureOr _removeFromSelectedValueById( - RemoveFromSelectedValueById event, Emitter emit) { - if (event.isAutomation == true) { - if (automationSelectedValues.containsKey(event.code)) { - automationSelectedValues.remove(event.code); - emit(const SelectedTaskValueState(value: null)); - emit(AddSceneTask( - tasksList: tasksList, automationTasksList: automationTasksList)); - } - } else { - if (selectedValues.containsKey(event.code)) { - selectedValues.remove(event.code); - emit(const SelectedTaskValueState(value: null)); - emit(AddSceneTask(tasksList: tasksList)); - } - } - } - - FutureOr _deleteScene( - DeleteSceneEvent event, Emitter emit) async { - emit(DeleteSceneLoading()); - - try { - final response = await SceneApi.deleteScene( - sceneId: event.sceneId, unitUuid: event.unitUuid); - if (response == true) { - emit(const DeleteSceneSuccess(true)); - } else { - emit(const DeleteSceneError(message: 'Something went wrong')); - } - } catch (e) { - emit(const DeleteSceneError(message: 'Something went wrong')); - } - } - - FutureOr _updateTaskValue( - UpdateTaskEvent event, Emitter emit) { - if (event.isAutomation == true) { - for (var i = 0; i < automationTasksList.length; i++) { - if (automationTasksList[i].uniqueCustomId == event.taskId) { - automationTasksList[i] = automationTasksList[i].copyWith( - functionValue: event.newValue, - ); - break; - } - } - emit(AddSceneTask( - tasksList: tasksList, automationTasksList: automationTasksList)); - } else { - for (var i = 0; i < tasksList.length; i++) { - if (tasksList[i].uniqueCustomId == event.taskId) { - tasksList[i] = tasksList[i].copyWith( - functionValue: event.newValue, - ); - break; - } - } - emit(AddSceneTask(tasksList: tasksList)); - } + emit(AddSceneTask( + tasksList: tasksList, automationTasksList: automationTasksList)); } void addToTempAutomationTaskList( @@ -354,10 +171,200 @@ class CreateSceneBloc extends Bloc automationSelectedValues[newElement.code] = event.deviceControlModel.value; } - emit(TempHoldSceneTask( - tempTasksList: tempTasksList, - automationTempTasksList: automationTempTasksList)); emit(AddSceneTask( tasksList: tasksList, automationTasksList: automationTasksList)); } + + FutureOr _selectedValue( + SelectedValueEvent event, Emitter emit) { + if (event.isAutomation == true) { + automationSelectedValues[event.code] = event.value; + emit(SelectedTaskValueState(value: event.value)); + emit(AddSceneTask( + tasksList: tasksList, automationTasksList: automationTasksList)); + } else { + selectedValues[event.code] = event.value; + emit(SelectedTaskValueState(value: event.value)); + emit(AddSceneTask( + tasksList: tasksList, automationTasksList: automationTasksList)); + } + } + + FutureOr _removeTaskById( + RemoveTaskByIdEvent event, Emitter emit) { + emit(CreateSceneLoading()); + if (event.isAutomation == true) { + for (var element in automationTasksList) { + if (element.uniqueCustomId == event.taskId) { + automationTasksList.remove(element); + emit(AddSceneTask( + tasksList: tasksList, automationTasksList: automationTasksList)); + break; + } + } + } else { + for (var element in tasksList) { + if (element.uniqueCustomId == event.taskId) { + tasksList.remove(element); + + emit(AddSceneTask( + tasksList: tasksList, automationTasksList: automationTasksList)); + break; + } + } + } + } + + FutureOr _removeTempTaskById( + RemoveTempTaskByIdEvent event, Emitter emit) { + if (event.isAutomation == true) { + for (var element in automationTempTasksList) { + if (element.uniqueCustomId == event.code) { + automationTempTasksList.remove(element); + emit(AddSceneTask( + tasksList: tasksList, automationTasksList: automationTasksList)); + break; + } + } + } else { + for (var element in tempTasksList) { + if (element.code == event.code) { + tempTasksList.remove(element); + + emit(AddSceneTask( + tasksList: tasksList, automationTasksList: automationTasksList)); + + break; + } + } + } + } + + FutureOr _createSceneWithTasks( + CreateSceneWithTasksEvent event, Emitter emit) async { + emit(CreateSceneLoading()); + try { + final response = event.updateScene + ? await SceneApi.updateScene(event.createSceneModel, event.sceneId) + : await SceneApi.createScene(event.createSceneModel); + if (response['success'] == true) { + tasksList.clear(); + tempTasksList.clear(); + selectedValues.clear(); + emit(const CreateSceneWithTasks(success: true)); + } else { + emit(const CreateSceneError(message: 'Something went wrong')); + } + } catch (e) { + emit(const CreateSceneError(message: 'Something went wrong')); + emit(AddSceneTask( + tasksList: tasksList, automationTasksList: automationTasksList)); + } + } + + FutureOr _clearTaskList( + ClearTaskListEvent event, Emitter emit) { + automationTasksList.clear(); + tasksList.clear(); + emit(AddSceneTask( + tasksList: tasksList, automationTasksList: automationTasksList)); + } + + FutureOr _fetchSceneTasks( + FetchSceneTasksEvent event, Emitter emit) async { + emit(CreateSceneLoading()); + + try { + final response = await SceneApi.getSceneDetails(event.sceneId); + if (response.id.isNotEmpty) { + tasksList = List.from(getTaskListFunctionsFromApi( + actions: response.actions, isAutomation: false)); + emit(AddSceneTask( + tasksList: tasksList, + )); + } else { + emit(const CreateSceneError(message: 'Something went wrong')); + } + } catch (e) { + emit(const CreateSceneError(message: 'Something went wrong')); + } + } + + FutureOr _clearTempTaskList( + ClearTempTaskListEvent event, Emitter emit) { + if (event.isAutomation == true) { + automationTempTasksList.clear(); + automationSelectedValues.clear(); + emit(AddSceneTask( + tasksList: tasksList, automationTasksList: automationTasksList)); + } else { + tempTasksList.clear(); + selectedValues.clear(); + emit(AddSceneTask( + tasksList: tasksList, automationTasksList: automationTasksList)); + } + } + + FutureOr _removeFromSelectedValueById( + RemoveFromSelectedValueById event, Emitter emit) { + if (event.isAutomation == true) { + if (automationSelectedValues.containsKey(event.code)) { + automationSelectedValues.remove(event.code); + emit(const SelectedTaskValueState(value: null)); + emit(AddSceneTask( + tasksList: tasksList, automationTasksList: automationTasksList)); + } + } else { + if (selectedValues.containsKey(event.code)) { + selectedValues.remove(event.code); + emit(const SelectedTaskValueState(value: null)); + emit(AddSceneTask( + tasksList: tasksList, automationTasksList: automationTasksList)); + } + } + } + + FutureOr _deleteScene( + DeleteSceneEvent event, Emitter emit) async { + emit(DeleteSceneLoading()); + + try { + final response = await SceneApi.deleteScene( + sceneId: event.sceneId, unitUuid: event.unitUuid); + if (response == true) { + emit(const DeleteSceneSuccess(true)); + } else { + emit(const DeleteSceneError(message: 'Something went wrong')); + } + } catch (e) { + emit(const DeleteSceneError(message: 'Something went wrong')); + } + } + + FutureOr _updateTaskValue( + UpdateTaskEvent event, Emitter emit) { + if (event.isAutomation == true) { + for (var i = 0; i < automationTasksList.length; i++) { + if (automationTasksList[i].uniqueCustomId == event.taskId) { + automationTasksList[i] = automationTasksList[i].copyWith( + functionValue: event.newValue, + ); + break; + } + } + emit(AddSceneTask( + tasksList: tasksList, automationTasksList: automationTasksList)); + } else { + for (var i = 0; i < tasksList.length; i++) { + if (tasksList[i].uniqueCustomId == event.taskId) { + tasksList[i] = tasksList[i].copyWith( + functionValue: event.newValue, + ); + break; + } + } + emit(AddSceneTask( + tasksList: tasksList, automationTasksList: automationTasksList)); + } + } } diff --git a/lib/features/scene/bloc/create_scene/create_scene_event.dart b/lib/features/scene/bloc/create_scene/create_scene_event.dart index b97154b..16f0fb4 100644 --- a/lib/features/scene/bloc/create_scene/create_scene_event.dart +++ b/lib/features/scene/bloc/create_scene/create_scene_event.dart @@ -113,10 +113,12 @@ class CreateSceneWithTasksEvent extends CreateSceneEvent { final CreateSceneModel createSceneModel; final bool updateScene; final String sceneId; + //final bool isAutomation; const CreateSceneWithTasksEvent({ required this.createSceneModel, required this.updateScene, required this.sceneId, + // required this.isAutomation, }); @override 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 bb3f49d..d6f6070 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 @@ -157,18 +157,6 @@ class HumanPresenceHelperFunctions { icon: Assets.assetsAcPowerOFF, description: "OFF", value: false), ], ), - SceneStaticFunction( - deviceId: deviceId, - deviceName: deviceName, - icon: Assets.assetsNobodyTime, - operationName: 'Nobody Time', - code: 'presence_time', - functionValue: functionValue, - operationDialogType: OperationDialogType.countdown, - operationalValues: [ - SceneOperationalValue(icon: '', value: 0), - ], - ), ]; } @@ -234,142 +222,6 @@ class HumanPresenceHelperFunctions { ), ], ), - SceneStaticFunction( - deviceId: deviceId, - deviceName: deviceName, - icon: Assets.assetsFarDetection, - operationName: 'Far Detection', - code: 'far_detection', - functionValue: functionValue, - operationDialogType: OperationDialogType.listOfOptions, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 75, - description: '75cm', - iconValue: '75', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 150, - description: '150cm', - iconValue: '150', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 225, - description: '225cm', - iconValue: '225', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 300, - description: '300cm', - iconValue: '300', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 375, - description: '375cm', - iconValue: '375', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 450, - description: '450cm', - iconValue: '450', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 525, - description: '525cm', - iconValue: '525', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 600, - description: '600cm', - iconValue: '600', - ), - ], - ), - SceneStaticFunction( - deviceId: deviceId, - deviceName: deviceName, - icon: Assets.assetsMotionDetection, - operationName: 'Motion Detection Sensitivity', - code: 'motion_sensitivity_value', - 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(), - ), - ], - ), - SceneStaticFunction( - deviceId: deviceId, - deviceName: deviceName, - icon: Assets.assetsMotionlessDetection, - operationName: 'Motionless Detection Sensitivity', - code: 'motionless_sensitivity', - functionValue: functionValue, - operationDialogType: OperationDialogType.listOfOptions, - operationalValues: [ - SceneOperationalValue( - iconValue: '1', - icon: Assets.assetsFarDetectionFunction, - value: 1, - description: '1', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 2, - description: '2', - iconValue: '2', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 3, - description: '3', - iconValue: '3', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 4, - description: '4', - iconValue: '4', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 5, - description: '5', - iconValue: '5', - ), - ], - ), SceneStaticFunction( deviceId: deviceId, deviceName: deviceName, @@ -395,13 +247,12 @@ class HumanPresenceHelperFunctions { operationDialogType: OperationDialogType.integerSteps, operationalValues: [ SceneOperationalValue( - icon: '', - value: 0.0, - minValue: 0.0, - maxValue: 65535, - stepValue: 1, - description: 'min' - ), + icon: '', + value: 0.0, + minValue: 0.0, + maxValue: 65535, + stepValue: 1, + description: 'min'), ], ), ]; diff --git a/lib/features/scene/helper/scene_logic_helper.dart b/lib/features/scene/helper/scene_logic_helper.dart index 3c115b4..a6f6ad8 100644 --- a/lib/features/scene/helper/scene_logic_helper.dart +++ b/lib/features/scene/helper/scene_logic_helper.dart @@ -81,9 +81,8 @@ mixin SceneLogicHelper { } Widget getTheCorrectDialogBody( - SceneStaticFunction taskItem, - dynamic functionValue, - ) { + SceneStaticFunction taskItem, dynamic functionValue, + {required bool isAutomation}) { if (taskItem.operationDialogType == OperationDialogType.temperature) { return AlertDialogTemperatureBody( taskItem: taskItem, @@ -102,12 +101,14 @@ mixin SceneLogicHelper { return AlertDialogSliderSteps( taskItem: taskItem, functionValue: functionValue ?? taskItem.functionValue, + isAutomation: isAutomation, ); } return AlertDialogFunctionsOperationsBody( taskItem: taskItem, functionValue: functionValue ?? taskItem.functionValue, + isAutomation: isAutomation, ); } } diff --git a/lib/features/scene/helper/scene_operations_data_helper.dart b/lib/features/scene/helper/scene_operations_data_helper.dart index f53708a..dff462b 100644 --- a/lib/features/scene/helper/scene_operations_data_helper.dart +++ b/lib/features/scene/helper/scene_operations_data_helper.dart @@ -20,79 +20,36 @@ mixin SceneOperationsDataHelper { required String deviceName, required bool isAutomation, }) { + const functionValue = null; + switch (type) { case DeviceType.LightBulb: return lightBulbFunctions( - functions: functions, - deviceId: deviceId, - deviceName: deviceName, - functionValue: null, - isAutomation: isAutomation, - ); + functions, deviceId, deviceName, functionValue, isAutomation); case DeviceType.CeilingSensor: return ceilingSensorFunctions( - functions: functions, - deviceId: deviceId, - deviceName: deviceName, - functionValue: null, - isAutomation: isAutomation, - ); + functions, deviceId, deviceName, functionValue, isAutomation); case DeviceType.WallSensor: return wallSensorFunctions( - functions: functions, - deviceId: deviceId, - deviceName: deviceName, - functionValue: null, - isAutomation: isAutomation, - ); + functions, deviceId, deviceName, functionValue, isAutomation); case DeviceType.AC: return acFunctions( - functions: functions, - deviceId: deviceId, - deviceName: deviceName, - functionValue: null, - isAutomation: isAutomation, - ); + functions, deviceId, deviceName, functionValue, isAutomation); case DeviceType.DoorLock: return doorLockFunctions( - functions: functions, - deviceId: deviceId, - deviceName: deviceName, - functionValue: null, - isAutomation: isAutomation, - ); + functions, deviceId, deviceName, functionValue, isAutomation); case DeviceType.Curtain: return curtainFunctions( - functions: functions, - deviceId: deviceId, - deviceName: deviceName, - functionValue: null, - isAutomation: isAutomation, - ); + functions, deviceId, deviceName, functionValue, isAutomation); case DeviceType.ThreeGang: return threeGangFunctions( - functions: functions, - deviceId: deviceId, - deviceName: deviceName, - functionValue: null, - isAutomation: isAutomation, - ); + functions, deviceId, deviceName, functionValue, isAutomation); case DeviceType.Gateway: return gatewayFunctions( - functions: functions, - deviceId: deviceId, - deviceName: deviceName, - functionValue: null, - isAutomation: isAutomation, - ); + functions, deviceId, deviceName, functionValue, isAutomation); default: return lightBulbFunctions( - functions: functions, - deviceId: deviceId, - deviceName: deviceName, - functionValue: null, - isAutomation: isAutomation, - ); + functions, deviceId, deviceName, functionValue, isAutomation); } } @@ -119,14 +76,12 @@ mixin SceneOperationsDataHelper { } } - /// presence sensor - List ceilingSensorFunctions({ - required List functions, - required String deviceId, - required String deviceName, - required dynamic functionValue, - required bool isAutomation, - }) { + List ceilingSensorFunctions( + List functions, + String deviceId, + String deviceName, + dynamic functionValue, + bool isAutomation) { if (isAutomation) { return PresenceSensorHelperFunctions.automationPresenceSensorFunctions( deviceId, deviceName, functionValue); @@ -136,21 +91,20 @@ mixin SceneOperationsDataHelper { } List curtainFunctions( - {required List functions, - required String deviceId, - required String deviceName, - required functionValue, - required bool isAutomation}) { + List functions, + String deviceId, + String deviceName, + dynamic functionValue, + bool isAutomation) { return []; } - List doorLockFunctions({ - required List functions, - required String deviceId, - required String deviceName, - required functionValue, - required bool isAutomation, - }) { + List doorLockFunctions( + List functions, + String deviceId, + String deviceName, + dynamic functionValue, + bool isAutomation) { if (isAutomation) { return DoorLockHelperFunctions.doorLockAutomationFunctions( deviceId, deviceName, functionValue); @@ -159,13 +113,12 @@ mixin SceneOperationsDataHelper { deviceId, deviceName, functionValue); } - List wallSensorFunctions({ - required List functions, - required String deviceId, - required String deviceName, - required functionValue, - required bool isAutomation, - }) { + List wallSensorFunctions( + List functions, + String deviceId, + String deviceName, + dynamic functionValue, + bool isAutomation) { if (isAutomation) { return HumanPresenceHelperFunctions.automationHumanPresenceFunctions( deviceId, deviceName, functionValue); @@ -175,32 +128,30 @@ mixin SceneOperationsDataHelper { } List lightBulbFunctions( - {required List functions, - required String deviceId, - required String deviceName, - required functionValue, - required bool isAutomation}) { + List functions, + String deviceId, + String deviceName, + dynamic functionValue, + bool isAutomation) { return []; } - List gatewayFunctions({ - required List functions, - required String deviceId, - required String deviceName, - required functionValue, - required bool isAutomation, - }) { + List gatewayFunctions( + List functions, + String deviceId, + String deviceName, + dynamic functionValue, + bool isAutomation) { return GatewayHelperFunctions.tabToRunGatewayFunctions( deviceId, deviceName, functionValue); } - List threeGangFunctions({ - required List functions, - required String deviceId, - required String deviceName, - required functionValue, - required bool isAutomation, - }) { + List threeGangFunctions( + List functions, + String deviceId, + String deviceName, + dynamic functionValue, + bool isAutomation) { if (isAutomation) { return ThreeGangHelperFunctions.threeGangAutomationFunctions( deviceId, deviceName, functionValue); @@ -209,14 +160,12 @@ mixin SceneOperationsDataHelper { deviceId, deviceName, functionValue); } - /// smart ac thermostat - List acFunctions({ - required List functions, - required String deviceId, - required String deviceName, - required functionValue, - required bool isAutomation, - }) { + List acFunctions( + List functions, + String deviceId, + String deviceName, + dynamic functionValue, + bool isAutomation) { if (isAutomation) { return ACFunctionsHelper.automationAcFunctions( deviceId, deviceName, functionValue); @@ -225,14 +174,9 @@ mixin SceneOperationsDataHelper { deviceId, deviceName, functionValue); } -///////&************ END of get function with icons for device *************&&//////// - /// - /// - List getTaskListFunctionsFromApi({ - required List actions, - }) { + List getTaskListFunctionsFromApi( + {required List actions, required bool isAutomation}) { List functions = []; - for (var action in actions) { if (action.entityId == 'delay') { functions.add( @@ -247,648 +191,366 @@ mixin SceneOperationsDataHelper { code: '', operationalValues: [ SceneOperationalValue( - icon: '', - description: "", - value: action.executorProperty.delaySeconds, - ), + icon: '', + description: "", + value: action.executorProperty.delaySeconds), ], ), ); - } - ExecutorProperty executorProperty = action.executorProperty; - - switch (executorProperty.functionCode) { - case 'sensitivity': - functions.add( - SceneStaticFunction( - deviceId: action.entityId, - deviceName: 'Presence Sensor', - deviceIcon: Assets.assetsIconsSensors, - icon: Assets.assetsSensitivityFunction, - operationName: 'Sensitivity', - code: 'sensitivity', - functionValue: executorProperty.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(), - ), - SceneOperationalValue( - icon: Assets.assetsSensitivityOperationIcon, - value: 10, - description: 10.toString(), - ), - ], - ), - ); - break; - case 'normal_open_switch': - functions.add( - SceneStaticFunction( - deviceId: action.entityId, - deviceName: 'WIFI LOCK PRO', - deviceIcon: Assets.assetsIconsDoorLock, - icon: Assets.assetsIconsDoorLock, - operationName: 'Set Door lock Normal Open', - functionValue: executorProperty.functionValue, - code: 'normal_open_switch', - operationDialogType: OperationDialogType.onOff, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcPower, description: "ON", value: true), - SceneOperationalValue( - icon: Assets.assetsAcPowerOFF, - description: "OFF", - value: false, - ), - ], - ), - ); - break; - case 'far_detection': - functions.add( - SceneStaticFunction( - deviceId: action.entityId, - deviceName: 'Human Presence Sensor', - deviceIcon: Assets.assetsIconsSensors, - icon: Assets.assetsFarDetection, - operationName: 'Far Detection', - functionValue: executorProperty.functionValue, - code: 'far_detection', - operationDialogType: OperationDialogType.listOfOptions, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 75, - description: '75cm', - iconValue: '75', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 150, - description: '150cm', - iconValue: '150', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 225, - description: '225cm', - iconValue: '225', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 300, - description: '300cm', - iconValue: '300', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 375, - description: '375cm', - iconValue: '375', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 450, - description: '450cm', - iconValue: '450', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 525, - description: '525cm', - iconValue: '525', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 600, - description: '600cm', - iconValue: '600', - ), - ], - ), - ); - break; - case 'motion_sensitivity_value': - functions.add( - SceneStaticFunction( - deviceId: action.entityId, - deviceName: 'Human Presence Sensor', - deviceIcon: Assets.assetsIconsSensors, - icon: Assets.assetsMotionDetection, - operationName: 'Motion Detection Sensitivity', - functionValue: executorProperty.functionValue, - code: 'motion_sensitivity_value', - 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(), - ), - ], - ), - ); - break; - case 'motionless_sensitivity': - functions.add( - SceneStaticFunction( - deviceId: action.entityId, - deviceName: 'Human Presence Sensor', - deviceIcon: Assets.assetsIconsSensors, - icon: Assets.assetsMotionlessDetection, - operationName: 'Motionless Detection Sensitivity', - functionValue: executorProperty.functionValue, - code: 'motion_sensitivity_value', - operationDialogType: OperationDialogType.listOfOptions, - operationalValues: [ - SceneOperationalValue( - iconValue: '1', - icon: Assets.assetsFarDetectionFunction, - value: 1, - description: '1', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 2, - description: '2', - iconValue: '2', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 3, - description: '3', - iconValue: '3', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 4, - description: '4', - iconValue: '4', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 5, - description: '5', - iconValue: '5', - ), - ], - ), - ); - break; - case 'indicator': - functions.add( - SceneStaticFunction( - deviceId: action.entityId, - deviceName: 'Human Presence Sensor', - deviceIcon: Assets.assetsIconsSensors, - icon: Assets.assetsIndicator, - operationName: 'Indicator', - functionValue: executorProperty.functionValue, - code: 'indicator', - operationDialogType: OperationDialogType.onOff, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcPower, - description: "ON", - value: true, - ), - SceneOperationalValue( - icon: Assets.assetsAcPowerOFF, - description: "OFF", - value: false, - ), - ], - ), - ); - break; - case 'presence_time': - functions.add( - SceneStaticFunction( - deviceId: action.entityId, - deviceName: 'Human Presence Sensor', - deviceIcon: Assets.assetsIconsSensors, - icon: Assets.assetsNobodyTime, - operationName: 'Nobody Time', - functionValue: executorProperty.functionValue, - code: 'presence_time', - operationDialogType: OperationDialogType.temperature, - operationalValues: [ - SceneOperationalValue(icon: '', value: 0), - ], - ), - ); - break; - case 'switch_alarm_sound': - functions.add( - SceneStaticFunction( - deviceId: action.entityId, - deviceName: 'Multi-Mode Gateway Z-W-B', - deviceIcon: Assets.assetsIconsGateway, - icon: Assets.assetsSwitchAlarmSound, - operationName: 'Switch Alarm Sound', - functionValue: executorProperty.functionValue, - code: 'switch_alarm_sound', - operationDialogType: OperationDialogType.onOff, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcPower, - description: "ON", - value: true, - ), - SceneOperationalValue( - icon: Assets.assetsAcPowerOFF, - description: "OFF", - value: false), - ], - ), - ); - break; - case 'master_state': - functions.add( - SceneStaticFunction( - deviceId: action.entityId, - deviceName: 'Multi-Mode Gateway Z-W-B', - deviceIcon: Assets.assetsIconsGateway, - icon: Assets.assetsMasterState, - operationName: 'Master State', - functionValue: executorProperty.functionValue, - code: 'master_state', - operationDialogType: OperationDialogType.listOfOptions, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcPower, - description: "Alarm", - value: 'alarm', - ), - SceneOperationalValue( - icon: Assets.assetsAcPowerOFF, - description: "Normal", - value: 'normal', - ), - ], - ), - ); - break; - case 'factory_reset': - functions.add( - SceneStaticFunction( - deviceId: action.entityId, - deviceName: 'Multi-Mode Gateway Z-W-B', - deviceIcon: Assets.assetsIconsGateway, - icon: Assets.assetsFactoryReset, - operationName: 'Reset Factory', - functionValue: executorProperty.functionValue, - code: 'factory_reset', - operationDialogType: OperationDialogType.onOff, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsSceneRefresh, - description: "ON", - value: true), - SceneOperationalValue( - icon: Assets.assetsResetOff, - description: "OFF", - value: false, - ), - ], - ), - ); - break; - case 'switch_1': - functions.add(SceneStaticFunction( - deviceId: action.entityId, - deviceName: '3 Gang Button Switch L-L', - deviceIcon: Assets.assetsIcons3GangSwitch, - icon: Assets.assetsAcPower, - operationName: 'Light 1 Switch', - code: 'switch_1', - functionValue: executorProperty.functionValue, - operationDialogType: OperationDialogType.onOff, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcPower, - description: "ON", - value: true, - ), - SceneOperationalValue( - icon: Assets.assetsAcPowerOFF, - description: "OFF", - value: false), - // SceneOperationalValue( - // icon: Assets.assetsSceneRefresh, - // description: "Reverse Switch", - // value: null, - // ), - ], - )); - break; - case 'switch_2': - functions.add(SceneStaticFunction( - deviceId: action.entityId, - deviceName: '3 Gang Button Switch L-L', - deviceIcon: Assets.assetsIcons3GangSwitch, - icon: Assets.assetsAcPower, - operationName: 'Light 2 Switch', - code: 'switch_2', - functionValue: executorProperty.functionValue, - operationDialogType: OperationDialogType.onOff, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcPower, description: "ON", value: true), - SceneOperationalValue( - icon: Assets.assetsAcPowerOFF, - description: "OFF", - value: false), - // SceneOperationalValue( - // icon: Assets.assetsSceneRefresh, - // description: "Reverse Switch", - // value: null, - // ), - ], - )); - break; - case 'switch_3': - functions.add(SceneStaticFunction( - deviceId: action.entityId, - deviceName: '3 Gang Button Switch L-L', - deviceIcon: Assets.assetsIcons3GangSwitch, - icon: Assets.assetsAcPower, - operationName: 'Light 3 Switch', - code: 'switch_3', - functionValue: executorProperty.functionValue, - operationDialogType: OperationDialogType.onOff, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcPower, description: "ON", value: true), - SceneOperationalValue( - icon: Assets.assetsAcPowerOFF, - description: "OFF", - value: false), - // SceneOperationalValue( - // icon: Assets.assetsSceneRefresh, - // description: "Reverse Switch", - // value: null, - // ), - ], - )); - break; - case 'countdown_1': - functions.add(SceneStaticFunction( - deviceId: action.entityId, - deviceName: '3 Gang Button Switch L-L', - deviceIcon: Assets.assetsIcons3GangSwitch, - icon: Assets.assetsLightCountdown, - operationName: 'Light 1 CountDown', - code: 'countdown_1', - functionValue: executorProperty.functionValue, - operationDialogType: OperationDialogType.countdown, - operationalValues: [ - SceneOperationalValue(icon: '', value: 0), - ], - )); - break; - case 'countdown_2': - functions.add(SceneStaticFunction( - deviceId: action.entityId, - deviceName: '3 Gang Button Switch L-L', - deviceIcon: Assets.assetsIcons3GangSwitch, - icon: Assets.assetsLightCountdown, - operationName: 'Light 2 CountDown', - code: 'countdown_2', - functionValue: executorProperty.functionValue, - operationDialogType: OperationDialogType.countdown, - operationalValues: [ - SceneOperationalValue(icon: '', value: 0), - ], - )); - break; - case 'countdown_3': - functions.add(SceneStaticFunction( - deviceId: action.entityId, - deviceName: '3 Gang Button Switch L-L', - deviceIcon: Assets.assetsIcons3GangSwitch, - icon: Assets.assetsLightCountdown, - operationName: 'Light 3 CountDown', - code: 'countdown_3', - functionValue: executorProperty.functionValue, - operationDialogType: OperationDialogType.countdown, - operationalValues: [ - SceneOperationalValue(icon: '', value: 0), - ], - )); - break; - case 'switch': - functions.add(SceneStaticFunction( - deviceId: action.entityId, - deviceName: 'Smart AC Thermostat - Grey - Model A', - deviceIcon: Assets.assetsIconsAC, - icon: Assets.assetsAcPower, - operationName: 'Power', - code: 'switch', - functionValue: executorProperty.functionValue, - operationDialogType: OperationDialogType.onOff, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcPower, - description: "ON", - value: true, - ), - SceneOperationalValue( - icon: Assets.assetsAcPowerOFF, - description: "OFF", - value: false, - ), - ], - )); - break; - case 'temp_set': - functions.add(SceneStaticFunction( - deviceId: action.entityId, - deviceName: 'Smart AC Thermostat - Grey - Model A', - deviceIcon: Assets.assetsIconsAC, - icon: Assets.assetsTempreture, - operationName: 'Set Temperature', - code: 'temp_set', - functionValue: executorProperty.functionValue, - operationDialogType: OperationDialogType.temperature, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsCelsiusDegrees, - value: 0, - description: 'COOL TO', - ), - ], - )); - break; - case 'mode': - functions.add(SceneStaticFunction( - deviceId: action.entityId, - deviceName: 'Smart AC Thermostat - Grey - Model A', - deviceIcon: Assets.assetsIconsAC, - icon: Assets.assetsFreezing, - operationName: 'Mode', - code: 'mode', - functionValue: executorProperty.functionValue, - operationDialogType: OperationDialogType.listOfOptions, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcCooling, - description: AcValuesEnums.Cooling.name, - value: TempModes.cold.name, - ), - SceneOperationalValue( - icon: Assets.assetsAcHeating, - description: AcValuesEnums.Heating.name, - value: TempModes.hot.name, - ), - SceneOperationalValue( - icon: Assets.assetsFanSpeed, - description: AcValuesEnums.Ventilation.name, - value: TempModes.wind.name, - ), - ], - )); - break; - case 'level': - functions.add(SceneStaticFunction( - deviceId: action.entityId, - deviceName: 'Smart AC Thermostat - Grey - Model A', - deviceIcon: Assets.assetsIconsAC, - icon: Assets.assetsFanSpeed, - operationName: 'Fan Speed', - code: 'level', - functionValue: executorProperty.functionValue, - operationDialogType: OperationDialogType.listOfOptions, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcFanLow, - description: ValueACRange.LOW.name, - value: FanSpeeds.low.name, - ), - SceneOperationalValue( - icon: Assets.assetsAcFanMiddle, - description: ValueACRange.MIDDLE.name, - value: FanSpeeds.middle.name, - ), - SceneOperationalValue( - icon: Assets.assetsAcFanHigh, - description: ValueACRange.HIGH.name, - value: FanSpeeds.high.name, - ), - SceneOperationalValue( - icon: Assets.assetsAcFanAuto, - description: ValueACRange.AUTO.name, - value: FanSpeeds.auto.name, - ), - ], - )); - break; - case 'child_lock': - functions.add(SceneStaticFunction( - deviceId: action.entityId, - deviceName: 'Smart AC Thermostat - Grey - Model A', - deviceIcon: Assets.assetsIconsAC, - icon: Assets.assetsChildLock, - operationName: 'Child Lock', - code: 'child_lock', - functionValue: executorProperty.functionValue, - operationDialogType: OperationDialogType.onOff, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsSceneChildLock, - description: 'Lock', - value: true, - ), - SceneOperationalValue( - icon: Assets.assetsSceneChildUnlock, - description: 'Unlock', - value: false, - ), - ], - )); - break; - default: + } else { + functions + .add(_mapExecutorPropertyToSceneFunction(action, isAutomation)); } } - return functions; } - ///// END of get fucntion for once device based on the CODE ***** /////// - /// - /// - /// + SceneStaticFunction _mapExecutorPropertyToSceneFunction( + Action action, bool isAutomation) { + ExecutorProperty executorProperty = action.executorProperty; + switch (executorProperty.functionCode) { + case 'sensitivity': + return _createSceneFunction( + action, + 'Presence Sensor', + Assets.assetsSensitivityFunction, + 'Sensitivity', + isAutomation + ? OperationDialogType.integerSteps + : OperationDialogType.listOfOptions, + isAutomation + ? _createIntegerStepsOptions() + : _createSensitivityOptions(), + isAutomation); + case 'normal_open_switch': + return _createSceneFunction( + action, + 'WIFI LOCK PRO', + Assets.assetsIconsDoorLock, + 'Set Door lock Normal Open', + OperationDialogType.onOff, + _createOnOffOptions(), + isAutomation); + case 'far_detection': + return _createSceneFunction( + action, + 'Human Presence Sensor', + Assets.assetsFarDetection, + 'Far Detection', + OperationDialogType.listOfOptions, + _createFarDetectionOptions(), + isAutomation); + case 'motion_sensitivity_value': + return _createSceneFunction( + action, + 'Human Presence Sensor', + Assets.assetsMotionDetection, + 'Motion Detection Sensitivity', + OperationDialogType.listOfOptions, + _createSensitivityOptions(), + isAutomation); + case 'motionless_sensitivity': + return _createSceneFunction( + action, + 'Human Presence Sensor', + Assets.assetsMotionlessDetection, + 'Motionless Detection Sensitivity', + OperationDialogType.listOfOptions, + _createSensitivityOptions(), + isAutomation); + case 'indicator': + return _createSceneFunction( + action, + 'Human Presence Sensor', + Assets.assetsIndicator, + 'Indicator', + OperationDialogType.onOff, + _createOnOffOptions(), + isAutomation); + case 'presence_time': + return _createSceneFunction( + action, + 'Human Presence Sensor', + Assets.assetsNobodyTime, + 'Nobody Time', + OperationDialogType.countdown, + _createCountdownOptions(), + isAutomation); + case 'switch_alarm_sound': + return _createSceneFunction( + action, + 'Multi-Mode Gateway Z-W-B', + Assets.assetsSwitchAlarmSound, + 'Switch Alarm Sound', + OperationDialogType.onOff, + _createOnOffOptions(), + isAutomation); + case 'master_state': + return _createSceneFunction( + action, + 'Multi-Mode Gateway Z-W-B', + Assets.assetsMasterState, + 'Master State', + OperationDialogType.listOfOptions, + _createMasterStateOptions(), + isAutomation); + case 'factory_reset': + return _createSceneFunction( + action, + 'Multi-Mode Gateway Z-W-B', + Assets.assetsFactoryReset, + 'Reset Factory', + OperationDialogType.onOff, + _createOnOffOptions(), + isAutomation); + case 'switch_1': + return _createSceneFunction( + action, + '3 Gang Button Switch L-L', + Assets.assetsAcPower, + 'Light 1 Switch', + OperationDialogType.onOff, + _createOnOffOptions(), + isAutomation); + case 'switch_2': + return _createSceneFunction( + action, + '3 Gang Button Switch L-L', + Assets.assetsAcPower, + 'Light 2 Switch', + OperationDialogType.onOff, + _createOnOffOptions(), + isAutomation); + case 'switch_3': + return _createSceneFunction( + action, + '3 Gang Button Switch L-L', + Assets.assetsAcPower, + 'Light 3 Switch', + OperationDialogType.onOff, + _createOnOffOptions(), + isAutomation); + case 'countdown_1': + return _createSceneFunction( + action, + '3 Gang Button Switch L-L', + Assets.assetsLightCountdown, + 'Light 1 CountDown', + OperationDialogType.countdown, + _createCountdownOptions(), + isAutomation); + case 'countdown_2': + return _createSceneFunction( + action, + '3 Gang Button Switch L-L', + Assets.assetsLightCountdown, + 'Light 2 CountDown', + OperationDialogType.countdown, + _createCountdownOptions(), + isAutomation); + case 'countdown_3': + return _createSceneFunction( + action, + '3 Gang Button Switch L-L', + Assets.assetsLightCountdown, + 'Light 3 CountDown', + OperationDialogType.countdown, + _createCountdownOptions(), + isAutomation); + case 'switch': + return _createSceneFunction( + action, + 'Smart AC Thermostat - Grey - Model A', + Assets.assetsAcPower, + 'Power', + OperationDialogType.onOff, + _createOnOffOptions(), + isAutomation); + case 'temp_set': + return _createSceneFunction( + action, + 'Smart AC Thermostat - Grey - Model A', + Assets.assetsTempreture, + 'Set Temperature', + isAutomation + ? OperationDialogType.integerSteps + : OperationDialogType.temperature, + isAutomation + ? _createAutomationTemperatureOptions() + : _createTemperatureOptions(), + isAutomation); + case 'mode': + return _createSceneFunction( + action, + 'Smart AC Thermostat - Grey - Model A', + Assets.assetsFreezing, + 'Mode', + OperationDialogType.listOfOptions, + _createAcModeOptions(), + isAutomation); + case 'level': + return _createSceneFunction( + action, + 'Smart AC Thermostat - Grey - Model A', + Assets.assetsFanSpeed, + 'Fan Speed', + OperationDialogType.listOfOptions, + _createFanSpeedOptions(), + isAutomation); + case 'child_lock': + return _createSceneFunction( + action, + 'Smart AC Thermostat - Grey - Model A', + Assets.assetsChildLock, + 'Child Lock', + OperationDialogType.onOff, + _createOnOffOptions(), + isAutomation); + default: + throw ArgumentError( + 'Unsupported function code: ${executorProperty.functionCode}'); + } + } - List getOperationsForOneFunction({ - required String deviceId, - required SceneStaticFunction taskItem, - }) { - List functions = []; + List _createAutomationTemperatureOptions() { + return [ + SceneOperationalValue( + icon: Assets.assetsCelsiusDegrees, + value: 0.0, + description: '°C', + minValue: 20, + maxValue: 30, + stepValue: 0.5) + ]; + } + + List _createIntegerStepsOptions() { + return [ + SceneOperationalValue( + icon: '', + value: 0.0, + description: "CM", + minValue: 1, + maxValue: 600, + stepValue: 1) + ]; + } + + SceneStaticFunction _createSceneFunction( + Action action, + String deviceName, + String icon, + String operationName, + OperationDialogType operationDialogType, + List operationalValues, + bool isAutomation) { + final functionValue = action.executorProperty.functionValue; + return SceneStaticFunction( + deviceId: action.entityId, + deviceName: deviceName, + deviceIcon: icon, + icon: icon, + operationName: operationName, + functionValue: functionValue, + code: action.executorProperty.functionCode ?? '', + operationDialogType: operationDialogType, + operationalValues: operationalValues, + ); + } + + List _createOnOffOptions() { + return [ + SceneOperationalValue( + icon: Assets.assetsAcPower, description: "ON", value: true), + SceneOperationalValue( + icon: Assets.assetsAcPowerOFF, description: "OFF", value: false), + ]; + } + + List _createSensitivityOptions() { + return List.generate( + 10, + (index) => SceneOperationalValue( + icon: Assets.assetsSensitivityOperationIcon, + value: index + 1, + description: (index + 1).toString())); + } + + List _createFarDetectionOptions() { + final distances = [75, 150, 225, 300, 375, 450, 525, 600]; + return distances + .map((distance) => SceneOperationalValue( + icon: Assets.assetsFarDetectionFunction, + value: distance, + description: '${distance}cm', + iconValue: distance.toString())) + .toList(); + } + + List _createTemperatureOptions() { + return [ + SceneOperationalValue( + icon: Assets.assetsCelsiusDegrees, value: 0, description: 'COOL TO') + ]; + } + + List _createMasterStateOptions() { + return [ + SceneOperationalValue( + icon: Assets.assetsAcPower, description: "Alarm", value: 'alarm'), + SceneOperationalValue( + icon: Assets.assetsAcPowerOFF, + description: "Normal", + value: 'normal'), + ]; + } + + List _createAcModeOptions() { + return [ + SceneOperationalValue( + icon: Assets.assetsAcCooling, + description: AcValuesEnums.Cooling.name, + value: TempModes.cold.name), + SceneOperationalValue( + icon: Assets.assetsAcHeating, + description: AcValuesEnums.Heating.name, + value: TempModes.hot.name), + SceneOperationalValue( + icon: Assets.assetsFanSpeed, + description: AcValuesEnums.Ventilation.name, + value: TempModes.wind.name), + ]; + } + + List _createFanSpeedOptions() { + return [ + SceneOperationalValue( + icon: Assets.assetsAcFanLow, + description: ValueACRange.LOW.name, + value: FanSpeeds.low.name), + SceneOperationalValue( + icon: Assets.assetsAcFanMiddle, + description: ValueACRange.MIDDLE.name, + value: FanSpeeds.middle.name), + SceneOperationalValue( + icon: Assets.assetsAcFanHigh, + description: ValueACRange.HIGH.name, + value: FanSpeeds.high.name), + SceneOperationalValue( + icon: Assets.assetsAcFanAuto, + description: ValueACRange.AUTO.name, + value: FanSpeeds.auto.name), + ]; + } + + List _createCountdownOptions() { + return [SceneOperationalValue(icon: '', value: 0)]; + } + + List getOperationsForOneFunction( + {required String deviceId, required SceneStaticFunction taskItem}) { if (deviceId.contains('delay')) { - functions.add( + return [ SceneStaticFunction( deviceId: taskItem.deviceId, deviceName: 'delay', @@ -899,733 +561,21 @@ mixin SceneOperationsDataHelper { code: '', operationDialogType: OperationDialogType.delay, operationalValues: [ - SceneOperationalValue( - icon: '', - description: "", - value: 0, - ), + SceneOperationalValue(icon: '', description: "", value: 0) ], ), - ); - return functions; - } - switch (taskItem.code) { - case 'sensitivity': - functions.add( - sensitivityFunctionsBasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'normal_open_switch': - functions.add( - normalOpenSwitchBasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'far_detection': - functions.add( - farDetectionBasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'motion_sensitivity_value': - functions.add( - motionSensitivityValueBasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'motionless_sensitivity': - functions.add( - motionlessSensitivityBasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'indicator': - functions.add( - indicatorBasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'presence_time': - functions.add( - presenceTimeBasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'switch_alarm_sound': - functions.add( - switchAlarmSoundBasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'master_state': - functions.add( - masterStateBasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'factory_reset': - functions.add( - factoryResetBasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'switch_1': - functions.add( - switch1BasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'switch_2': - functions.add( - switch2BasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'switch_3': - functions.add( - switch3BasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'countdown_1': - functions.add( - countdown1BasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'countdown_2': - functions.add( - countdown2BasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'countdown_3': - functions.add( - countdown3BasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'switch': - functions.add( - switchBasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'temp_set': - functions.add( - tempSetBasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'mode': - functions.add( - modeBasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'level': - functions.add( - levelBasedOnCodeMatch(deviceId, taskItem), - ); - break; - case 'child_lock': - functions.add( - childLockBasedOnCodeMatch(deviceId, taskItem), - ); - break; - default: + ]; } - return functions; - } - - SceneStaticFunction childLockBasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: 'Smart AC Thermostat - Grey - Model A', - deviceIcon: Assets.assetsIconsAC, - icon: Assets.assetsChildLock, - operationName: 'Child Lock', - code: 'child_lock', - functionValue: taskItem.functionValue, - operationDialogType: OperationDialogType.onOff, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsSceneChildLock, - description: 'Lock', - value: true, - ), - SceneOperationalValue( - icon: Assets.assetsSceneChildUnlock, - description: 'Unlock', - value: false, - ), - ], - ); - } - - SceneStaticFunction levelBasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: 'Smart AC Thermostat - Grey - Model A', - deviceIcon: Assets.assetsIconsAC, - icon: Assets.assetsFanSpeed, - operationName: 'Fan Speed', - code: 'level', - functionValue: taskItem.functionValue, - operationDialogType: OperationDialogType.listOfOptions, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcFanLow, - description: ValueACRange.LOW.name, - value: FanSpeeds.low.name, - ), - SceneOperationalValue( - icon: Assets.assetsAcFanMiddle, - description: ValueACRange.MIDDLE.name, - value: FanSpeeds.middle.name, - ), - SceneOperationalValue( - icon: Assets.assetsAcFanHigh, - description: ValueACRange.HIGH.name, - value: FanSpeeds.high.name, - ), - SceneOperationalValue( - icon: Assets.assetsAcFanAuto, - description: ValueACRange.AUTO.name, - value: FanSpeeds.auto.name, - ), - ], - ); - } - - SceneStaticFunction modeBasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: 'Smart AC Thermostat - Grey - Model A', - deviceIcon: Assets.assetsIconsAC, - icon: Assets.assetsFreezing, - operationName: 'Mode', - code: 'mode', - functionValue: taskItem.functionValue, - operationDialogType: OperationDialogType.listOfOptions, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcCooling, - description: AcValuesEnums.Cooling.name, - value: TempModes.cold.name, - ), - SceneOperationalValue( - icon: Assets.assetsAcHeating, - description: AcValuesEnums.Heating.name, - value: TempModes.hot.name, - ), - SceneOperationalValue( - icon: Assets.assetsFanSpeed, - description: AcValuesEnums.Ventilation.name, - value: TempModes.wind.name, - ), - ], - ); - } - - SceneStaticFunction tempSetBasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: 'Smart AC Thermostat - Grey - Model A', - deviceIcon: Assets.assetsIconsAC, - icon: Assets.assetsTempreture, - operationName: 'Set Temperature', - code: 'temp_set', - functionValue: taskItem.functionValue != null - ? ((taskItem.functionValue / 10) as double).toInt() - : null, - operationDialogType: OperationDialogType.temperature, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsCelsiusDegrees, - value: 0, - description: 'COOL TO', - ), - ], - ); - } - - SceneStaticFunction switchBasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: 'Smart AC Thermostat - Grey - Model A', - deviceIcon: Assets.assetsIconsAC, - icon: Assets.assetsAcPower, - operationName: 'Power', - code: 'switch', - functionValue: taskItem.functionValue, - operationDialogType: OperationDialogType.onOff, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcPower, - description: "ON", - value: true, - ), - SceneOperationalValue( - icon: Assets.assetsAcPowerOFF, - description: "OFF", - value: false, - ), - ], - ); - } - - SceneStaticFunction countdown3BasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: '3 Gang Button Switch L-L', - deviceIcon: Assets.assetsIcons3GangSwitch, - icon: Assets.assetsLightCountdown, - operationName: 'Light 3 CountDown', - code: 'countdown_3', - functionValue: taskItem.functionValue, - operationDialogType: OperationDialogType.countdown, - operationalValues: [ - SceneOperationalValue(icon: '', value: 0), - ], - ); - } - - SceneStaticFunction countdown2BasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: '3 Gang Button Switch L-L', - deviceIcon: Assets.assetsIcons3GangSwitch, - icon: Assets.assetsLightCountdown, - operationName: 'Light 2 CountDown', - code: 'countdown_2', - functionValue: taskItem.functionValue, - operationDialogType: OperationDialogType.countdown, - operationalValues: [ - SceneOperationalValue(icon: '', value: 0), - ], - ); - } - - SceneStaticFunction countdown1BasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: '3 Gang Button Switch L-L', - deviceIcon: Assets.assetsIcons3GangSwitch, - icon: Assets.assetsLightCountdown, - operationName: 'Light 1 CountDown', - code: 'countdown_1', - functionValue: taskItem.functionValue, - operationDialogType: OperationDialogType.countdown, - operationalValues: [ - SceneOperationalValue(icon: '', value: 0), - ], - ); - } - - SceneStaticFunction switch3BasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: '3 Gang Button Switch L-L', - deviceIcon: Assets.assetsIcons3GangSwitch, - icon: Assets.assetsAcPower, - operationName: 'Light 3 Switch', - code: 'switch_3', - functionValue: taskItem.functionValue, - operationDialogType: OperationDialogType.onOff, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcPower, description: "ON", value: true), - SceneOperationalValue( - icon: Assets.assetsAcPowerOFF, description: "OFF", value: false), - ], - ); - } - - SceneStaticFunction switch2BasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: '3 Gang Button Switch L-L', - deviceIcon: Assets.assetsIcons3GangSwitch, - icon: Assets.assetsAcPower, - operationName: 'Light 2 Switch', - code: 'switch_2', - functionValue: taskItem.functionValue, - operationDialogType: OperationDialogType.onOff, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcPower, description: "ON", value: true), - SceneOperationalValue( - icon: Assets.assetsAcPowerOFF, description: "OFF", value: false), - ], - ); - } - - SceneStaticFunction switch1BasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: '3 Gang Button Switch L-L', - deviceIcon: Assets.assetsIcons3GangSwitch, - icon: Assets.assetsAcPower, - operationName: 'Light 1 Switch', - code: 'switch_1', - functionValue: taskItem.functionValue, - operationDialogType: OperationDialogType.onOff, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcPower, - description: "ON", - value: true, - ), - SceneOperationalValue( - icon: Assets.assetsAcPowerOFF, description: "OFF", value: false), - ], - ); - } - - SceneStaticFunction factoryResetBasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: 'Multi-Mode Gateway Z-W-B', - deviceIcon: Assets.assetsIconsGateway, - icon: Assets.assetsFactoryReset, - operationName: 'Reset Factory', - functionValue: taskItem.functionValue, - code: 'factory_reset', - operationDialogType: OperationDialogType.onOff, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsSceneRefresh, description: "ON", value: true), - SceneOperationalValue( - icon: Assets.assetsResetOff, - description: "OFF", - value: false, - ), - ], - ); - } - - SceneStaticFunction masterStateBasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: 'Multi-Mode Gateway Z-W-B', - deviceIcon: Assets.assetsIconsGateway, - icon: Assets.assetsMasterState, - operationName: 'Master State', - functionValue: taskItem.functionValue, - code: 'master_state', - operationDialogType: OperationDialogType.listOfOptions, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcPower, - description: "Alarm", - value: 'alarm', - ), - SceneOperationalValue( - icon: Assets.assetsAcPowerOFF, - description: "Normal", - value: 'normal', - ), - ], - ); - } - - SceneStaticFunction switchAlarmSoundBasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: 'Multi-Mode Gateway Z-W-B', - deviceIcon: Assets.assetsIconsGateway, - icon: Assets.assetsSwitchAlarmSound, - operationName: 'Switch Alarm Sound', - functionValue: taskItem.functionValue, - code: 'switch_alarm_sound', - operationDialogType: OperationDialogType.onOff, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcPower, - description: "ON", - value: true, - ), - SceneOperationalValue( - icon: Assets.assetsAcPowerOFF, description: "OFF", value: false), - ], - ); - } - - SceneStaticFunction presenceTimeBasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: 'Human Presence Sensor', - deviceIcon: Assets.assetsIconsSensors, - icon: Assets.assetsNobodyTime, - operationName: 'Nobody Time', - functionValue: taskItem.functionValue, - code: 'presence_time', - operationDialogType: OperationDialogType.temperature, - operationalValues: [ - SceneOperationalValue(icon: '', value: 0), - ], - ); - } - - SceneStaticFunction indicatorBasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: 'Human Presence Sensor', - deviceIcon: Assets.assetsIconsSensors, - icon: Assets.assetsIndicator, - operationName: 'Indicator', - functionValue: taskItem.functionValue, - code: 'indicator', - operationDialogType: OperationDialogType.onOff, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcPower, description: "ON", value: true), - SceneOperationalValue( - icon: Assets.assetsAcPowerOFF, - description: "OFF", - value: false, - ), - ], - ); - } - - SceneStaticFunction motionlessSensitivityBasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: 'Human Presence Sensor', - deviceIcon: Assets.assetsIconsSensors, - icon: Assets.assetsMotionlessDetection, - operationName: 'Motionless Detection Sensitivity', - functionValue: taskItem.functionValue, - code: 'motion_sensitivity_value', - operationDialogType: OperationDialogType.listOfOptions, - operationalValues: [ - SceneOperationalValue( - iconValue: '1', - icon: Assets.assetsFarDetectionFunction, - value: 1, - description: '1', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 2, - description: '2', - iconValue: '2', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 3, - description: '3', - iconValue: '3', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 4, - description: '4', - iconValue: '4', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 5, - description: '5', - iconValue: '5', - ), - ], - ); - } - - SceneStaticFunction motionSensitivityValueBasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: 'Human Presence Sensor', - deviceIcon: Assets.assetsIconsSensors, - icon: Assets.assetsMotionDetection, - operationName: 'Motion Detection Sensitivity', - functionValue: taskItem.functionValue, - code: 'motion_sensitivity_value', - 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(), - ), - ], - ); - } - - SceneStaticFunction farDetectionBasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: 'Human Presence Sensor', - deviceIcon: Assets.assetsIconsSensors, - icon: Assets.assetsFarDetection, - operationName: 'Far Detection', - functionValue: taskItem.functionValue, - code: 'far_detection', - operationDialogType: OperationDialogType.listOfOptions, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 75, - description: '75cm', - iconValue: '75', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 150, - description: '150cm', - iconValue: '150', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 225, - description: '225cm', - iconValue: '225', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 300, - description: '300cm', - iconValue: '300', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 375, - description: '375cm', - iconValue: '375', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 450, - description: '450cm', - iconValue: '450', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 525, - description: '525cm', - iconValue: '525', - ), - SceneOperationalValue( - icon: Assets.assetsFarDetectionFunction, - value: 600, - description: '600cm', - iconValue: '600', - ), - ], - ); - } - - SceneStaticFunction normalOpenSwitchBasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: 'WIFI LOCK PRO', - deviceIcon: Assets.assetsIconsDoorLock, - icon: Assets.assetsIconsDoorLock, - operationName: 'Set Door lock Normal Open', - functionValue: taskItem.functionValue, - code: 'normal_open_switch', - operationDialogType: OperationDialogType.onOff, - operationalValues: [ - SceneOperationalValue( - icon: Assets.assetsAcPower, description: "ON", value: true), - SceneOperationalValue( - icon: Assets.assetsAcPowerOFF, - description: "OFF", - value: false, - ), - ], - ); - } - - SceneStaticFunction sensitivityFunctionsBasedOnCodeMatch( - String deviceId, SceneStaticFunction taskItem) { - return SceneStaticFunction( - deviceId: deviceId, - deviceName: 'Presence Sensor', - deviceIcon: Assets.assetsIconsSensors, - icon: Assets.assetsSensitivityFunction, - operationName: 'Sensitivity', - code: 'sensitivity', - functionValue: taskItem.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(), - ), - SceneOperationalValue( - icon: Assets.assetsSensitivityOperationIcon, - value: 10, - description: 10.toString(), - ), - ], - ); + return [ + _mapExecutorPropertyToSceneFunction( + Action( + entityId: deviceId, + executorProperty: ExecutorProperty( + functionCode: taskItem.code, + functionValue: taskItem.functionValue), + actionExecutor: ''), + false) + ]; } } diff --git a/lib/features/scene/model/create_scene_model.dart b/lib/features/scene/model/create_scene_model.dart index 53dc344..ca7919a 100644 --- a/lib/features/scene/model/create_scene_model.dart +++ b/lib/features/scene/model/create_scene_model.dart @@ -3,29 +3,11 @@ import 'dart:convert'; import 'package:flutter/foundation.dart'; class CreateSceneModel { - /* -{ - "unitUuid": "string", - "sceneName": "string", - "decisionExpr": "string", - "actions": [ - { - "entityId": "string", - "actionExecutor": "string", - "executorProperty": { - "functionCode": "string", - "functionValue": {}, - "delaySeconds": 0 - } - } - ] -} - */ - String unitUuid; String sceneName; String decisionExpr; List actions; + CreateSceneModel({ required this.unitUuid, required this.sceneName, @@ -100,6 +82,7 @@ class CreateSceneAction { String entityId; String actionExecutor; CreateSceneExecutorProperty executorProperty; + CreateSceneAction({ required this.entityId, required this.actionExecutor, @@ -122,7 +105,7 @@ class CreateSceneAction { return { 'entityId': entityId, 'actionExecutor': actionExecutor, - 'executorProperty': executorProperty.toMap(), + 'executorProperty': executorProperty.toMap(actionExecutor), }; } @@ -163,6 +146,7 @@ class CreateSceneExecutorProperty { String functionCode; dynamic functionValue; int delaySeconds; + CreateSceneExecutorProperty({ required this.functionCode, required this.functionValue, @@ -181,12 +165,14 @@ class CreateSceneExecutorProperty { ); } - Map toMap() { - return { - if (functionCode.isNotEmpty == true) 'functionCode': functionCode, - if (functionValue != '') 'functionValue': functionValue, - if (delaySeconds > 0) 'delaySeconds': delaySeconds, - }; + Map toMap(String actionExecutor) { + final map = {}; + if (functionCode.isNotEmpty) map['functionCode'] = functionCode; + if (functionValue != null) map['functionValue'] = functionValue; + if (actionExecutor == 'delay' && delaySeconds > 0) { + map['delaySeconds'] = delaySeconds; + } + return map; } factory CreateSceneExecutorProperty.fromMap(Map map) { @@ -197,7 +183,7 @@ class CreateSceneExecutorProperty { ); } - String toJson() => json.encode(toMap()); + String toJson(String actionExecutor) => json.encode(toMap(actionExecutor)); factory CreateSceneExecutorProperty.fromJson(String source) => CreateSceneExecutorProperty.fromMap(json.decode(source)); diff --git a/lib/features/scene/view/device_functions_view.dart b/lib/features/scene/view/device_functions_view.dart index 0990a32..e707889 100644 --- a/lib/features/scene/view/device_functions_view.dart +++ b/lib/features/scene/view/device_functions_view.dart @@ -188,6 +188,7 @@ class DeviceFunctionsView extends StatelessWidget alertBody: getTheCorrectDialogBody( function, functionValues, + isAutomation: false, ), title: function.operationName, onConfirm: () { @@ -237,6 +238,7 @@ class DeviceFunctionsView extends StatelessWidget alertBody: getTheCorrectDialogBody( function, automationFunctionValues, + isAutomation: true, ), title: function.operationName, onConfirm: () { diff --git a/lib/features/scene/widgets/alert_dialogs/alert_dialog_functions_body.dart b/lib/features/scene/widgets/alert_dialogs/alert_dialog_functions_body.dart index b93abcf..58ef349 100644 --- a/lib/features/scene/widgets/alert_dialogs/alert_dialog_functions_body.dart +++ b/lib/features/scene/widgets/alert_dialogs/alert_dialog_functions_body.dart @@ -11,10 +11,12 @@ class AlertDialogFunctionsOperationsBody extends StatefulWidget { super.key, this.functionValue, required this.taskItem, + required this.isAutomation, }); dynamic functionValue; final SceneStaticFunction taskItem; + final bool isAutomation; @override State createState() => @@ -26,25 +28,46 @@ class _AlertDialogFunctionsOperationsBodyState @override didChangeDependencies() { super.didChangeDependencies(); - - final tempTaskList = context.read().tempTasksList; + if (widget.isAutomation) { + final automationTempTasksList = + context.read().automationTempTasksList; - if (tempTaskList.isNotEmpty) { - for (var element in tempTaskList) { - if (element.code == widget.taskItem.code) { - groupValue = element.functionValue; - } else { - context - .read() - .add(RemoveFromSelectedValueById(code: widget.taskItem.code)); + if (automationTempTasksList.isNotEmpty) { + for (var element in automationTempTasksList) { + if (element.code == widget.taskItem.code) { + groupValue = element.functionValue; + } else { + context.read().add(RemoveFromSelectedValueById( + code: widget.taskItem.code, isAutomation: widget.isAutomation)); + } } } - } - if (widget.functionValue != null) { - setState(() { - groupValue = widget.functionValue; - }); + if (widget.functionValue != null) { + setState(() { + groupValue = widget.functionValue; + }); + } + } else { + final tempTaskList = context.read().tempTasksList; + + if (tempTaskList.isNotEmpty) { + for (var element in tempTaskList) { + if (element.code == widget.taskItem.code) { + groupValue = element.functionValue; + } else { + context + .read() + .add(RemoveFromSelectedValueById(code: widget.taskItem.code)); + } + } + } + + if (widget.functionValue != null) { + setState(() { + groupValue = widget.functionValue; + }); + } } } @@ -77,7 +100,9 @@ class _AlertDialogFunctionsOperationsBodyState groupValue = value; }); context.read().add(SelectedValueEvent( - value: value!, code: widget.taskItem.code)); + value: value!, + code: widget.taskItem.code, + isAutomation: widget.isAutomation)); }, ), onPressed: () { @@ -85,7 +110,9 @@ class _AlertDialogFunctionsOperationsBodyState groupValue = operation.value; }); context.read().add(SelectedValueEvent( - value: groupValue, code: widget.taskItem.code)); + value: groupValue, + code: widget.taskItem.code, + isAutomation: widget.isAutomation)); }, ); }, 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 ebfff07..c732142 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 @@ -11,10 +11,12 @@ class AlertDialogSliderSteps extends StatefulWidget { super.key, this.functionValue, required this.taskItem, + required this.isAutomation, }); final dynamic functionValue; final SceneStaticFunction taskItem; + final bool isAutomation; @override State createState() => _AlertDialogSliderStepsState(); @@ -27,24 +29,27 @@ class _AlertDialogSliderStepsState extends State { @override void didChangeDependencies() { super.didChangeDependencies(); - final tempTaskList = context.read().tempTasksList; - if (tempTaskList.isNotEmpty) { - for (var element in tempTaskList) { - if (element.code == widget.taskItem.code) { - groupValue = element.functionValue; - } else { - context - .read() - .add(RemoveFromSelectedValueById(code: widget.taskItem.code)); + + if (widget.isAutomation) { + final automationTempTaskList = + context.read().automationTempTasksList; + if (automationTempTaskList.isNotEmpty) { + for (var element in automationTempTaskList) { + if (element.code == widget.taskItem.code) { + groupValue = element.functionValue; + } else { + context.read().add(RemoveFromSelectedValueById( + code: widget.taskItem.code, isAutomation: widget.isAutomation)); + } } } - } - if (widget.functionValue != null) { - setState(() { - groupValue = widget.functionValue; - }); - } else { - groupValue = widget.taskItem.operationalValues[0].minValue; + if (widget.functionValue != null) { + setState(() { + groupValue = widget.functionValue; + }); + } else { + groupValue = widget.taskItem.operationalValues[0].minValue; + } } } @@ -154,8 +159,12 @@ class _AlertDialogSliderStepsState extends State { : null, onChanged: (value) { setState(() { - groupValue = value; + groupValue = value.round().toDouble(); }); + context.read().add(SelectedValueEvent( + value: groupValue, + code: widget.taskItem.code, + isAutomation: widget.isAutomation)); }, ), ), diff --git a/lib/features/scene/widgets/alert_dialogs/alert_dialog_temperature_body.dart b/lib/features/scene/widgets/alert_dialogs/alert_dialog_temperature_body.dart index fb662ad..783d8c1 100644 --- a/lib/features/scene/widgets/alert_dialogs/alert_dialog_temperature_body.dart +++ b/lib/features/scene/widgets/alert_dialogs/alert_dialog_temperature_body.dart @@ -14,14 +14,10 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; class AlertDialogTemperatureBody extends StatefulWidget { AlertDialogTemperatureBody({ super.key, - //required this.index, - // required this.functions, this.functionValue, required this.taskItem, }); - //final List functions; - // final int index; final SceneStaticFunction taskItem; dynamic functionValue; @@ -32,14 +28,16 @@ class AlertDialogTemperatureBody extends StatefulWidget { class _AlertDialogTemperatureBodyState extends State { + int temperature = 24; + @override - didChangeDependencies() { + void didChangeDependencies() { super.didChangeDependencies(); final tempTaskList = context.read().tempTasksList; for (var element in tempTaskList) { if (element.code == widget.taskItem.code) { - temperature = element.functionValue; + temperature = _normalizeTemperature(element.functionValue); } else { context .read() @@ -48,12 +46,18 @@ class _AlertDialogTemperatureBodyState } if (widget.functionValue != null) { setState(() { - temperature = widget.functionValue; + temperature = _normalizeTemperature(widget.functionValue); }); } } - int temperature = 24; + int _normalizeTemperature(dynamic value) { + if (value is int && value >= 100) { + return value ~/ 10; + } + return value as int? ?? 24; + } + @override Widget build(BuildContext context) { return ListTile( @@ -98,8 +102,7 @@ class _AlertDialogTemperatureBodyState ], ), subtitle: BodyLarge( - text: widget.taskItem.operationalValues[0].description - .toString(), + text: widget.taskItem.operationalValues[0].description.toString(), textAlign: TextAlign.center, ), trailing: IconButton( @@ -110,8 +113,7 @@ class _AlertDialogTemperatureBodyState } }); context.read().add(SelectedValueEvent( - value: temperature * 10, - code: widget.taskItem.code)); + value: temperature * 10, code: widget.taskItem.code)); }, icon: const Icon( Icons.add, diff --git a/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart b/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart index 85612f6..61510a5 100644 --- a/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart +++ b/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart @@ -34,7 +34,7 @@ class ThenAddedTasksContainer extends StatelessWidget Widget build(BuildContext context) { final createSceneBloc = context.read(); String operationValue = ''; - if (taskItem.code.contains('countdown') || + if ((taskItem.code.contains('countdown') && isAutomation != true) || taskItem.deviceId.contains('delay')) { final functionValue = taskItem.functionValue ?? taskItem.operationalValues.first.value; @@ -64,7 +64,8 @@ class ThenAddedTasksContainer extends StatelessWidget /// show alert dialog based on type context.customAlertDialog( - alertBody: getTheCorrectDialogBody(functionOperation.first, null), + alertBody: getTheCorrectDialogBody(functionOperation.first, null, + isAutomation: isAutomation ?? false), title: functionOperation.first.operationName, onConfirm: () { final savedCode = functionOperation.first.deviceId.contains('delay') diff --git a/lib/services/api/api_links_endpoints.dart b/lib/services/api/api_links_endpoints.dart index 457f96b..f252a09 100644 --- a/lib/services/api/api_links_endpoints.dart +++ b/lib/services/api/api_links_endpoints.dart @@ -2,8 +2,8 @@ import 'package:flutter/foundation.dart'; abstract class ApiEndpoints { static const String baseUrl = kReleaseMode - ? 'https://syncrow-staging.azurewebsites.net/api' - : 'https://syncrow-dev.azurewebsites.net/api'; + ? 'https://syncrow-staging.azurewebsites.net' + : 'https://syncrow-dev.azurewebsites.net'; // static const String baseUrl = 'http://100.107.182.63:4001'; //Localhost ////////////////////////////////////// Authentication /////////////////////////////// diff --git a/lib/services/api/scene_api.dart b/lib/services/api/scene_api.dart index d28c03d..4d377f1 100644 --- a/lib/services/api/scene_api.dart +++ b/lib/services/api/scene_api.dart @@ -12,7 +12,7 @@ class SceneApi { try { final response = await _httpService.post( path: ApiEndpoints.createScene, - body: createSceneModel.toJson(), + body: createSceneModel.toMap(), showServerMessage: false, expectedResponseModel: (json) { return json;