@@ -242,6 +242,14 @@ def _parse_message(self, msg: dict[str, Any]) -> None:
242242 self ._ready_event .set ()
243243 LOG .info ("Websocket: Ready for data" )
244244 return
245+
246+ # Cache device list from DeviceListInitialValuesReceived
247+ if msg .get ("target" ) == "DeviceListInitialValuesReceived" :
248+ if "arguments" in msg and len (msg ["arguments" ]) > 0 :
249+ device_list = msg ["arguments" ][0 ]
250+ if isinstance (device_list , list ) and self ._api .api :
251+ self ._api .api .cache_websocket_devices (device_list )
252+
245253 event = websocket_event_from_payload (msg )
246254 for callback in self ._event_callbacks :
247255 schedule_callback (callback , event )
@@ -436,6 +444,7 @@ class WebsocketConfig:
436444 """Configuration for a websocket connection"""
437445
438446 endpoint : str
447+ api : API | None = None
439448 url : Optional [str ] = None
440449 token : Optional [str ] = None
441450 connection_id : Optional [str ] = None
@@ -453,6 +462,7 @@ def __init__(
453462 async_request : Callable [..., Any ],
454463 state_yaml : str ,
455464 set_state_callback : Callable [..., Any ],
465+ api : API ,
456466 ) -> None :
457467 """Initialize the websocket manager.
458468
@@ -461,18 +471,20 @@ def __init__(
461471 async_request: The async request method from the API class
462472 state_yaml: Path to the state file
463473 set_state_callback: Callback to save state
474+ api: The API instance
464475 """
465476 self .session = session
466477 self .async_request = async_request
467478 self ._state_yaml = state_yaml
468479 self ._set_state = set_state_callback
480+ self ._api = api
469481 self ._shared_token : Optional [str ] = None
470482 # Initialize websocket configurations, more can be added here
471483 self .devicehub = WebsocketConfig (
472- endpoint = AUTOMATION_DEVICEHUB_ENDPOINT , session = session
484+ endpoint = AUTOMATION_DEVICEHUB_ENDPOINT , session = session , api = api
473485 )
474486 self .challengehub = WebsocketConfig (
475- endpoint = AUTOMATION_CHALLENGE_ENDPOINT , session = session
487+ endpoint = AUTOMATION_CHALLENGE_ENDPOINT , session = session , api = api
476488 )
477489
478490 async def initialize_websockets (self ) -> None :
@@ -567,4 +579,4 @@ async def _get_websocket_params(self, config: WebsocketConfig) -> None:
567579 else "websocketChallenges"
568580 )
569581 LOG .debug ("Calling set_state %s_params" , state_key )
570- await self ._set_state (self ._state_yaml , state_key , websocket_dict )
582+ await self ._set_state (self ._state_yaml , state_key , websocket_dict )
0 commit comments