-
Notifications
You must be signed in to change notification settings - Fork 57
Fix V1Channel reconnection by falling back to cache when MQTT fails #604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
|
👋 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 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 | |||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
| 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
|
no good |
I've refactored the code to restore the original structure for the initial cache check (restoring |
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