Compare commits

...

3 Commits

Author SHA1 Message Date
ohyeah521
6ecffbb47a
Merge 64d9d54170 into f2200ba003 2025-08-29 18:15:57 +08:00
Li Shuzhen
f2200ba003
fix: contact-state value format (#1387)
Some checks failed
Tests / check-rule-format (push) Has been cancelled
Validate / validate-hassfest (push) Has been cancelled
Validate / validate-hacs (push) Has been cancelled
Validate / validate-lint (push) Has been cancelled
Validate / validate-setup (push) Has been cancelled
2025-08-29 17:36:25 +08:00
Li Shuzhen
073cdf2dcb
fix: integer value step (#1388) 2025-08-29 17:35:46 +08:00
2 changed files with 7 additions and 4 deletions

View File

@ -70,8 +70,8 @@ async def async_setup_entry(
for miot_device in device_list:
if miot_device.miot_client.display_binary_bool:
for prop in miot_device.prop_list.get('binary_sensor', []):
new_entities.append(BinarySensor(
miot_device=miot_device, spec=prop))
new_entities.append(
BinarySensor(miot_device=miot_device, spec=prop))
if new_entities:
async_add_entities(new_entities)
@ -90,7 +90,7 @@ class BinarySensor(MIoTPropertyEntity, BinarySensorEntity):
def is_on(self) -> bool:
"""On/Off state. True if the binary sensor is on, False otherwise."""
if self.spec.name == 'contact-state':
return self._value is False
return bool(self._value) is False
elif self.spec.name == 'occupancy-status':
return bool(self._value)
return self._value is True

View File

@ -601,7 +601,10 @@ class MIoTSpecProperty(_MIoTSpecBase):
if value is None:
return None
if self.format_ == int:
return int(round(value))
if self.value_range is None:
return int(round(value))
return int(
round(value / self.value_range.step) * self.value_range.step)
if self.format_ == float:
return round(value, self.precision)
if self.format_ == bool: