Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use binary sensor class for door and windows sensor and water leak sensor #236

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions custom_components/xiaomi_home/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions custom_components/xiaomi_home/miot/specs/specv2entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -336,6 +337,10 @@
'format': {'int', 'float'},
'access': {'read'}
},
'binary_sensor': {
'format': {'bool'},
'access': {'read'}
},
'switch': {
'format': {'bool'},
'access': {'read', 'write'}
Expand Down Expand Up @@ -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'
}
Expand Down
Loading