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 5ac0c32..4182ed2 100644 --- a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart +++ b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart @@ -191,19 +191,28 @@ class CreateSceneBloc extends Bloc FutureOr _selectedValue( SelectedValueEvent event, Emitter emit) { - emit(CreateSceneLoading()); if (event.isAutomation == true) { automationSelectedValues[event.code] = event.value; automationComparatorValues[event.code] = event.comparator ?? '=='; - emit(SelectedTaskValueState(value: event.value)); - emit(AddSceneTask( - tasksList: tasksList, automationTasksList: automationTasksList)); + + // Update the comparator value for the specific task in automationTasksList + for (int i = 0; i < automationTasksList.length; i++) { + if (automationTasksList[i].code == event.code) { + automationTasksList[i] = automationTasksList[i].copyWith( + comparator: event.comparator ?? '==', + functionValue: event.value, + ); + break; + } + } } else { selectedValues[event.code] = event.value; - emit(SelectedTaskValueState(value: event.value)); - emit(AddSceneTask( - tasksList: tasksList, automationTasksList: automationTasksList)); } + emit(SelectedTaskValueState(value: event.value)); + emit(AddSceneTask( + tasksList: List.from(tasksList), + automationTasksList: List.from(automationTasksList), + )); } FutureOr _removeTaskById( diff --git a/lib/features/scene/helper/scene_logic_helper.dart b/lib/features/scene/helper/scene_logic_helper.dart index 005162d..f77da60 100644 --- a/lib/features/scene/helper/scene_logic_helper.dart +++ b/lib/features/scene/helper/scene_logic_helper.dart @@ -68,6 +68,17 @@ mixin SceneLogicHelper { actions.length, (index) { final task = actions[index]; + if (task.deviceId == 'delay') { + return CreateSceneAction( + entityId: actions[index].deviceId, + actionExecutor: 'delay', + executorProperty: CreateSceneExecutorProperty( + functionCode: '', + functionValue: '', + delaySeconds: task.functionValue, + ), + ); + } return CreateSceneAction( entityId: task.deviceId, actionExecutor: 'device_issue', 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 66e4647..2563b28 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 @@ -29,41 +29,51 @@ class _AlertDialogSliderStepsState extends State { @override void didChangeDependencies() { super.didChangeDependencies(); + final createSceneBloc = context.read(); if (widget.isAutomation) { - final automationTempTaskList = - context.read().automationTempTasksList; + final automationTempTaskList = createSceneBloc.automationTempTasksList; final automationComparatorValues = - context.read().automationComparatorValues; + createSceneBloc.automationComparatorValues; - if (automationTempTaskList.isNotEmpty) { - for (var element in automationTempTaskList) { - if (element.code == widget.taskItem.code) { - groupValue = element.functionValue; - selectedToggleIndex = - _comparatorToIndex(automationComparatorValues[element.code]); - } + for (var element in automationTempTaskList) { + if (element.code == widget.taskItem.code) { + groupValue = element.functionValue; + selectedToggleIndex = + _comparatorToIndex(automationComparatorValues[element.code]); } } - if (widget.functionValue != null) { - groupValue = widget.functionValue; - } else { - groupValue = widget.taskItem.operationalValues[0].minValue; - } - if (widget.taskItem.comparator != null) { - selectedToggleIndex = _comparatorToIndex(widget.taskItem.comparator); - } - setState(() {}); } + + if (widget.functionValue != null) { + groupValue = _normalizeValue(widget.functionValue); + } else { + groupValue = + _normalizeValue(widget.taskItem.operationalValues[0].minValue); + } + + if (widget.taskItem.comparator != null) { + selectedToggleIndex = _comparatorToIndex(widget.taskItem.comparator); + } + + setState(() {}); + } + + double _normalizeValue(dynamic value) { + if (widget.taskItem.code == "temp_set" || + widget.taskItem.code == "temp_current") { + return (value as double) / 10; + } + return value.toDouble(); } int _comparatorToIndex(String? comparator) { switch (comparator) { - case "<=": + case "<": return 0; case "==": return 1; - case ">=": + case ">": return 2; default: return 1; @@ -73,11 +83,11 @@ class _AlertDialogSliderStepsState extends State { String _indexToComparator(int index) { switch (index) { case 0: - return "<="; + return "<"; case 1: return "=="; case 2: - return ">="; + return ">"; default: return "=="; } @@ -98,10 +108,14 @@ class _AlertDialogSliderStepsState extends State { setState(() { selectedToggleIndex = index; }); - context.read().add(SelectedValueEvent( - code: widget.taskItem.code, - isAutomation: widget.isAutomation, - comparator: _indexToComparator(selectedToggleIndex))); + context.read().add( + SelectedValueEvent( + value: _deNormalizeValue(groupValue), + code: widget.taskItem.code, + isAutomation: widget.isAutomation, + comparator: _indexToComparator(selectedToggleIndex), + ), + ); }, borderRadius: BorderRadius.circular(30), selectedColor: Colors.white, @@ -181,8 +195,8 @@ class _AlertDialogSliderStepsState extends State { padding: const EdgeInsets.symmetric(horizontal: 8), child: Slider( value: groupValue ?? 0, - min: operation.minValue?.toDouble() ?? 0, - max: operation.maxValue?.toDouble() ?? 0, + min: operation.minValue ?? 0, + max: operation.maxValue ?? 0, inactiveColor: ColorsManager.primaryColorWithOpacity .withOpacity(0.2), divisions: operation.stepValue != null @@ -193,10 +207,10 @@ class _AlertDialogSliderStepsState extends State { : null, onChanged: (value) { setState(() { - groupValue = value.round().toDouble(); + groupValue = value; }); context.read().add(SelectedValueEvent( - value: groupValue, + value: _deNormalizeValue(groupValue), code: widget.taskItem.code, isAutomation: widget.isAutomation, comparator: @@ -213,4 +227,12 @@ class _AlertDialogSliderStepsState extends State { ], ); } + + double _deNormalizeValue(double? value) { + if (widget.taskItem.code == "temp_set" || + widget.taskItem.code == "temp_current") { + return (value ?? 0) * 10; + } + return value ?? 0; + } }