Skip to content

Commit

Permalink
Add watchdog for Z3GatewayHost executed commands
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Apr 6, 2024
1 parent 1410750 commit 21d3f18
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions custom_components/xiaomi_gateway3/core/gate/silabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class SilabsGateway(XGateway):
force_pair: bool = False
unknown: dict = {}

# sometimes Multimode Gateway 1 stop respond on /commands (no /executed messages)
# probably this happenes when Aqara Bulb exist in network
# so we will restart Z3GatewayHost on next /heartbeat
commands_ts: float = 0

async def silabs_read_device(self, sh: ShellBase):
# 1. Read coordinator info
raw = await sh.read_file("/data/zigbee/coordinator.info")
Expand Down Expand Up @@ -60,6 +65,10 @@ def silabs_on_mqtt_publish(self, msg: MQTTMessage):
asyncio.create_task(coro)
elif msg.topic.endswith("/heartbeat"):
self.silabs_process_heartbeat(msg.json)
elif msg.topic.endswith("/commands"):
self.commands_ts = time.time()
elif msg.topic.endswith("/executed"):
self.commands_ts = 0
elif msg.topic.endswith("/deviceleft"):
self.silabs_process_deviceleft(msg.json)

Expand Down Expand Up @@ -119,6 +128,11 @@ def silabs_process_recv(self, data: dict):
device.on_report(data, self, ts)

def silabs_process_heartbeat(self, data: dict):
if self.commands_ts and time.time() - self.commands_ts > 5:
self.commands_ts = 0
self.warning("Z3GatewayHost has no respond - restart it")
asyncio.create_task(self.silabs_restart())

payload = {
"network_pan_id": data.get("networkPanId"),
"radio_tx_power": data.get("radioTxPower"),
Expand Down Expand Up @@ -270,3 +284,11 @@ async def silabs_process_neighbors(self, device: XDevice, data: dict):
index = payload["start_index"] + len(payload["neighbors"])
if index < payload["entries"]:
await self.silabs_neighbors_read(device.nwk, index)

async def silabs_restart(self):
try:
async with Session(self.host) as sh:
# names for all supported gateway models
await sh.exec("killall Lumi_Z3GatewayHost_MQTT mZ3GatewayHost_MQTT")
except Exception as e:
self.warning("Can't restart silabs", exc_info=e)

0 comments on commit 21d3f18

Please sign in to comment.