Skip to content

Commit

Permalink
Return limited support for old gateway firmwares
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Nov 22, 2021
1 parent 52f86a0 commit 326257d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
14 changes: 8 additions & 6 deletions custom_components/xiaomi_gateway3/core/gateway3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 15 additions & 2 deletions custom_components/xiaomi_gateway3/core/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 326257d

Please sign in to comment.