mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-23 11:57:54 +00:00
fixed automation bugs
This commit is contained in:
@@ -191,19 +191,28 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
|
||||
FutureOr<void> _selectedValue(
|
||||
SelectedValueEvent event, Emitter<CreateSceneState> 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<void> _removeTaskById(
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -29,41 +29,51 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final createSceneBloc = context.read<CreateSceneBloc>();
|
||||
|
||||
if (widget.isAutomation) {
|
||||
final automationTempTaskList =
|
||||
context.read<CreateSceneBloc>().automationTempTasksList;
|
||||
final automationTempTaskList = createSceneBloc.automationTempTasksList;
|
||||
final automationComparatorValues =
|
||||
context.read<CreateSceneBloc>().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<AlertDialogSliderSteps> {
|
||||
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<AlertDialogSliderSteps> {
|
||||
setState(() {
|
||||
selectedToggleIndex = index;
|
||||
});
|
||||
context.read<CreateSceneBloc>().add(SelectedValueEvent(
|
||||
code: widget.taskItem.code,
|
||||
isAutomation: widget.isAutomation,
|
||||
comparator: _indexToComparator(selectedToggleIndex)));
|
||||
context.read<CreateSceneBloc>().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<AlertDialogSliderSteps> {
|
||||
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<AlertDialogSliderSteps> {
|
||||
: null,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
groupValue = value.round().toDouble();
|
||||
groupValue = value;
|
||||
});
|
||||
context.read<CreateSceneBloc>().add(SelectedValueEvent(
|
||||
value: groupValue,
|
||||
value: _deNormalizeValue(groupValue),
|
||||
code: widget.taskItem.code,
|
||||
isAutomation: widget.isAutomation,
|
||||
comparator:
|
||||
@@ -213,4 +227,12 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
double _deNormalizeValue(double? value) {
|
||||
if (widget.taskItem.code == "temp_set" ||
|
||||
widget.taskItem.code == "temp_current") {
|
||||
return (value ?? 0) * 10;
|
||||
}
|
||||
return value ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user