Compare commits

...

4 Commits

Author SHA1 Message Date
Yi Zhai
5a6678f4b1
Merge 3546517093 into c1867e2baf 2024-12-22 16:41:06 +08:00
Yi Zhai
3546517093
fix: Update specv2entity.py for missing "binary_sensor"
fix: Update specv2entity.py for missing "binary_sensor"

fix typo which forgets to  adding "binary_sensor" entity in `SPEC_PROP_TRANS_MAP`.
2024-12-19 17:18:55 +08:00
Yi Zhai
9cc2c52d44
fix: revert value of door and windows sensor with binary sensor class
fix: revert value of door and windows sensor with binary sensor class

Binary sensor class in Home Assistant uses true to indicate open, which is opposite of Xiaomi Home.
This commit reverts the value of  door and windows sensor to make them the same.
2024-12-19 16:59:39 +08:00
Yi Zhai
162f943924
fix: use binary sensor class for door and windows sensor and water leak sensor
fix: use Binary sensor class for door&windows and water leak sensor

The original version uses a sensor class for various sensors, such as door and windows sensors, water leak sensors, occupancy sensors, motion sensors, etc., which prevents the HomeKit Bridge from generating corresponding entities.
This fix is to use binary sensor class for door andwindows sensor and water leak sensor.

Correspoding issue: https://github.com/XiaoMi/ha_xiaomi_home/issues/206
2024-12-19 16:55:28 +08:00
2 changed files with 16 additions and 0 deletions

View File

@ -88,4 +88,7 @@ class BinarySensor(MIoTPropertyEntity, BinarySensorEntity):
@property
def is_on(self) -> bool:
"""On/Off state. True if the binary sensor is on, False otherwise."""
"""If it is a door and windows sensor, revert the value."""
if self._attr_device_class == 'door':
return not (self._value is True)
return self._value is True

View File

@ -47,6 +47,7 @@ Conversion rules of MIoT-Spec-V2 instance to Home Assistant entity.
"""
from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.components.event import EventDeviceClass
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
# pylint: disable=pointless-string-statement
"""SPEC_DEVICE_TRANS_MAP
@ -336,6 +337,10 @@ SPEC_PROP_TRANS_MAP: dict[str, dict | str] = {
'format': {'int', 'float'},
'access': {'read'}
},
'binary_sensor': {
'format': {'bool'},
'access': {'read'}
},
'switch': {
'format': {'bool'},
'access': {'read', 'write'}
@ -391,6 +396,14 @@ SPEC_PROP_TRANS_MAP: dict[str, dict | str] = {
'device_class': SensorDeviceClass.DURATION,
'entity': 'sensor'
},
'submersion-state': {
'device_class': BinarySensorDeviceClass.MOISTURE,
'entity': 'binary_sensor'
},
'contact-state': {
'device_class': BinarySensorDeviceClass.DOOR,
'entity': 'binary_sensor'
},
'has-someone-duration': 'no-one-determine-time',
'no-one-duration': 'no-one-determine-time'
}