From bf315da8dfe1d5bdafa51d4dedb0317fead750f6 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Sun, 27 Aug 2017 21:06:11 +0200 Subject: [PATCH] Xiaomi gateway: Device support for the Aqara Water Leak Sensor (sensor_wleak.aq1) (#9172) * Device support for the Aqara Water Leak Sensor (sensor_wleak.aq1) added. * Required version of PyXiaomiGateway changed. --- .../components/binary_sensor/xiaomi.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/homeassistant/components/binary_sensor/xiaomi.py b/homeassistant/components/binary_sensor/xiaomi.py index fafdc098c5d..c5f0a7b3dce 100644 --- a/homeassistant/components/binary_sensor/xiaomi.py +++ b/homeassistant/components/binary_sensor/xiaomi.py @@ -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': @@ -214,6 +216,35 @@ class XiaomiDoorSensor(XiaomiBinarySensor): 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."""