@@ -75,7 +75,7 @@ def __init__(self, vendor_id: int, ota_provider_dir: Path) -> None:
75
75
self ._ota_file_path : Path | None = None
76
76
self ._ota_provider_proc : Process | None = None
77
77
self ._ota_provider_task : asyncio .Task | None = None
78
- self ._ota_done : asyncio .Event = asyncio .Event ()
78
+ self ._ota_done : asyncio .Future = asyncio .Future ()
79
79
self ._ota_target_node_id : int | None = None
80
80
81
81
async def initialize (self ) -> None :
@@ -161,11 +161,9 @@ async def _commission_ota_provider(
161
161
"Failed writing adjusted OTA Provider App ACL: Status %s." ,
162
162
str (write_result [0 ].Status ),
163
163
)
164
- await self .stop ()
165
164
raise UpdateError ("Error while setting up OTA Provider." )
166
165
except ChipStackError as ex :
167
166
logging .exception ("Failed adjusting OTA Provider App ACL." , exc_info = ex )
168
- await self .stop ()
169
167
raise UpdateError ("Error while setting up OTA Provider." ) from ex
170
168
171
169
async def start_update (
@@ -239,8 +237,11 @@ async def start_update(
239
237
"Error while announcing OTA Provider to node."
240
238
) from ex
241
239
242
- await self ._ota_done .wait ()
240
+ LOGGER .info ("Waiting for target node update state change" )
241
+ await self ._ota_done
242
+ LOGGER .info ("OTA update finished successfully" )
243
243
finally :
244
+ LOGGER .info ("Cleaning up OTA provider" )
244
245
await self .stop ()
245
246
self ._ota_target_node_id = None
246
247
@@ -345,30 +346,28 @@ async def check_update_state(
345
346
) -> None :
346
347
"""Check the update state of a node and take appropriate action."""
347
348
348
- LOGGER .info ("Update state changed: %s, %s %s" , str (path ), old_value , new_value )
349
349
if str (path ) != OTA_SOFTWARE_UPDATE_REQUESTOR_UPDATE_STATE_ATTRIBUTE_PATH :
350
350
return
351
351
352
- update_state = cast (
353
- Clusters .OtaSoftwareUpdateRequestor .Enums .UpdateStateEnum , new_value
354
- )
352
+ UpdateState = Clusters .OtaSoftwareUpdateRequestor .Enums .UpdateStateEnum # noqa: N806
355
353
356
- old_update_state = cast (
357
- Clusters .OtaSoftwareUpdateRequestor .Enums .UpdateStateEnum , old_value
354
+ new_update_state = UpdateState (new_value )
355
+ old_update_state = UpdateState (old_value )
356
+
357
+ LOGGER .info (
358
+ "Update state changed from %r to %r" ,
359
+ old_update_state ,
360
+ new_update_state ,
358
361
)
359
362
360
363
# Update state of target node changed, check if update is done.
361
- if (
362
- update_state
363
- == Clusters .OtaSoftwareUpdateRequestor .Enums .UpdateStateEnum .kIdle
364
- ):
365
- if (
366
- old_update_state
367
- == Clusters .OtaSoftwareUpdateRequestor .Enums .UpdateStateEnum .kQuerying
368
- ):
369
- raise UpdateError ("Target node did not process the update file" )
364
+ if new_update_state == UpdateState .kIdle :
365
+ if old_update_state == UpdateState .kQuerying :
366
+ self ._ota_done .set_exception (
367
+ UpdateError ("Target node did not process the update file" )
368
+ )
370
369
371
370
LOGGER .info (
372
371
"Node %d update state idle, assuming done." , self ._ota_target_node_id
373
372
)
374
- self ._ota_done .set ( )
373
+ self ._ota_done .set_result ( None )
0 commit comments