From 326257dc00c599c1f522bf33c01b0a163fc6075f Mon Sep 17 00:00:00 2001 From: Alexey Khit Date: Mon, 22 Nov 2021 20:13:23 +0300 Subject: [PATCH] Return limited support for old gateway firmwares --- .../xiaomi_gateway3/core/gateway3.py | 14 ++++++++------ custom_components/xiaomi_gateway3/core/shell.py | 17 +++++++++++++++-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/custom_components/xiaomi_gateway3/core/gateway3.py b/custom_components/xiaomi_gateway3/core/gateway3.py index 0c9d2c65..ef7eadbd 100644 --- a/custom_components/xiaomi_gateway3/core/gateway3.py +++ b/custom_components/xiaomi_gateway3/core/gateway3.py @@ -56,6 +56,9 @@ def debug(self, message: str): if 'true' in self.debug_mode: _LOGGER.debug(f"{self.host} | {message}") + def warning(self, message: str): + _LOGGER.warning(f"{self.host} | {message}") + class GatewayMesh(GatewayBase): mesh_params: list = None @@ -828,12 +831,6 @@ async def prepare_gateway(self): if not await sh.connect(self.host): return False - if sh.ver < '1.4.7_0000': - _LOGGER.error( - f"Gateway {self.host} firmware {sh.ver} unsupported" - ) - return False - self.debug(f"Version: {sh.ver}") ps = await sh.get_running_ps() @@ -885,6 +882,11 @@ async def prepare_gateway(self): shell.PATCH_MEMORY_ZIGBEE3] await sh.exec(shell.SAVE_SERIAL_STATS) + if sh.ver < '1.4.7_0000': + await sh.patch_miio_mqtt_fw146(ps) + self.warning(f"Firmware {sh.ver} support is very limited!") + return True + if sh.miio_ps(mpatches) not in ps: self.debug(f"Patch daemon_miio.sh with {len(mpatches)}") await sh.update_daemon_miio(mpatches) diff --git a/custom_components/xiaomi_gateway3/core/shell.py b/custom_components/xiaomi_gateway3/core/shell.py index 3b19873c..a867e689 100644 --- a/custom_components/xiaomi_gateway3/core/shell.py +++ b/custom_components/xiaomi_gateway3/core/shell.py @@ -29,8 +29,8 @@ b"ble_info miioconfig.db 2>/dev/null | base64\n" MD5_BT = { - '1.4.6_0012': '367bf0045d00c28f6bff8d4132b883de', - '1.4.6_0043': 'c4fa99797438f21d0ae4a6c855b720d2', + # '1.4.6_0012': '367bf0045d00c28f6bff8d4132b883de', + # '1.4.6_0043': 'c4fa99797438f21d0ae4a6c855b720d2', '1.4.7_0115': 'be4724fbc5223fcde60aff7f58ffea28', '1.4.7_0160': '9290241cd9f1892d2ba84074f07391d4', '1.5.0_0026': '9290241cd9f1892d2ba84074f07391d4', @@ -124,6 +124,9 @@ def sed(app: str, pattern: str, repl: str): DB_BLUETOOTH = "`ls -1t /data/miio/mible_local.db /tmp/miio/mible_local.db 2>/dev/null | sed q`" DB_ZIGBEE = "`ls -1t /data/zigbee_gw/* /tmp/zigbee_gw/* 2>/dev/null | sed -r 's/[^/]+$/*.json/;q'`" +# limited partial support on old firmwares +MIIO2MQTT_FW146 = "miio_client -l 4 -d /data/miio | awk '/ot_agent_recv_handler_one.+(ble_event|properties_changed|heartbeat)/{print $0;fflush()}' | mosquitto_pub -t log/miio -l &" + class TelnetShell: reader: StreamReader = None @@ -243,6 +246,16 @@ async def memory_sync(self): command = SYNC_MEMORY_FILE.format(file[5:]) await self.exec(command) + async def patch_miio_mqtt_fw146(self, ps: str): + assert self.ver < "1.4.7_0000", self.ver + if "-t log/miio" in ps: + return + await self.exec("killall daemon_miio.sh") + await self.exec("killall miio_client; pkill -f log/miio") + await asyncio.sleep(.5) + await self.exec(MIIO2MQTT_FW146) + await self.exec("daemon_miio.sh &") + @staticmethod def app_ps(patches: list): if patches: