Skip to content

chore: sync custom_components/growatt_server to clean upstream - #35

Open
johanzander wants to merge 2 commits into
masterfrom
chore/clean-sync-master
Open

chore: sync custom_components/growatt_server to clean upstream#35
johanzander wants to merge 2 commits into
masterfrom
chore/clean-sync-master

Conversation

@johanzander

Copy link
Copy Markdown
Owner

Summary

Pure sync step, deliberately split out from what was PR #34 so this base can be verified as clean on its own before any wanted changes go on top (see follow-up PR).

Replaces custom_components/growatt_server wholesale with current home-assistant/core upstream (cd52154), plus the minimal test-infrastructure fixes needed to actually validate that.

Consequences of syncing to upstream:

  • Drops the duplicate SPH implementation (sph.py + wiring) in favor of upstream's own canonical version — merged via your own home-assistant/core#165314.
  • Drops throttle.py (ApiThrottleManager) and its test file/fixture — confirmed it was never wired into the real setup flow (zero call sites for _handle_throttled_setup, ApiThrottleManager never instantiated anywhere). Removing dead code, not changing behavior.

Only deviations from a literal byte-for-byte copy — both genuine bugs in upstream's current source, verified directly against the GitHub API (not just the local clone) to rule out extraction issues:

  • Two except ValueError, TypeError:-style clauses (invalid Python 3 syntax) in coordinator.py.
  • Missing from __future__ import annotations in number.py, sensor/__init__.py, switch.py — each forward-references an entity class in a return-type annotation before its definition; without the future import this raises NameError at import time. Reproduced the exact failure standalone to confirm before fixing.

Both worth reporting upstream separately.

Also found and fixed, pre-existing and unrelated to the sync itself (discovered because this appears to be the first time this suite has actually been run — there's no CI workflow that runs pytest, only a release workflow):

  • Every test file imported homeassistant.components.growatt_server instead of custom_components.growatt_server — silently testing whatever's pip-installed, not this repo's code.
  • conftest.py never wired up pytest-homeassistant-custom-component's enable_custom_integrations fixture, so hass.config_entries.async_setup loaded the real installed package at runtime regardless of the test-file import fix above. Confirmed via setup logs before/after.
  • A few GrowattV1ApiError(...) test calls using an outdated constructor signature.

Known NOT fixed here, flagging for visibility:

  • test_config_flow.py expects a CONF_REGION constant/config-flow feature that was never implemented — looks like an intended CONF_URL→region-selection rename that never landed. Real feature work, out of scope for a sync PR. Excluded from the test run below.
  • Two migration tests (test_migrate_legacy_*_config) fail because the migration-detection logic is gated on config_entry.minor_version < 1, but the tests' MockConfigEntry doesn't set a version, so it never triggers. Pre-existing test bug, unrelated to anything changed here.
  • Snapshots (tests/snapshots/*.ambr) and several service/switch error-message assertions are stale against upstream's actual current behavior (nicer translated field names, different entity structure) — regenerating them means reviewing a 16k+ line snapshot diff, which needs human eyes, not something to wave through in an agent session.

Test plan

  • ruff check clean on every changed file.
  • python -m py_compile clean on every changed file.
  • Actually ran the test suite for the first time (Python 3.14, matching upstream's requires-python = \">=3.14.2\", plus current pytest-homeassistant-custom-component/homeassistant/growattServer): 33 passed, 56 failed (excluding test_config_flow.py). Confirmed the failures are upstream-sync-driven staleness (stale snapshots/messages) or pre-existing unrelated gaps (above), not regressions from this PR — happy to dig into any specific one you want prioritized.

Replaces custom_components/growatt_server wholesale with the current
home-assistant/core upstream implementation (commit cd52154), with zero
functional additions of our own — this is deliberately just the sync step,
so it's reviewable/verifiable on its own before any wanted changes are
layered back on top in a follow-up PR.

Consequences of syncing to upstream:
- Drops the duplicate SPH implementation (sph.py + wiring) in favor of
  upstream's own canonical version — merged via our own
  home-assistant/core#165314.
- Drops throttle.py (ApiThrottleManager) and its test file/fixture — it was
  never wired into the real setup flow (no call sites), so this is inert
  code being removed, not a behavior change.

Only deviations from a literal byte-for-byte copy, both genuine bugs in
upstream's current source (verified directly against the GitHub API, not
just our local clone, to rule out extraction issues on our side):
- Two `except ValueError, TypeError:`-style clauses (invalid Python 3
  syntax) in coordinator.py.
- Missing `from __future__ import annotations` in number.py,
  sensor/__init__.py, and switch.py, each of which forward-references an
  entity class in a return-type annotation before its definition — without
  the future import this raises NameError at import time, before any test
  can even collect. Reproduced the exact failure standalone to confirm.

Both are worth reporting upstream separately; fixing them here is required
for "clean" to also mean "importable."

Also restores repo-identity manifest.json fields (name, documentation,
issue_tracker) that syncing wholesale would otherwise overwrite with
upstream's own.
…tches

Two pre-existing test-infrastructure bugs, unrelated to the vendor sync,
found while trying to actually run this suite (it apparently never has
been — no CI workflow runs pytest at all, only a release workflow):

1. Every test file imported from `homeassistant.components.growatt_server`
   instead of `custom_components.growatt_server`. Direct top-level imports
   resolve to whichever is actually pip-installed regardless, so this was
   silently testing the real published PyPI package's growatt_server, not
   this repo's code, whenever a compatible version happened to be
   installed.

2. `conftest.py` never wired up pytest-homeassistant-custom-component's
   `enable_custom_integrations` fixture (it's opt-in, not automatic). This
   is the piece that actually makes runtime component loading
   (`hass.config_entries.async_setup`) use this repo's
   custom_components/growatt_server instead of the real installed package.
   Confirmed via logs: before this fix, setup logged
   "Loaded growatt_server from homeassistant.components.growatt_server";
   after, "Loaded growatt_server from custom_components.growatt_server".

Also updates a handful of `GrowattV1ApiError(...)` test calls to the
current required (error_code, error_msg) signature.

Result: tests now genuinely exercise this repo's code. Pass count looks
worse than before (33/89 vs whatever it was testing the wrong package),
which is expected and correct — it's now surfacing real staleness in this
suite's snapshots and error-message assertions against the current
upstream-synced behavior, not evidence of a regression. That staleness is
a separate, sizable follow-up (see PR description), not fixed here.
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