From 162f943924f89c564dc4e0ebb477e6a7a9b00225 Mon Sep 17 00:00:00 2001 From: Yi Zhai Date: Thu, 19 Dec 2024 16:55:28 +0800 Subject: [PATCH 1/3] 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 --- custom_components/xiaomi_home/miot/specs/specv2entity.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/custom_components/xiaomi_home/miot/specs/specv2entity.py b/custom_components/xiaomi_home/miot/specs/specv2entity.py index 4a57867..30528f8 100644 --- a/custom_components/xiaomi_home/miot/specs/specv2entity.py +++ b/custom_components/xiaomi_home/miot/specs/specv2entity.py @@ -47,6 +47,7 @@ """ 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 @@ -391,6 +392,14 @@ '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' } From 9cc2c52d441ba2751fc784c29b4ea941f5f345af Mon Sep 17 00:00:00 2001 From: Yi Zhai Date: Thu, 19 Dec 2024 16:59:39 +0800 Subject: [PATCH 2/3] 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. --- custom_components/xiaomi_home/binary_sensor.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/custom_components/xiaomi_home/binary_sensor.py b/custom_components/xiaomi_home/binary_sensor.py index 9ec6e83..fd31dda 100644 --- a/custom_components/xiaomi_home/binary_sensor.py +++ b/custom_components/xiaomi_home/binary_sensor.py @@ -88,4 +88,7 @@ def __init__(self, miot_device: MIoTDevice, spec: MIoTSpecProperty) -> None: @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 From 3546517093735d92ccadba911d486439e8248d6a Mon Sep 17 00:00:00 2001 From: Yi Zhai Date: Thu, 19 Dec 2024 17:18:55 +0800 Subject: [PATCH 3/3] 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`. --- custom_components/xiaomi_home/miot/specs/specv2entity.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/custom_components/xiaomi_home/miot/specs/specv2entity.py b/custom_components/xiaomi_home/miot/specs/specv2entity.py index 30528f8..911c2aa 100644 --- a/custom_components/xiaomi_home/miot/specs/specv2entity.py +++ b/custom_components/xiaomi_home/miot/specs/specv2entity.py @@ -337,6 +337,10 @@ 'format': {'int', 'float'}, 'access': {'read'} }, + 'binary_sensor': { + 'format': {'bool'}, + 'access': {'read'} + }, 'switch': { 'format': {'bool'}, 'access': {'read', 'write'}