Skip to content

Commit

Permalink
Fix ezsp flasher
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Dec 25, 2024
1 parent 516824e commit 4ff8e70
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions custom_components/xiaomi_gateway3/core/ezsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging
import socket
import time
from typing import Optional

from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_create_clientsession
Expand All @@ -19,7 +18,7 @@
async def update_zigbee_firmware(hass: HomeAssistant, host: str, custom: bool):
tar_fw = "6.7.10.0" if custom else "6.6.2.0"

_LOGGER.debug(f"{host} [FWUP] Target zigbee firmware v{tar_fw}")
_LOGGER.info(f"{host} [FWUP] Target zigbee firmware v{tar_fw}")

session = Session(host)

Expand Down Expand Up @@ -51,6 +50,7 @@ async def update_zigbee_firmware(hass: HomeAssistant, host: str, custom: bool):

# some users have broken firmware, so unknown firmware also OK
cur_fw = await read_firmware(host)
_LOGGER.info(f"{host} [FWUP] Firmware before update: {cur_fw}")
if cur_fw and cur_fw.startswith(tar_fw):
_LOGGER.debug(f"{host} [FWUP] No need to update")
return True
Expand Down Expand Up @@ -83,6 +83,7 @@ async def update_zigbee_firmware(hass: HomeAssistant, host: str, custom: bool):
await asyncio.sleep(2)

cur_fw = await read_firmware(host)
_LOGGER.info(f"{host} [FWUP] Firmware after update: {cur_fw}")
return cur_fw and cur_fw.startswith(tar_fw)

except Exception as e:
Expand All @@ -96,23 +97,19 @@ async def update_zigbee_firmware(hass: HomeAssistant, host: str, custom: bool):
await sh.close()


async def read_firmware(host: str) -> Optional[str]:
ezsp = None
async def read_firmware(host: str) -> str | None:
version = None
try:
from bellows.ezsp import EZSP

ezsp = EZSP(
{"path": f"socket://{host}:8889", "baudrate": 0, "flow_control": None}
)
await ezsp.connect(use_thread=False)
await ezsp.startup_reset()
_, _, version = await ezsp.get_board_info()
await ezsp.disconnect()
except Exception as e:
_LOGGER.debug(f"{host} [FWUP] Read firmware error: {e}")
return None
finally:
if ezsp:
ezsp.close()
_LOGGER.warning(f"{host} [FWUP] Read firmware error: {e}")

_LOGGER.debug(f"{host} [FWUP] Current zigbee firmware v{version}")

Expand Down

0 comments on commit 4ff8e70

Please sign in to comment.