@@ -142,7 +142,7 @@ async def subscribe(self, callback: Callable[[RoborockMessage], None]) -> Callab
142142 # Make an initial, optimistic attempt to connect to local with the
143143 # cache. The cache information will be refreshed by the background task.
144144 try :
145- await self ._local_connect (use_cache = True )
145+ await self ._local_connect (prefer_cache = True )
146146 except RoborockException as err :
147147 _LOGGER .warning ("Could not establish local connection for device %s: %s" , self ._device_uid , err )
148148
@@ -175,33 +175,37 @@ def unsub() -> None:
175175 self ._callback = callback
176176 return unsub
177177
178- async def _get_networking_info (self , * , use_cache : bool = True ) -> NetworkInfo :
178+ async def _get_networking_info (self , * , prefer_cache : bool = True ) -> NetworkInfo :
179179 """Retrieve networking information for the device.
180180
181181 This is a cloud only command used to get the local device's IP address.
182182 """
183183 cache_data = await self ._cache .get ()
184- if use_cache and cache_data .network_info and (network_info := cache_data .network_info .get (self ._device_uid )):
184+ if prefer_cache and cache_data .network_info and (network_info := cache_data .network_info .get (self ._device_uid )):
185185 _LOGGER .debug ("Using cached network info for device %s" , self ._device_uid )
186186 return network_info
187187 try :
188188 network_info = await self ._mqtt_rpc_channel .send_command (
189189 RoborockCommand .GET_NETWORK_INFO , response_type = NetworkInfo
190190 )
191191 except RoborockException as e :
192+ _LOGGER .debug ("Error fetching network info for device %s" , self ._device_uid )
193+ if cache_data .network_info and (network_info := cache_data .network_info .get (self ._device_uid )):
194+ _LOGGER .debug ("Falling back to cached network info for device %s after error" , self ._device_uid )
195+ return network_info
192196 raise RoborockException (f"Network info failed for device { self ._device_uid } " ) from e
193197 _LOGGER .debug ("Network info for device %s: %s" , self ._device_uid , network_info )
194198 self ._last_network_info_refresh = datetime .datetime .now (datetime .UTC )
195199 cache_data .network_info [self ._device_uid ] = network_info
196200 await self ._cache .set (cache_data )
197201 return network_info
198202
199- async def _local_connect (self , * , use_cache : bool = True ) -> None :
203+ async def _local_connect (self , * , prefer_cache : bool = True ) -> None :
200204 """Set up local connection if possible."""
201205 _LOGGER .debug (
202- "Attempting to connect to local channel for device %s (use_cache =%s)" , self ._device_uid , use_cache
206+ "Attempting to connect to local channel for device %s (prefer_cache =%s)" , self ._device_uid , prefer_cache
203207 )
204- networking_info = await self ._get_networking_info (use_cache = use_cache )
208+ networking_info = await self ._get_networking_info (prefer_cache = prefer_cache )
205209 host = networking_info .ip
206210 _LOGGER .debug ("Connecting to local channel at %s" , host )
207211 # Create a new local channel and connect
@@ -236,7 +240,7 @@ async def _background_reconnect(self) -> None:
236240 reconnect_backoff = min (reconnect_backoff * RECONNECT_MULTIPLIER , MAX_RECONNECT_INTERVAL )
237241
238242 use_cache = self ._should_use_cache (local_connect_failures )
239- await self ._local_connect (use_cache = use_cache )
243+ await self ._local_connect (prefer_cache = use_cache )
240244 # Reset backoff and failures on success
241245 reconnect_backoff = MIN_RECONNECT_INTERVAL
242246 local_connect_failures = 0
0 commit comments