From 17ef258425aed6baa51795b62953ea4784fec5b6 Mon Sep 17 00:00:00 2001 From: ileler Date: Fri, 30 Mar 2018 15:02:24 +0800 Subject: [PATCH 1/9] support new device model;support new LAN protocol 2.0 --- .../components/binary_sensor/xiaomi_aqara.py | 18 +++++++++--------- homeassistant/components/light/xiaomi_aqara.py | 2 +- .../components/sensor/xiaomi_aqara.py | 4 ++-- .../components/switch/xiaomi_aqara.py | 4 ++-- homeassistant/components/xiaomi_aqara.py | 1 + 5 files changed, 15 insertions(+), 14 deletions(-) mode change 100644 => 100755 homeassistant/components/binary_sensor/xiaomi_aqara.py mode change 100644 => 100755 homeassistant/components/light/xiaomi_aqara.py mode change 100644 => 100755 homeassistant/components/sensor/xiaomi_aqara.py mode change 100644 => 100755 homeassistant/components/switch/xiaomi_aqara.py mode change 100644 => 100755 homeassistant/components/xiaomi_aqara.py diff --git a/homeassistant/components/binary_sensor/xiaomi_aqara.py b/homeassistant/components/binary_sensor/xiaomi_aqara.py old mode 100644 new mode 100755 index 2ed0de66b186b..f53d460d9b8f9 --- a/homeassistant/components/binary_sensor/xiaomi_aqara.py +++ b/homeassistant/components/binary_sensor/xiaomi_aqara.py @@ -25,30 +25,30 @@ def setup_platform(hass, config, add_devices, discovery_info=None): for (_, gateway) in hass.data[PY_XIAOMI_GATEWAY].gateways.items(): for device in gateway.devices['binary_sensor']: model = device['model'] - if model in ['motion', 'sensor_motion.aq2']: + if model in ['motion', 'sensor_motion', 'sensor_motion.aq2']: devices.append(XiaomiMotionSensor(device, hass, gateway)) - elif model in ['magnet', 'sensor_magnet.aq2']: + elif model in ['magnet', 'sensor_magnet', 'sensor_magnet.aq2']: devices.append(XiaomiDoorSensor(device, gateway)) elif model == 'sensor_wleak.aq1': devices.append(XiaomiWaterLeakSensor(device, gateway)) - elif model == 'smoke': + elif model in ['smoke', 'sensor_smoke']: devices.append(XiaomiSmokeSensor(device, gateway)) - elif model == 'natgas': + elif model in ['natgas', 'sensor_natgas']: devices.append(XiaomiNatgasSensor(device, gateway)) - elif model in ['switch', 'sensor_switch.aq2', 'sensor_switch.aq3']: - devices.append(XiaomiButton(device, 'Switch', 'status', + elif model in ['switch', 'sensor_switch', 'sensor_switch.aq2', 'sensor_switch.aq3']: + devices.append(XiaomiButton(device, 'Switch', 'status' if int(device['proto'][0:1]) == 1 else 'channel_0', hass, gateway)) - elif model == '86sw1': + elif model in ['86sw1', 'sensor_86sw1.aq1']: devices.append(XiaomiButton(device, 'Wall Switch', 'channel_0', hass, gateway)) - elif model == '86sw2': + elif model in ['86sw2', 'sensor_86sw2.aq1']: devices.append(XiaomiButton(device, 'Wall Switch (Left)', 'channel_0', hass, gateway)) devices.append(XiaomiButton(device, 'Wall Switch (Right)', 'channel_1', hass, gateway)) devices.append(XiaomiButton(device, 'Wall Switch (Both)', 'dual_channel', hass, gateway)) - elif model == 'cube': + elif model in ['cube', 'sensor_cube']: devices.append(XiaomiCube(device, hass, gateway)) add_devices(devices) diff --git a/homeassistant/components/light/xiaomi_aqara.py b/homeassistant/components/light/xiaomi_aqara.py old mode 100644 new mode 100755 index 125e791829fac..37ae60e3494db --- a/homeassistant/components/light/xiaomi_aqara.py +++ b/homeassistant/components/light/xiaomi_aqara.py @@ -18,7 +18,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): for (_, gateway) in hass.data[PY_XIAOMI_GATEWAY].gateways.items(): for device in gateway.devices['light']: model = device['model'] - if model == 'gateway': + if model in ['gateway', 'gateway.v3']: devices.append(XiaomiGatewayLight(device, 'Gateway Light', gateway)) add_devices(devices) diff --git a/homeassistant/components/sensor/xiaomi_aqara.py b/homeassistant/components/sensor/xiaomi_aqara.py old mode 100644 new mode 100755 index 33bbdc323088a..497a3915154d2 --- a/homeassistant/components/sensor/xiaomi_aqara.py +++ b/homeassistant/components/sensor/xiaomi_aqara.py @@ -26,7 +26,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): 'temperature', gateway)) devices.append(XiaomiSensor(device, 'Humidity', 'humidity', gateway)) - elif device['model'] == 'weather.v1': + elif device['model'] in ['weather', 'weather.v1']: devices.append(XiaomiSensor(device, 'Temperature', 'temperature', gateway)) devices.append(XiaomiSensor(device, 'Humidity', @@ -36,7 +36,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): elif device['model'] == 'sensor_motion.aq2': devices.append(XiaomiSensor(device, 'Illumination', 'lux', gateway)) - elif device['model'] == 'gateway': + elif device['model'] in ['gateway', 'gateway.v3', 'acpartner.v3']: devices.append(XiaomiSensor(device, 'Illumination', 'illumination', gateway)) add_devices(devices) diff --git a/homeassistant/components/switch/xiaomi_aqara.py b/homeassistant/components/switch/xiaomi_aqara.py old mode 100644 new mode 100755 index 939fc70660ad7..da15578c17b12 --- a/homeassistant/components/switch/xiaomi_aqara.py +++ b/homeassistant/components/switch/xiaomi_aqara.py @@ -26,7 +26,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): for device in gateway.devices['switch']: model = device['model'] if model == 'plug': - devices.append(XiaomiGenericSwitch(device, "Plug", 'status', + devices.append(XiaomiGenericSwitch(device, "Plug", 'status' if int(device['proto'][0:1]) == 1 else 'channel_0', True, gateway)) elif model in ['ctrl_neutral1', 'ctrl_neutral1.aq1']: devices.append(XiaomiGenericSwitch(device, 'Wall Switch', @@ -52,7 +52,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): 'Wall Switch LN Right', 'channel_1', False, gateway)) - elif model in ['86plug', 'ctrl_86plug.aq1']: + elif model in ['86plug', 'ctrl_86plug', 'ctrl_86plug.aq1']: devices.append(XiaomiGenericSwitch(device, 'Wall Plug', 'status', True, gateway)) add_devices(devices) diff --git a/homeassistant/components/xiaomi_aqara.py b/homeassistant/components/xiaomi_aqara.py old mode 100644 new mode 100755 index 244605a7b9733..96ba090ad8910 --- a/homeassistant/components/xiaomi_aqara.py +++ b/homeassistant/components/xiaomi_aqara.py @@ -211,6 +211,7 @@ def __init__(self, device, device_type, xiaomi_hub): self._sid = device['sid'] self._name = '{}_{}'.format(device_type, self._sid) self._type = device_type + self._proto = xiaomi_hub.proto self._write_to_hub = xiaomi_hub.write_to_hub self._get_from_hub = xiaomi_hub.get_from_hub self._device_state_attributes = {} From 7ace03856ff4364f03d522f00aef7d23120ce7b8 Mon Sep 17 00:00:00 2001 From: ileler Date: Fri, 30 Mar 2018 15:23:04 +0800 Subject: [PATCH 2/9] format code style --- homeassistant/components/binary_sensor/xiaomi_aqara.py | 6 ++++-- homeassistant/components/switch/xiaomi_aqara.py | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/binary_sensor/xiaomi_aqara.py b/homeassistant/components/binary_sensor/xiaomi_aqara.py index f53d460d9b8f9..6ec0ec878fbab 100755 --- a/homeassistant/components/binary_sensor/xiaomi_aqara.py +++ b/homeassistant/components/binary_sensor/xiaomi_aqara.py @@ -35,8 +35,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None): devices.append(XiaomiSmokeSensor(device, gateway)) elif model in ['natgas', 'sensor_natgas']: devices.append(XiaomiNatgasSensor(device, gateway)) - elif model in ['switch', 'sensor_switch', 'sensor_switch.aq2', 'sensor_switch.aq3']: - devices.append(XiaomiButton(device, 'Switch', 'status' if int(device['proto'][0:1]) == 1 else 'channel_0', + elif model in ['switch', 'sensor_switch', + 'sensor_switch.aq2', 'sensor_switch.aq3']: + devices.append(XiaomiButton(device, 'Switch', + 'status' if int(device['proto'][0:1]) == 1 else 'channel_0', hass, gateway)) elif model in ['86sw1', 'sensor_86sw1.aq1']: devices.append(XiaomiButton(device, 'Wall Switch', 'channel_0', diff --git a/homeassistant/components/switch/xiaomi_aqara.py b/homeassistant/components/switch/xiaomi_aqara.py index da15578c17b12..408b278e4614d 100755 --- a/homeassistant/components/switch/xiaomi_aqara.py +++ b/homeassistant/components/switch/xiaomi_aqara.py @@ -26,7 +26,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): for device in gateway.devices['switch']: model = device['model'] if model == 'plug': - devices.append(XiaomiGenericSwitch(device, "Plug", 'status' if int(device['proto'][0:1]) == 1 else 'channel_0', + devices.append(XiaomiGenericSwitch(device, "Plug", + 'status' if int(device['proto'][0:1]) == 1 else 'channel_0', True, gateway)) elif model in ['ctrl_neutral1', 'ctrl_neutral1.aq1']: devices.append(XiaomiGenericSwitch(device, 'Wall Switch', From 54dad521aa54d464a37b8f20dc9e35887d303eb7 Mon Sep 17 00:00:00 2001 From: ileler Date: Fri, 30 Mar 2018 15:25:16 +0800 Subject: [PATCH 3/9] format code style --- homeassistant/components/binary_sensor/xiaomi_aqara.py | 2 +- homeassistant/components/switch/xiaomi_aqara.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/binary_sensor/xiaomi_aqara.py b/homeassistant/components/binary_sensor/xiaomi_aqara.py index 6ec0ec878fbab..2e5b5f7eacb86 100755 --- a/homeassistant/components/binary_sensor/xiaomi_aqara.py +++ b/homeassistant/components/binary_sensor/xiaomi_aqara.py @@ -38,7 +38,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): elif model in ['switch', 'sensor_switch', 'sensor_switch.aq2', 'sensor_switch.aq3']: devices.append(XiaomiButton(device, 'Switch', - 'status' if int(device['proto'][0:1]) == 1 else 'channel_0', + 'status' if int(device['proto'][0:1]) == 1 else 'channel_0', hass, gateway)) elif model in ['86sw1', 'sensor_86sw1.aq1']: devices.append(XiaomiButton(device, 'Wall Switch', 'channel_0', diff --git a/homeassistant/components/switch/xiaomi_aqara.py b/homeassistant/components/switch/xiaomi_aqara.py index 408b278e4614d..997febdf26b5f 100755 --- a/homeassistant/components/switch/xiaomi_aqara.py +++ b/homeassistant/components/switch/xiaomi_aqara.py @@ -27,7 +27,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): model = device['model'] if model == 'plug': devices.append(XiaomiGenericSwitch(device, "Plug", - 'status' if int(device['proto'][0:1]) == 1 else 'channel_0', + 'status' if int(device['proto'][0:1]) == 1 else 'channel_0', True, gateway)) elif model in ['ctrl_neutral1', 'ctrl_neutral1.aq1']: devices.append(XiaomiGenericSwitch(device, 'Wall Switch', From 77cc7dfb3c8c1e34bb41e28b9b91d736667f3d06 Mon Sep 17 00:00:00 2001 From: ileler Date: Fri, 30 Mar 2018 15:52:36 +0800 Subject: [PATCH 4/9] format code style --- homeassistant/components/binary_sensor/xiaomi_aqara.py | 4 +++- homeassistant/components/switch/xiaomi_aqara.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/binary_sensor/xiaomi_aqara.py b/homeassistant/components/binary_sensor/xiaomi_aqara.py index 2e5b5f7eacb86..4e07585a5f4fb 100755 --- a/homeassistant/components/binary_sensor/xiaomi_aqara.py +++ b/homeassistant/components/binary_sensor/xiaomi_aqara.py @@ -38,7 +38,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None): elif model in ['switch', 'sensor_switch', 'sensor_switch.aq2', 'sensor_switch.aq3']: devices.append(XiaomiButton(device, 'Switch', - 'status' if int(device['proto'][0:1]) == 1 else 'channel_0', + 'status' if 'proto' not in device + or int(device['proto'][0:1]) == 1 + else 'channel_0', hass, gateway)) elif model in ['86sw1', 'sensor_86sw1.aq1']: devices.append(XiaomiButton(device, 'Wall Switch', 'channel_0', diff --git a/homeassistant/components/switch/xiaomi_aqara.py b/homeassistant/components/switch/xiaomi_aqara.py index 997febdf26b5f..3d66f33ad890d 100755 --- a/homeassistant/components/switch/xiaomi_aqara.py +++ b/homeassistant/components/switch/xiaomi_aqara.py @@ -27,7 +27,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None): model = device['model'] if model == 'plug': devices.append(XiaomiGenericSwitch(device, "Plug", - 'status' if int(device['proto'][0:1]) == 1 else 'channel_0', + 'status' if 'proto' not in device + or int(device['proto'][0:1]) == 1 + else 'channel_0', True, gateway)) elif model in ['ctrl_neutral1', 'ctrl_neutral1.aq1']: devices.append(XiaomiGenericSwitch(device, 'Wall Switch', From 29b2d979b809ec9d76bf3f57d3281a1c0fe2924e Mon Sep 17 00:00:00 2001 From: ileler Date: Fri, 30 Mar 2018 15:55:09 +0800 Subject: [PATCH 5/9] format code style --- homeassistant/components/binary_sensor/xiaomi_aqara.py | 3 +-- homeassistant/components/switch/xiaomi_aqara.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/binary_sensor/xiaomi_aqara.py b/homeassistant/components/binary_sensor/xiaomi_aqara.py index 4e07585a5f4fb..b59132fa86692 100755 --- a/homeassistant/components/binary_sensor/xiaomi_aqara.py +++ b/homeassistant/components/binary_sensor/xiaomi_aqara.py @@ -38,8 +38,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): elif model in ['switch', 'sensor_switch', 'sensor_switch.aq2', 'sensor_switch.aq3']: devices.append(XiaomiButton(device, 'Switch', - 'status' if 'proto' not in device - or int(device['proto'][0:1]) == 1 + 'status' if 'proto' not in device or int(device['proto'][0:1]) == 1 else 'channel_0', hass, gateway)) elif model in ['86sw1', 'sensor_86sw1.aq1']: diff --git a/homeassistant/components/switch/xiaomi_aqara.py b/homeassistant/components/switch/xiaomi_aqara.py index 3d66f33ad890d..51c3c9cfd0ce7 100755 --- a/homeassistant/components/switch/xiaomi_aqara.py +++ b/homeassistant/components/switch/xiaomi_aqara.py @@ -27,8 +27,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): model = device['model'] if model == 'plug': devices.append(XiaomiGenericSwitch(device, "Plug", - 'status' if 'proto' not in device - or int(device['proto'][0:1]) == 1 + 'status' if 'proto' not in device or int(device['proto'][0:1]) == 1 else 'channel_0', True, gateway)) elif model in ['ctrl_neutral1', 'ctrl_neutral1.aq1']: From 8a116750303648dbe731692db8c0481230f16f9e Mon Sep 17 00:00:00 2001 From: ileler Date: Fri, 30 Mar 2018 15:58:38 +0800 Subject: [PATCH 6/9] format code style --- homeassistant/components/binary_sensor/xiaomi_aqara.py | 8 +++++--- homeassistant/components/switch/xiaomi_aqara.py | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/binary_sensor/xiaomi_aqara.py b/homeassistant/components/binary_sensor/xiaomi_aqara.py index b59132fa86692..19a02064ca8bd 100755 --- a/homeassistant/components/binary_sensor/xiaomi_aqara.py +++ b/homeassistant/components/binary_sensor/xiaomi_aqara.py @@ -37,9 +37,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None): devices.append(XiaomiNatgasSensor(device, gateway)) elif model in ['switch', 'sensor_switch', 'sensor_switch.aq2', 'sensor_switch.aq3']: - devices.append(XiaomiButton(device, 'Switch', - 'status' if 'proto' not in device or int(device['proto'][0:1]) == 1 - else 'channel_0', + if 'proto' not in device or int(device['proto'][0:1]) == 1: + data_key = 'status' + else: + data_key = 'channel_0' + devices.append(XiaomiButton(device, 'Switch', data_key, hass, gateway)) elif model in ['86sw1', 'sensor_86sw1.aq1']: devices.append(XiaomiButton(device, 'Wall Switch', 'channel_0', diff --git a/homeassistant/components/switch/xiaomi_aqara.py b/homeassistant/components/switch/xiaomi_aqara.py index 51c3c9cfd0ce7..4c44d6b2592f2 100755 --- a/homeassistant/components/switch/xiaomi_aqara.py +++ b/homeassistant/components/switch/xiaomi_aqara.py @@ -26,9 +26,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None): for device in gateway.devices['switch']: model = device['model'] if model == 'plug': - devices.append(XiaomiGenericSwitch(device, "Plug", - 'status' if 'proto' not in device or int(device['proto'][0:1]) == 1 - else 'channel_0', + if 'proto' not in device or int(device['proto'][0:1]) == 1: + data_key = 'status' + else: + data_key = 'channel_0' + devices.append(XiaomiGenericSwitch(device, "Plug", data_key, True, gateway)) elif model in ['ctrl_neutral1', 'ctrl_neutral1.aq1']: devices.append(XiaomiGenericSwitch(device, 'Wall Switch', From 5dc40bf2e12b4bec885e34879ea8b59ae472656a Mon Sep 17 00:00:00 2001 From: ileler Date: Sat, 31 Mar 2018 00:10:22 +0800 Subject: [PATCH 7/9] support motion 2.0 --- homeassistant/components/binary_sensor/xiaomi_aqara.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/binary_sensor/xiaomi_aqara.py b/homeassistant/components/binary_sensor/xiaomi_aqara.py index 19a02064ca8bd..49f716b9eb7b9 100755 --- a/homeassistant/components/binary_sensor/xiaomi_aqara.py +++ b/homeassistant/components/binary_sensor/xiaomi_aqara.py @@ -134,8 +134,12 @@ def __init__(self, device, hass, xiaomi_hub): """Initialize the XiaomiMotionSensor.""" self._hass = hass self._no_motion_since = 0 + if 'proto' not in device or int(device['proto'][0:1]) == 1: + data_key = 'status' + else: + data_key = 'motion_status' XiaomiBinarySensor.__init__(self, device, 'Motion Sensor', xiaomi_hub, - 'status', 'motion') + data_key, 'motion') @property def device_state_attributes(self): From e1f4036b416e6b2e3c4a03dac80db2871514efd2 Mon Sep 17 00:00:00 2001 From: ileler Date: Mon, 2 Apr 2018 00:34:42 +0800 Subject: [PATCH 8/9] remove file executable permissions --- homeassistant/components/binary_sensor/xiaomi_aqara.py | 0 homeassistant/components/light/xiaomi_aqara.py | 0 homeassistant/components/sensor/xiaomi_aqara.py | 0 homeassistant/components/switch/xiaomi_aqara.py | 0 homeassistant/components/xiaomi_aqara.py | 0 5 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 homeassistant/components/binary_sensor/xiaomi_aqara.py mode change 100755 => 100644 homeassistant/components/light/xiaomi_aqara.py mode change 100755 => 100644 homeassistant/components/sensor/xiaomi_aqara.py mode change 100755 => 100644 homeassistant/components/switch/xiaomi_aqara.py mode change 100755 => 100644 homeassistant/components/xiaomi_aqara.py diff --git a/homeassistant/components/binary_sensor/xiaomi_aqara.py b/homeassistant/components/binary_sensor/xiaomi_aqara.py old mode 100755 new mode 100644 diff --git a/homeassistant/components/light/xiaomi_aqara.py b/homeassistant/components/light/xiaomi_aqara.py old mode 100755 new mode 100644 diff --git a/homeassistant/components/sensor/xiaomi_aqara.py b/homeassistant/components/sensor/xiaomi_aqara.py old mode 100755 new mode 100644 diff --git a/homeassistant/components/switch/xiaomi_aqara.py b/homeassistant/components/switch/xiaomi_aqara.py old mode 100755 new mode 100644 diff --git a/homeassistant/components/xiaomi_aqara.py b/homeassistant/components/xiaomi_aqara.py old mode 100755 new mode 100644 From d8c103f3822f37005509e395fa51777d4bbc37bc Mon Sep 17 00:00:00 2001 From: ileler Date: Mon, 2 Apr 2018 09:13:35 +0800 Subject: [PATCH 9/9] remove unused variables --- homeassistant/components/xiaomi_aqara.py | 1 - 1 file changed, 1 deletion(-) diff --git a/homeassistant/components/xiaomi_aqara.py b/homeassistant/components/xiaomi_aqara.py index 96ba090ad8910..244605a7b9733 100755 --- a/homeassistant/components/xiaomi_aqara.py +++ b/homeassistant/components/xiaomi_aqara.py @@ -211,7 +211,6 @@ def __init__(self, device, device_type, xiaomi_hub): self._sid = device['sid'] self._name = '{}_{}'.format(device_type, self._sid) self._type = device_type - self._proto = xiaomi_hub.proto self._write_to_hub = xiaomi_hub.write_to_hub self._get_from_hub = xiaomi_hub.get_from_hub self._device_state_attributes = {}