diff --git a/custom_components/xiaomi_miot/core/miot_spec.py b/custom_components/xiaomi_miot/core/miot_spec.py index 422b53e65..b9e146710 100644 --- a/custom_components/xiaomi_miot/core/miot_spec.py +++ b/custom_components/xiaomi_miot/core/miot_spec.py @@ -862,6 +862,10 @@ def range_valid(self, val): return True if val == None: return False + try: + val = float(val) + except (TypeError, ValueError): + return False return range_min <= val <= range_max @property diff --git a/custom_components/xiaomi_miot/sensor.py b/custom_components/xiaomi_miot/sensor.py index f3c2b5998..e2d45adb8 100644 --- a/custom_components/xiaomi_miot/sensor.py +++ b/custom_components/xiaomi_miot/sensor.py @@ -134,7 +134,7 @@ def set_state(self, data: dict): value = data.get(self.attr) prop = self._miot_property if prop and prop.value_range: - if not prop.range_min() <= value <= prop.range_max(): + if not prop.range_valid(value): value = None if value is not None: try: