@@ -807,7 +807,10 @@ async def get_devices(self, location_id: int) -> list[dict[str, Any]]:
807807 # Try to use cached websocket device data first
808808 # The DeviceHub websocket sends DeviceListInitialValuesReceived with full device info
809809 if self ._websocket_device_cache :
810- LOG .debug ("Using cached device list from websocket (%d devices)" , len (self ._websocket_device_cache ))
810+ LOG .debug (
811+ "Using cached device list from websocket (%d devices)" ,
812+ len (self ._websocket_device_cache ),
813+ )
811814 devices = self ._websocket_device_cache .copy ()
812815 # Try GraphQL if we have a URN and no websocket cache
813816 elif self .urn :
@@ -862,37 +865,38 @@ async def get_devices(self, location_id: int) -> list[dict[str, Any]]:
862865 devices .append (callback ())
863866
864867 return devices
865-
868+
866869 def cache_websocket_devices (self , device_list : list [dict [str , Any ]]) -> None :
867870 """Cache device list received from DeviceHub websocket.
868-
871+
869872 The DeviceListInitialValuesReceived message contains the full device list
870873 with all the info we need (id, name, identifier, etc.) in REST format.
871874 This eliminates the need to call the deprecated REST endpoint.
872-
875+
873876 Args:
874877 device_list: List of devices from DeviceListInitialValuesReceived
875878 """
876879 self ._websocket_device_cache = device_list
877880 self ._device_cache_ready .set ()
878881 LOG .debug ("Cached %d devices from websocket" , len (device_list ))
879-
882+
880883 async def wait_for_device_cache (self , timeout : float = 10.0 ) -> bool :
881884 """Wait for the websocket device cache to be populated.
882-
885+
883886 This should be called before devices.async_init() to ensure
884887 device names and IDs are available from the websocket.
885-
888+
886889 Args:
887890 timeout: Maximum time to wait in seconds (default: 10.0)
888-
891+
889892 Returns:
890893 True if cache was populated, False if timeout occurred
891894 """
892895 import time
896+
893897 start_time = time .time ()
894898 LOG .debug ("Waiting for websocket device cache (timeout: %.1fs)..." , timeout )
895-
899+
896900 try :
897901 await asyncio .wait_for (self ._device_cache_ready .wait (), timeout = timeout )
898902 elapsed = time .time () - start_time
@@ -902,7 +906,7 @@ async def wait_for_device_cache(self, timeout: float = 10.0) -> bool:
902906 elapsed = time .time () - start_time
903907 LOG .warning (
904908 "Timeout waiting for websocket device cache after %.2f seconds, will use fallback method" ,
905- elapsed
909+ elapsed ,
906910 )
907911 return False
908912
@@ -1114,4 +1118,4 @@ async def get_weather(self, location_id: int) -> dict[str, Any]:
11141118 LOG .debug ("Weather URL is %s" , url )
11151119 response = await self .async_request ("get" , url )
11161120 LOG .debug ("Weather API response: %s" , response )
1117- return cast (dict [str , Any ], response )
1121+ return cast (dict [str , Any ], response )
0 commit comments