Skip to content

Commit

Permalink
Test that app has ota and ota has listeners for OTA operations
Browse files Browse the repository at this point in the history
Apparently in some situations they're absent. Let's guard against them.

Closes issue #225
  • Loading branch information
systemcrash committed May 26, 2024
1 parent ced7097 commit a9b37ca
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions custom_components/zha_toolkit/ota.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,28 +158,34 @@ async def download_sonoff_ota(listener, ota_dir):

async def download_zigpy_ota(app, listener):
LOGGER.debug("Zigpy download procedure starting")
for _, (ota, _) in app.ota._listeners.items():
if isinstance(ota, zigpy.ota.provider.FileStore):
# Skip files provider
continue
await ota.refresh_firmware_list()
for image_key, image in ota._cache.items():
url = getattr(image, "url", None)
LOGGER.error("Try getting %r, %r, %r", image_key, url, image)
try:
img = await app.ota.get_ota_image(
image_key.manufacturer_id, image_key.image_type, model=None
)
LOGGER.info("Got image %r", getattr(img, "header", None))
except Exception as e:
LOGGER.error("%r while getting %r - %s", e, image_key, url)
if hasattr(app, 'ota') and hasattr(app.ota, '_listeners'):
for _, (ota, _) in app.ota._listeners.items():
if isinstance(ota, zigpy.ota.provider.FileStore):
# Skip files provider
continue
await ota.refresh_firmware_list()
for image_key, image in ota._cache.items():
url = getattr(image, "url", None)
LOGGER.error("Try getting %r, %r, %r", image_key, url, image)
try:
img = await app.ota.get_ota_image(
image_key.manufacturer_id, image_key.image_type, model=None
)
LOGGER.info("Got image %r", getattr(img, "header", None))
except Exception as e:
LOGGER.error("%r while getting %r - %s", e, image_key, url)
else:
LOGGER.warning("Could not get ota object for download_zigpy_ota, try again")


async def ota_update_images(
app, listener, ieee, cmd, data, service, params, event_data
):
for _, (ota, _) in app.ota._listeners.items():
await ota.refresh_firmware_list()
if hasattr(app, 'ota') and hasattr(app.ota, '_listeners'):
for _, (ota, _) in app.ota._listeners.items():
await ota.refresh_firmware_list()
else:
LOGGER.warning("Could not get ota object for ota_update_images, try again")


async def ota_notify(
Expand Down

0 comments on commit a9b37ca

Please sign in to comment.