From ad6d40c7b3a424bfde9bacf22a4f3b81f7e23cbf Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Tue, 16 Jun 2020 22:58:49 +0200 Subject: [PATCH 01/10] prevent errors on "lumi.gateway.mieu01" --- miio/gateway.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/miio/gateway.py b/miio/gateway.py index da21e6049..6310dd96e 100644 --- a/miio/gateway.py +++ b/miio/gateway.py @@ -252,9 +252,14 @@ def discover_devices(self): DeviceType.D1WallSwitchTripleNN: D1WallSwitchTripleNN, DeviceType.ThermostatS2: ThermostatS2, } - devices_raw = self.get_prop("device_list") self._devices = {} + # Check if this gateway does not supports getting the device_list + if self.info().model == "lumi.gateway.mieu01": + return self._devices + + devices_raw = self.get_prop("device_list") + for x in range(0, len(devices_raw), 5): # Extract discovered information dev_info = SubDeviceInfo(*devices_raw[x : x + 5]) From 439eafa666cec2ecd825123679c21e7ba9e58527 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Wed, 17 Jun 2020 13:26:11 +0200 Subject: [PATCH 02/10] add voltage and better support "lumi.gateway.mieu01" --- miio/gateway.py | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/miio/gateway.py b/miio/gateway.py index 6310dd96e..e02b70018 100644 --- a/miio/gateway.py +++ b/miio/gateway.py @@ -166,6 +166,7 @@ def __init__( self._zigbee = GatewayZigbee(parent=self) self._light = GatewayLight(parent=self) self._devices = {} + self._info = None @property def alarm(self) -> "GatewayAlarm": @@ -193,6 +194,14 @@ def devices(self): """Return a dict of the already discovered devices.""" return self._devices + @property + def model(self): + """Return the zigbee model of the gateway.""" + # Check if catch already has the gateway info, otherwise get it from the device + if self._info is None: + self._info = self.info() + return self._info.model + @command() def discover_devices(self): """ @@ -255,7 +264,7 @@ def discover_devices(self): self._devices = {} # Check if this gateway does not supports getting the device_list - if self.info().model == "lumi.gateway.mieu01": + if self.model == "lumi.gateway.mieu01": return self._devices devices_raw = self.get_prop("device_list") @@ -711,6 +720,7 @@ def __init__(self, gw: Gateway = None, dev_info: SubDeviceInfo = None,) -> None: self._gw = gw self.sid = dev_info.sid self._battery = None + self._voltage = None self._fw_ver = dev_info.fw_ver self._props = self.props() try: @@ -720,7 +730,7 @@ def __init__(self, gw: Gateway = None, dev_info: SubDeviceInfo = None,) -> None: def __repr__(self): return ( - "" + "" % ( self.device_type, self.sid, @@ -728,6 +738,7 @@ def __repr__(self): self.zigbee_model, self.firmware_version, self.get_battery(), + self.get_voltage(), self.status, ) ) @@ -764,9 +775,14 @@ def firmware_version(self): @property def battery(self): - """Return the battery level.""" + """Return the battery level in %.""" return self._battery + @property + def voltage(self): + """Return the battery voltage in V.""" + return self._voltage + @command() def update(self): """Update the device-specific properties.""" @@ -852,9 +868,27 @@ def unpair(self): @command() def get_battery(self): """Update the battery level and return the new value.""" - self._battery = self.send("get_battery").pop() + if self._gw.model != "lumi.gateway.mieu01": + self._battery = self.send("get_battery").pop() + else: + _LOGGER.info( + "Gateway model '%s' does not (yet) support get_battery", + self._gw.model, + ) return self._battery + @command() + def get_voltage(self): + """Update the battery voltage and return the new value.""" + if self._gw.model == "lumi.gateway.mieu01": + self._voltage = self.get_property("voltage").pop()/1000 + else: + _LOGGER.info( + "Gateway model '%s' does not (yet) support get_voltage", + self._gw.model, + ) + return self._voltage + @command() def get_firmware_version(self) -> Optional[int]: """Returns firmware version.""" From ef38b2a35849108622184664132805c9d48e2340 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Thu, 18 Jun 2020 23:54:18 +0200 Subject: [PATCH 03/10] styling --- miio/gateway.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/miio/gateway.py b/miio/gateway.py index e02b70018..7c1121434 100644 --- a/miio/gateway.py +++ b/miio/gateway.py @@ -1,8 +1,8 @@ """Xiaomi Aqara Gateway implementation using Miio protecol.""" -import logging from datetime import datetime from enum import Enum, IntEnum +import logging from typing import Optional import attr @@ -872,8 +872,7 @@ def get_battery(self): self._battery = self.send("get_battery").pop() else: _LOGGER.info( - "Gateway model '%s' does not (yet) support get_battery", - self._gw.model, + "Gateway model '%s' does not (yet) support get_battery", self._gw.model, ) return self._battery @@ -881,11 +880,10 @@ def get_battery(self): def get_voltage(self): """Update the battery voltage and return the new value.""" if self._gw.model == "lumi.gateway.mieu01": - self._voltage = self.get_property("voltage").pop()/1000 + self._voltage = self.get_property("voltage").pop() / 1000 else: _LOGGER.info( - "Gateway model '%s' does not (yet) support get_voltage", - self._gw.model, + "Gateway model '%s' does not (yet) support get_voltage", self._gw.model, ) return self._voltage From f5f5dcae2b58e9f42a1a64179ca3922073eb04a7 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Fri, 19 Jun 2020 00:04:09 +0200 Subject: [PATCH 04/10] fix isort --- miio/gateway.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miio/gateway.py b/miio/gateway.py index 7c1121434..bfc6b8328 100644 --- a/miio/gateway.py +++ b/miio/gateway.py @@ -1,8 +1,8 @@ """Xiaomi Aqara Gateway implementation using Miio protecol.""" +import logging from datetime import datetime from enum import Enum, IntEnum -import logging from typing import Optional import attr From 194f66f8188d75de2ca35c648928a0785e925be5 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 21 Jun 2020 08:12:51 +0200 Subject: [PATCH 05/10] Update comments Co-authored-by: Teemu R. --- miio/gateway.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miio/gateway.py b/miio/gateway.py index bfc6b8328..366933f73 100644 --- a/miio/gateway.py +++ b/miio/gateway.py @@ -263,7 +263,7 @@ def discover_devices(self): } self._devices = {} - # Check if this gateway does not supports getting the device_list + # Skip the models which do not support getting the device list if self.model == "lumi.gateway.mieu01": return self._devices From 21523e1d6d5a1a7934fb2d685a66138501fbc3b8 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 21 Jun 2020 08:17:46 +0200 Subject: [PATCH 06/10] add log message --- miio/gateway.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/miio/gateway.py b/miio/gateway.py index 366933f73..4dcab9d16 100644 --- a/miio/gateway.py +++ b/miio/gateway.py @@ -265,6 +265,9 @@ def discover_devices(self): # Skip the models which do not support getting the device list if self.model == "lumi.gateway.mieu01": + _LOGGER.info( + "Gateway model '%s' does not (yet) support getting the device list", self.model, + ) return self._devices devices_raw = self.get_prop("device_list") From ea709f1a5763b9e12bcb7edab71adafe48bab8c2 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 21 Jun 2020 19:18:25 +0200 Subject: [PATCH 07/10] fix black --- miio/gateway.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/miio/gateway.py b/miio/gateway.py index 4dcab9d16..aabb61cc3 100644 --- a/miio/gateway.py +++ b/miio/gateway.py @@ -266,7 +266,8 @@ def discover_devices(self): # Skip the models which do not support getting the device list if self.model == "lumi.gateway.mieu01": _LOGGER.info( - "Gateway model '%s' does not (yet) support getting the device list", self.model, + "Gateway model '%s' does not (yet) support getting the device list", + self.model, ) return self._devices From 83630b2beb60751a3e18acadfa575bf344c125ea Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Fri, 26 Jun 2020 09:21:12 +0200 Subject: [PATCH 08/10] add gateway model constants --- miio/gateway.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/miio/gateway.py b/miio/gateway.py index aabb61cc3..9f09c3c41 100644 --- a/miio/gateway.py +++ b/miio/gateway.py @@ -15,6 +15,10 @@ _LOGGER = logging.getLogger(__name__) +GATEWAY_MODEL_CHINA = "lumi.gateway.v3" +GATEWAY_MODEL_EU ="lumi.gateway.mieu01" +GATEWAY_MODEL_ZIG3 = "lumi.gateway.mgl03" +GATEWAY_MODEL_AQARA = "lumi.gateway.aqhm01" color_map = { "red": (255, 0, 0), @@ -264,7 +268,7 @@ def discover_devices(self): self._devices = {} # Skip the models which do not support getting the device list - if self.model == "lumi.gateway.mieu01": + if self.model == GATEWAY_MODEL_EU: _LOGGER.info( "Gateway model '%s' does not (yet) support getting the device list", self.model, @@ -871,8 +875,8 @@ def unpair(self): @command() def get_battery(self): - """Update the battery level and return the new value.""" - if self._gw.model != "lumi.gateway.mieu01": + """Update the battery level, if available.""" + if self._gw.model != GATEWAY_MODEL_EU: self._battery = self.send("get_battery").pop() else: _LOGGER.info( @@ -882,8 +886,8 @@ def get_battery(self): @command() def get_voltage(self): - """Update the battery voltage and return the new value.""" - if self._gw.model == "lumi.gateway.mieu01": + """Update the battery voltage, if available.""" + if self._gw.model == GATEWAY_MODEL_EU: self._voltage = self.get_property("voltage").pop() / 1000 else: _LOGGER.info( From 8c027f08d65cfd7284696f8c92b6c4be6dddf903 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Fri, 26 Jun 2020 09:34:35 +0200 Subject: [PATCH 09/10] black formatting --- miio/gateway.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miio/gateway.py b/miio/gateway.py index 9f09c3c41..815707cc8 100644 --- a/miio/gateway.py +++ b/miio/gateway.py @@ -16,7 +16,7 @@ _LOGGER = logging.getLogger(__name__) GATEWAY_MODEL_CHINA = "lumi.gateway.v3" -GATEWAY_MODEL_EU ="lumi.gateway.mieu01" +GATEWAY_MODEL_EU = "lumi.gateway.mieu01" GATEWAY_MODEL_ZIG3 = "lumi.gateway.mgl03" GATEWAY_MODEL_AQARA = "lumi.gateway.aqhm01" From a6374fdd1faa72bd1a182f1a59752129dae59e19 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Fri, 26 Jun 2020 18:27:44 +0200 Subject: [PATCH 10/10] change info to warning log --- miio/gateway.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miio/gateway.py b/miio/gateway.py index 815707cc8..e818efd5d 100644 --- a/miio/gateway.py +++ b/miio/gateway.py @@ -269,7 +269,7 @@ def discover_devices(self): # Skip the models which do not support getting the device list if self.model == GATEWAY_MODEL_EU: - _LOGGER.info( + _LOGGER.warning( "Gateway model '%s' does not (yet) support getting the device list", self.model, )