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 diff --git a/custom_components/xiaomi_home/miot/specs/specv2entity.py b/custom_components/xiaomi_home/miot/specs/specv2entity.py index 4a57867..911c2aa 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 @@ -336,6 +337,10 @@ 'format': {'int', 'float'}, 'access': {'read'} }, + 'binary_sensor': { + 'format': {'bool'}, + 'access': {'read'} + }, 'switch': { 'format': {'bool'}, 'access': {'read', 'write'} @@ -391,6 +396,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' }