@@ -158,28 +158,40 @@ async def download_sonoff_ota(listener, ota_dir):
158
158
159
159
async def download_zigpy_ota (app , listener ):
160
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 .debug ("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 .debug ("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
+ )
176
183
177
184
178
185
async def ota_update_images (
179
186
app , listener , ieee , cmd , data , service , params , event_data
180
187
):
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
+ )
183
195
184
196
185
197
async def ota_notify (
0 commit comments