Rebuild on current upstream: drop redundant SPH/throttle, keep shared-session re-login - #34
Closed
johanzander wants to merge 1 commit into
Closed
Rebuild on current upstream: drop redundant SPH/throttle, keep shared-session re-login#34johanzander wants to merge 1 commit into
johanzander wants to merge 1 commit into
Conversation
…-session re-login master had drifted behind upstream home-assistant/core's growatt_server component in several ways it shouldn't have: - SPH device support (sph.py, coordinator/service wiring) duplicated what's now upstream's own canonical implementation — merged via PR #165314 (home-assistant/core#165314), authored by @johanzander. Dropped in favor of upstream's version. - throttle.py's ApiThrottleManager (disk-persisted rate-limit guard) was never actually wired into the setup flow — dead code with its own test file but zero call sites. Dropped. Upstream's own ConfigEntryNotReady-based handling for V1-API rate-limit errors covers that path instead. - Everything else (translation_key-based exceptions, the periodic new/removed-device auto-discovery scanner, general refactors) — took upstream's more current version wholesale. What's kept, because it's real and 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 logs in 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. Also fixes two `except ValueError, TypeError:`-style syntax errors (invalid Python 3 syntax) present in the current upstream source itself — found because reconstructing on top of it wouldn't otherwise compile. Not verified by the test suite: this environment's package index caps at homeassistant==2025.1.4, which predates this component's current structure (AUTH_API_TOKEN and more), so pytest-homeassistant-custom-component can't actually run here — confirmed pre-existing by running unmodified master against the same environment with identical failure. Verified instead via ruff (clean) and py_compile (clean) on every changed file.
Owner
Author
|
Superseded by a cleaner split: #35 |
3 tasks
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
masterhad drifted behind current upstreamhome-assistant/corein ways it shouldn't have — this rebuilds onvendor-sync(a clean current snapshot of upstream'sgrowatt_servercomponent) and re-applies only what's genuinely still needed.Dropped (now redundant with upstream):
sph.py+ wiring in coordinator/services/sensor) — duplicated your own home-assistant/core#165314, merged 2026-03-16. Upstream's canonical version is used instead.throttle.py'sApiThrottleManager— verified it was never actually wired into the setup flow (_handle_throttled_setuphad zero call sites,ApiThrottleManagerwas never instantiated anywhere). Dead code with its own test file. Dropped, along withtests/test_throttle.pyand the now-unusedmock_throttle_managerautouse fixture /no_throttle_mockmarker.translation_key-based exceptions, the periodic new/removed-device auto-discovery scanner, general refactors,diagnostics.py).Kept, because it's real and still load-bearing:
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.Also fixed: two
except ValueError, TypeError:-style syntax errors (invalid Python 3 syntax) that are present in upstreamhome-assistant/core'sdevbranch itself right now — found because the file wouldn't compile otherwise. Worth reporting upstream separately.Test plan
ruff checkpasses clean on every changed file.python -m py_compilepasses clean on every changed file (also how the two upstream syntax errors were caught).pytest-homeassistant-custom-componentsuite. This dev environment's package index caps athomeassistant==2025.1.4, which predates this component's current structure (noAUTH_API_TOKEN, etc.) — confirmed this is a pre-existing environment limitation, not something introduced here, by running unmodifiedmasteragainst the same environment and getting an identical import failure. Please run the real test suite locally before merging.