mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
Refactor ceiling sensor functions and update slider helper mappings for improved value handling
This commit is contained in:
@ -11,6 +11,7 @@ import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ceiling_senso
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ceiling_sensor/cps_dialog_slider_selector.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ceiling_sensor/cps_dialog_value_selector.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ceiling_sensor/cps_functions_list.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ceiling_sensor/cps_slider_helpers.dart';
|
||||
|
||||
class CeilingSensorDialog extends StatefulWidget {
|
||||
const CeilingSensorDialog({
|
||||
@ -76,7 +77,8 @@ class _CeilingSensorDialogState extends State<CeilingSensorDialog> {
|
||||
? () {
|
||||
context.read<RoutineBloc>().add(
|
||||
AddFunctionToRoutine(
|
||||
state.addedFunctions,
|
||||
_updateValuesForAddedFunctions(
|
||||
state.addedFunctions),
|
||||
'${widget.uniqueCustomId}',
|
||||
),
|
||||
);
|
||||
@ -150,15 +152,58 @@ class _CeilingSensorDialogState extends State<CeilingSensorDialog> {
|
||||
],
|
||||
);
|
||||
}
|
||||
List<DeviceFunctionData> updateValuesForAddedFunctions(List<DeviceFunctionData> addedFunctions) {
|
||||
|
||||
List<DeviceFunctionData> _updateValuesForAddedFunctions(
|
||||
List<DeviceFunctionData> addedFunctions,
|
||||
) {
|
||||
const mappableSteppedFunctions = <String>{
|
||||
'static_max_dis',
|
||||
'presence_reference',
|
||||
'moving_reference',
|
||||
'perceptual_boundary',
|
||||
'moving_boundary',
|
||||
'moving_rigger_time',
|
||||
'moving_static_time',
|
||||
'none_body_time',
|
||||
'moving_max_dis',
|
||||
};
|
||||
return addedFunctions.map((function) {
|
||||
if (function.functionCode == 'sensitivity') {
|
||||
return function.copyWith(
|
||||
if (mappableSteppedFunctions.contains(function.functionCode)) {
|
||||
final mappedValue = mapSteppedValue(
|
||||
value: function.value,
|
||||
inputStep: CpsSliderHelpers.dividendOfRange(function.functionCode),
|
||||
inputRange: CpsSliderHelpers.sliderRange(function.functionCode),
|
||||
outputRange: CpsSliderHelpers.mappedRange(function.functionCode),
|
||||
);
|
||||
return DeviceFunctionData(
|
||||
value: mappedValue,
|
||||
entityId: function.entityId,
|
||||
functionCode: function.functionCode,
|
||||
operationName: function.operationName,
|
||||
condition: function.condition,
|
||||
actionExecutor: function.actionExecutor,
|
||||
valueDescription: function.valueDescription,
|
||||
);
|
||||
}
|
||||
return function;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
int mapSteppedValue({
|
||||
required (double min, double max) inputRange,
|
||||
required double inputStep,
|
||||
required (double min, double max, double dividend) outputRange,
|
||||
required double value,
|
||||
}) {
|
||||
final (inputMin, inputMax) = inputRange;
|
||||
final (outputMin, outputMax, outputStep) = outputRange;
|
||||
|
||||
final clampedValue = value.clamp(inputMin, inputMax);
|
||||
|
||||
final stepsFromMin = ((clampedValue - inputMin) / inputStep).round();
|
||||
|
||||
final mappedValue = outputMin + (stepsFromMin * outputStep);
|
||||
|
||||
return mappedValue.clamp(outputMin, outputMax).round();
|
||||
}
|
||||
}
|
||||
|
@ -66,22 +66,4 @@ class CpsDialogSliderSelector extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
double reverseMappedValue(double value) {
|
||||
final (inputMin, inputMax) =
|
||||
CpsSliderHelpers.sliderRange(selectedFunctionData.functionCode);
|
||||
final (outputMin, outputMax, outputStep) = CpsSliderHelpers.mappedRange(
|
||||
selectedFunctionData.functionCode,
|
||||
);
|
||||
|
||||
final clampedValue = value.clamp(outputMin, outputMax);
|
||||
|
||||
final stepsFromMin = ((clampedValue - outputMin) / outputStep).round();
|
||||
|
||||
final mappedValue = inputMin +
|
||||
(stepsFromMin *
|
||||
CpsSliderHelpers.dividendOfRange(selectedFunctionData.functionCode));
|
||||
|
||||
return mappedValue.clamp(inputMin, inputMax);
|
||||
}
|
||||
}
|
||||
|
@ -4,13 +4,14 @@ abstract final class CpsSliderHelpers {
|
||||
final defaultDivdidend = dividendOfRange(functionCode);
|
||||
return switch (functionCode) {
|
||||
'static_max_dis' => (0, 500, 50),
|
||||
'presence_reference' => (0, 255, 50),
|
||||
'presence_reference' => (0, 255, 5),
|
||||
'moving_reference' => (0, 255, 5),
|
||||
'perceptual_boundary' => (0, 500, 50),
|
||||
'moving_boundary' => (0, 500, 50),
|
||||
'moving_rigger_time' => (0, 2000, 100),
|
||||
'moving_static_time' => (0, 6000, 100),
|
||||
'none_body_time' => (0, 300000, 500),
|
||||
'moving_static_time' => (0, 60000, 1000),
|
||||
'none_body_time' => (0, 300000, 5000),
|
||||
'moving_max_dis' => (0, 500, 50),
|
||||
_ => (defaultMin, defaultMax, defaultDivdidend),
|
||||
};
|
||||
}
|
||||
@ -83,4 +84,7 @@ abstract final class CpsSliderHelpers {
|
||||
_ => '${parsedValue?.toStringAsFixed(0) ?? 0}',
|
||||
};
|
||||
}
|
||||
// TODO: Sports Para causes 400 in IF and THEN / sports_para
|
||||
// TODO: Detection range causes 400 in IF / moving_range
|
||||
// TODO: Distance of moving objects causes 400 in IF / presence_range
|
||||
}
|
||||
|
Reference in New Issue
Block a user