From 9cc2c52d441ba2751fc784c29b4ea941f5f345af Mon Sep 17 00:00:00 2001 From: Yi Zhai Date: Thu, 19 Dec 2024 16:59:39 +0800 Subject: [PATCH] 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 @@ 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