Skip to content

Commit

Permalink
🔢 improve for number sensor (#1968)
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Nov 21, 2024
1 parent ca2f330 commit f0a0b9f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions custom_components/xiaomi_miot/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,17 @@ def device_class(self):

@property
def native_value(self):
if not self._prop_state:
prop = self._prop_state
if not prop:
return None
key = f'{self._prop_state.full_name}_desc'
key = f'{prop.full_name}_desc'
if key in self._state_attrs:
return f'{self._state_attrs[key]}'.lower()
return self._prop_state.from_dict(self._state_attrs)
val = prop.from_dict(self._state_attrs)
if prop.value_range:
if not prop.range_min() <= val <= prop.range_max():
val = None
return val

def before_select_modes(self, prop, option, **kwargs):
if prop := self._miot_service.get_property('on'):
Expand Down Expand Up @@ -506,11 +511,15 @@ def update(self, data=None):

@property
def native_value(self):
prop = self._miot_property
if not self._attr_native_unit_of_measurement:
key = f'{self._miot_property.full_name}_desc'
key = f'{prop.full_name}_desc'
if key in self._state_attrs:
return f'{self._state_attrs[key]}'.lower()
val = self._miot_property.from_dict(self._state_attrs)
val = prop.from_dict(self._state_attrs)
if prop.value_range:
if not prop.range_min() <= val <= prop.range_max():
val = None
if val is not None:
svd = self.custom_config_number('value_ratio') or 0
if svd:
Expand Down

0 comments on commit f0a0b9f

Please sign in to comment.