Skip to content

Commit fecf8ae

Browse files
authored
Merge pull request #226 from systemcrash/fixes
Test that app has ota and ota has listeners for OTA operations
2 parents ac1e4b0 + d82cdc4 commit fecf8ae

File tree

1 file changed

+29
-17
lines changed
  • custom_components/zha_toolkit

1 file changed

+29
-17
lines changed

custom_components/zha_toolkit/ota.py

+29-17
Original file line numberDiff line numberDiff line change
@@ -158,28 +158,40 @@ async def download_sonoff_ota(listener, ota_dir):
158158

159159
async def download_zigpy_ota(app, listener):
160160
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)
161+
if hasattr(app, "ota") and hasattr(app.ota, "_listeners"):
162+
for _, (ota, _) in app.ota._listeners.items():
163+
if isinstance(ota, zigpy.ota.provider.FileStore):
164+
# Skip files provider
165+
continue
166+
await ota.refresh_firmware_list()
167+
for image_key, image in ota._cache.items():
168+
url = getattr(image, "url", None)
169+
LOGGER.error("Try getting %r, %r, %r", image_key, url, image)
170+
try:
171+
img = await app.ota.get_ota_image(
172+
image_key.manufacturer_id,
173+
image_key.image_type,
174+
model=None,
175+
)
176+
LOGGER.info("Got image %r", getattr(img, "header", None))
177+
except Exception as e:
178+
LOGGER.error("%r while getting %r - %s", e, image_key, url)
179+
else:
180+
LOGGER.warning(
181+
"Could not get ota object for download_zigpy_ota, try again"
182+
)
176183

177184

178185
async def ota_update_images(
179186
app, listener, ieee, cmd, data, service, params, event_data
180187
):
181-
for _, (ota, _) in app.ota._listeners.items():
182-
await ota.refresh_firmware_list()
188+
if hasattr(app, "ota") and hasattr(app.ota, "_listeners"):
189+
for _, (ota, _) in app.ota._listeners.items():
190+
await ota.refresh_firmware_list()
191+
else:
192+
LOGGER.warning(
193+
"Could not get ota object for ota_update_images, try again"
194+
)
183195

184196

185197
async def ota_notify(

0 commit comments

Comments
 (0)