Skip to content
Merged
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
31 changes: 31 additions & 0 deletions homeassistant/components/binary_sensor/xiaomi.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
devices.append(XiaomiDoorSensor(device, gateway))
elif model == 'sensor_magnet.aq2':
devices.append(XiaomiDoorSensor(device, gateway))
elif model == 'sensor_wleak.aq1':
devices.append(XiaomiWaterLeakSensor(device, gateway))
elif model == 'smoke':
devices.append(XiaomiSmokeSensor(device, gateway))
elif model == 'natgas':
Expand Down Expand Up @@ -214,6 +216,35 @@ def parse_data(self, data):
return False


class XiaomiWaterLeakSensor(XiaomiBinarySensor):
"""Representation of a XiaomiWaterLeakSensor."""

def __init__(self, device, xiaomi_hub):
"""Initialize the XiaomiWaterLeakSensor."""
XiaomiBinarySensor.__init__(self, device, 'Water Leak Sensor',
xiaomi_hub, 'status', 'moisture')

def parse_data(self, data):
"""Parse data sent by gateway."""
self._should_poll = False

value = data.get(self._data_key)
if value is None:
return False

if value == 'leak':
self._should_poll = True
if self._state:
return False
self._state = True
return True
elif value == 'no_leak':
if self._state:
self._state = False
return True
return False


class XiaomiSmokeSensor(XiaomiBinarySensor):
"""Representation of a XiaomiSmokeSensor."""

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/xiaomi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


REQUIREMENTS = ['https://github.com/Danielhiversen/PyXiaomiGateway/archive/'
'0.3.zip#PyXiaomiGateway==0.3.0']
'0.3.1.zip#PyXiaomiGateway==0.3.1']

ATTR_GW_MAC = 'gw_mac'
ATTR_RINGTONE_ID = 'ringtone_id'
Expand Down