From d0e1a35d87218d8fb6abf4f227498cad0dd77aa8 Mon Sep 17 00:00:00 2001 From: danieldotnl Date: Fri, 5 Apr 2024 14:38:04 +0000 Subject: [PATCH] Fix unknown error when update sensor config --- custom_components/measureit/config_flow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/measureit/config_flow.py b/custom_components/measureit/config_flow.py index 6738d8a..100552b 100644 --- a/custom_components/measureit/config_flow.py +++ b/custom_components/measureit/config_flow.py @@ -236,8 +236,8 @@ async def validate_sensor_edit( # Standard behavior is to merge the result with the options. # In this case, we want to add a sub-item so we update the options directly. idx: int = handler.flow_state["_idx"] - if handler.options[SENSOR_DOMAIN][idx][CONF_UNIT_OF_MEASUREMENT] != user_input.get(CONF_UNIT_OF_MEASUREMENT): - if handler.options[SENSOR_DOMAIN][idx][CONF_DEVICE_CLASS] and user_input.get(CONF_DEVICE_CLASS) is not None: + if handler.options[SENSOR_DOMAIN][idx].get(CONF_UNIT_OF_MEASUREMENT) != user_input.get(CONF_UNIT_OF_MEASUREMENT): + if handler.options[SENSOR_DOMAIN][idx].get(CONF_DEVICE_CLASS) and user_input.get(CONF_DEVICE_CLASS) is not None: raise SchemaFlowError("uom_with_device_class_update") handler.options[SENSOR_DOMAIN][idx].update(user_input) for key in DATA_SCHEMA_EDIT_SENSOR.schema: