Add shared-session API instance + reactive re-login - #36
Open
johanzander wants to merge 1 commit into
Open
Conversation
On top of the clean upstream sync (chore/clean-sync-master), adds back the one piece of prior work that's genuinely still needed: - Every GrowattCoordinator for a config entry now shares ONE authenticated API instance via config_entry.runtime_data.api, instead of each coordinator creating and logging into its own. Upstream's coordinator currently calls api.login() on every single update cycle for Classic API — with N devices that's N independent logins every scan interval, which is very likely the actual root cause of the rate-limiting this integration has fought historically. - GrowattCoordinator._async_re_login: reactive re-authentication on session expiry (a JSONDecodeError — the server returns an HTML login page instead of JSON), guarded by a shared asyncio.Lock + 60s cooldown (runtime_data.login_lock / last_login_time) so concurrent coordinators don't all re-login at once. Verified against chore/clean-sync-master's baseline: ruff clean, py_compile clean, and the test suite's pass/fail count (33 passed / 56 failed, minus test_config_flow.py's pre-existing CONF_REGION gap) is identical before and after this change — confirming zero new regressions from this diff itself.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacked on #35 (clean sync) — this is deliberately the only functional diff from clean upstream, so it's reviewable on its own.
GrowattCoordinatorfor a config entry now shares one authenticated API instance viaconfig_entry.runtime_data.api, instead of each coordinator creating and logging into its own. Upstream's coordinator currently callsapi.login()on every single update cycle for Classic API — with N devices that's N independent logins every scan interval, which is very likely the actual root cause of the rate-limiting problems this integration has fought historically.GrowattCoordinator._async_re_login: reactive re-authentication on session expiry (detected viaJSONDecodeError— the server returns an HTML login page instead of JSON), guarded by a sharedasyncio.Lock+ 60s cooldown (runtime_data.login_lock/last_login_time) so concurrent coordinators don't all re-login at once.Test plan
ruff checkclean.python -m py_compileclean.test_config_flow.py) is identical before and after this diff, confirming zero new regressions from this change on top of chore: sync custom_components/growatt_server to clean upstream #35's baseline.Merge #35 first; this will retarget to
masterautomatically once that lands.