Skip to content

Commit

Permalink
🔢 improve for number sensor (#1980)
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Dec 3, 2024
1 parent 7faaa0e commit 8f5c81c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions custom_components/xiaomi_miot/core/miot_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_miot/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8f5c81c

Please sign in to comment.