Skip to content

Commit 98f3931

Browse files
committed
Extra code to force download of images known by zigpy configuration
1 parent 2488aa9 commit 98f3931

File tree

1 file changed

+24
-3
lines changed
  • custom_components/zha_toolkit

1 file changed

+24
-3
lines changed

custom_components/zha_toolkit/ota.py

+24-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from glob import glob
55

66
import aiohttp
7+
import zigpy
78

89
from . import DEFAULT_OTAU
910
from . import utils as u
@@ -155,6 +156,25 @@ async def download_sonoff_ota(listener, ota_dir):
155156
LOGGER.warning("Exception getting '%s': %s", url, e)
156157

157158

159+
async def download_zigpy_ota(app, listener):
160+
LOGGER.debug("Zigpy download procedure starting")
161+
for _, (ota, _) in app.ota._listeners.items():
162+
if isinstance(ota, zigpy.ota.provider.FileStore):
163+
# Skip files provider
164+
continue
165+
await ota.refresh_firmware_list()
166+
for image_key, image in ota._cache.items():
167+
url = getattr(image, "url", None)
168+
LOGGER.error("Try getting %r, %r, %r", image_key, url, image)
169+
try:
170+
img = await app.ota.get_ota_image(
171+
image_key.manufacturer_id, image_key.image_type, model=None
172+
)
173+
LOGGER.info("Got image %r", getattr(img, "header", None))
174+
except Exception as e:
175+
LOGGER.error("%r while getting %r - %s", e, image_key, url)
176+
177+
158178
async def ota_update_images(
159179
app, listener, ieee, cmd, data, service, params, event_data
160180
):
@@ -165,20 +185,21 @@ async def ota_update_images(
165185
async def ota_notify(
166186
app, listener, ieee, cmd, data, service, params, event_data
167187
):
188+
LOGGER.error("OTA_notify")
168189
event_data["PAR"] = params
169190
if params[p.DOWNLOAD]:
170-
# Download FW from koenkk's list
171191
if params[p.PATH]:
172192
ota_dir = params[p.PATH]
173193
else:
174194
ota_dir = DEFAULT_OTAU
175195

176196
LOGGER.debug(
177-
"OTA image download requested - default:%s, effective: %s",
178-
DEFAULT_OTAU,
197+
"OTA image download to '%s' (Default dir is:'%s')",
179198
ota_dir,
199+
DEFAULT_OTAU,
180200
)
181201

202+
await download_zigpy_ota(app, listener)
182203
await download_koenkk_ota(listener, ota_dir)
183204
await download_sonoff_ota(listener, ota_dir)
184205

0 commit comments

Comments
 (0)