Skip to content

Conversation

@google-labs-jules
Copy link

Fixes a bug where the integration would fail to reconnect to a local device if the internet connection was lost, because it insisted on refreshing network info via MQTT. Now it falls back to cached network info if MQTT fails.


PR created automatically by Jules for task 12219964731058244295 started by @Lash-L

When the device disconnects from the internet, the MQTT connection may also be unavailable. Previously, `V1Channel` would force a fresh network info lookup via MQTT during reconnection attempts if the cache was stale or on the first retry, leading to repeated failures.

This change adds a fallback mechanism: if the MQTT request for network info fails, we check if we have cached network info. If so, we use it (with a warning) to attempt a local connection. This allows the device to reconnect locally even if the cloud is temporarily unreachable.

Added `tests/devices/test_v1_channel_reconnect.py` to verify this behavior.
@google-labs-jules
Copy link
Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!


For security, I will only act on instructions from the user who triggered this task.

New to Jules? Learn more at jules.google/docs.

@@ -0,0 +1,86 @@

import asyncio
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix linting in this file

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the linting issues (removed unused imports, sorted imports, fixed line length, and removed leading empty line).

Comment on lines -184 to +187
if use_cache and cache_data.network_info and (network_info := cache_data.network_info.get(self._device_uid)):
cached_info = cache_data.network_info.get(self._device_uid) if cache_data.network_info else None
if use_cache and cached_info:
_LOGGER.debug("Using cached network info for device %s", self._device_uid)
return network_info
return cached_info
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this equivalent to what we had before?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for the use_cache=True path it is equivalent. However, I extracted cached_info into a variable so it can be reused in the except block below (lines 193-199) to support the fallback mechanism without fetching from the cache again.

@Lash-L
Copy link
Collaborator

Lash-L commented Nov 28, 2025

no good

@Lash-L Lash-L closed this Nov 28, 2025
@google-labs-jules
Copy link
Author

no good

I've refactored the code to restore the original structure for the initial cache check (restoring network_info variable name and logic). The fallback cache lookup is now performed independently inside the exception handler. This avoids early lookup when not needed and keeps the diff minimal and cleaner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants