Skip to content

Add shared-session API instance + reactive re-login - #36

Open
johanzander wants to merge 1 commit into
chore/clean-sync-masterfrom
feat/shared-session-relogin
Open

Add shared-session API instance + reactive re-login#36
johanzander wants to merge 1 commit into
chore/clean-sync-masterfrom
feat/shared-session-relogin

Conversation

@johanzander

Copy link
Copy Markdown
Owner

Summary

Stacked on #35 (clean sync) — this is deliberately the only functional diff from clean upstream, so it's reviewable on its own.

  • 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 problems this integration has fought historically.
  • GrowattCoordinator._async_re_login: reactive re-authentication on session expiry (detected via 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.

Test plan

Merge #35 first; this will retarget to master automatically once that lands.

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.
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.

1 participant