Skip to content

Fix AtonStorageIntegrationSensor construction for HA 2026.8 (IntegrationSensor dropped hass again) - #58

Open
proscar87 wants to merge 1 commit into
wilds:masterfrom
proscar87:fix/ha-2026-8-integrationsensor-hass
Open

proscar87 wants to merge 1 commit into
wilds:masterfrom
proscar87:fix/ha-2026-8-integrationsensor-hass

Conversation

@proscar87

Copy link
Copy Markdown

Root cause

AtonStorageIntegrationSensor (custom_components/atonstorage/sensor.py) subclasses homeassistant.components.integration.sensor.IntegrationSensor and always forwards hass positionally to super().__init__() (lines 596/612, added in #51 for HA 2025.8, which made hass a required constructor argument — see the "Home Assistant 2025.8+: IntegrationSensor requires hass" comments and issue #50).

home-assistant/core#177596 ("Do not set a device on YAML integration entities", merged 2026-07-30, shipped in HA 2026.8.0 on 2026-08-05) reverses that: it removes hass from IntegrationSensor.__init__ entirely and makes every remaining parameter keyword-only:

# HA 2026.7.x
def __init__(self, hass: HomeAssistant, *, integration_method: str, ..., max_sub_interval): ...

# HA 2026.8.0
def __init__(self, *, integration_method: str, ..., max_sub_interval, device=None): ...

So on 2026.8+, AtonStorageIntegrationSensor.__init__'s super().__init__(hass, integration_method=..., ...) now raises:

TypeError: IntegrationSensor.__init__() takes 1 positional argument but 2 positional arguments (and 8 keyword-only arguments) were given

This matches the traceback in #57 exactly (line-for-line, down to sensor.py:618/sensor.py:501 in that report). That issue was closed today by the reporter without a fix landing — the code on master is still broken as of this PR.

Why it's not in HA's changelog

IntegrationSensor is a helper base class, not a public integration; core maintainers treat its constructor as internal API, so this removal wasn't listed in HA's official breaking-changes documentation for 2026.8. It only surfaces as a TypeError at entity-setup time once a user upgrades, exactly as in #57.

Fix

Detect at runtime, via inspect.signature(IntegrationSensor.__init__), whether hass is still an accepted parameter, and only forward it then — instead of assuming either direction. This is the second time this constructor's hass handling has flipped (required in 2025.8, removed again in 2026.8), so a version-independent check avoids having to chase every future core change:

if "hass" in inspect.signature(IntegrationSensor.__init__).parameters:
    integration_kwargs["hass"] = hass
super().__init__(**integration_kwargs)

hass is passed as a keyword (never positionally) to the parent, since positional hass is exactly what the 2026.8 keyword-only signature rejects too.

Diff is scoped to AtonStorageIntegrationSensor.__init__ (+ the import inspect). No other call sites, other classes, or unrelated code touched.

Precedent

Same pattern, same upstream change, already merged elsewhere in the HACS ecosystem this week:

  • woopstar/hsem#716
  • kamaradclimber/heishamon-homeassistant#389 (same IntegrationSensor subclassing pattern)
  • kamaradclimber/geovelo-homeassistant#33 (UtilityMeterSensor, same hass-removal shape)
  • TarasKhust/ecoflow-api-mqtt#71 (IntegrationSensor, same shape)

bramstroker/homeassistant-powercalc and Olen/homeassistant-plant#500 already carry their own version-independent guard for the same upstream change.

What I validated

  • This repo had no test suite before this PR (no tests/ dir, no pytest config). Added tests/test_integration_sensor_hass_2026_8.py and a minimal pytest.ini.
  • The main test (test_integration_sensor_constructs_against_real_ha) constructs AtonStorageIntegrationSensor for real, against the actually-installed IntegrationSensor (HA 2026.8.0, pinned via pip install homeassistant==2026.8.0 in my test environment), using a real homeassistant.core.HomeAssistant() instance with device/entity registries loaded (dr.async_load / er.async_load) — not a bare mock — exercising the exact call path used by _create_entities(). Confirmed this test fails with the exact TypeError from Errors after upgrading to HA 2026.08 #57 against the unfixed source, and passes once the fix is applied.
  • Two further tests monkeypatch IntegrationSensor.__init__ to pin the cross-version contract (hass forwarded when the parent accepts it / omitted when it doesn't), independent of whichever HA version is actually installed.
  • Ran flake8 --config=.flake8 custom_components/atonstorage/sensor.py: clean, matching the repo's existing lint config.

What I did NOT validate

  • I don't have an AtonStorage account/inverter, so no live end-to-end run against a real device or real HA instance/UI was possible — only the construction path shown above.
  • Didn't validate against real HA 2025.x–2026.7 (the "hass required" era) with the actual old IntegrationSensor installed; the pre-2026.8 contract is covered only via the monkeypatch stand-in test, not a second real HA install.
  • No CI wiring was added for the new tests (kept the diff to the fix + tests themselves); happy to add a workflow if the maintainer wants one.

🤖 Generated with Claude Code

Note: this fix (code, tests, and PR description) was authored with Claude Code (Anthropic). I've reviewed it and validated the test results above myself.

…ill accepts it

home-assistant/core#177596 ("Do not set a device on YAML integration
entities", merged 2026-07-30, shipped in HA 2026.8.0 on 2026-08-05) removed
the `hass` parameter from IntegrationSensor.__init__ and made every
remaining parameter keyword-only. This is not on HA's official
breaking-changes list, because core maintainers treat IntegrationSensor as
internal API.

AtonStorageIntegrationSensor.__init__ (custom_components/atonstorage/
sensor.py) already adapted once to a change in the opposite direction: HA
2025.8 made `hass` a *required* argument, so this component was updated to
always forward it positionally (see the "Home Assistant 2025.8+:
IntegrationSensor requires hass" comments, from PR wilds#51 / issue wilds#50). HA
2026.8 flips it back, so `super().__init__(hass, ...)` now raises:

    TypeError: IntegrationSensor.__init__() takes 1 positional argument but
    2 positional arguments (and 8 keyword-only arguments) were given

matching the traceback in issue wilds#57, which the reporter closed today without
a fix landing.

Detect at runtime via inspect.signature() whether the installed
IntegrationSensor.__init__ still accepts `hass`, and only forward it then,
so the same code works whether hass is required (pre-2026.8), optional, or
rejected (2026.8+) -- no version pinning needed.

Adds tests/test_integration_sensor_hass_2026_8.py (this repo had no test
suite before), plus a pytest.ini so async fixtures run. The main test
constructs AtonStorageIntegrationSensor for real, against the actually
installed IntegrationSensor, using a real HomeAssistant() instance with
device/entity registries loaded rather than a bare mock, so it exercises the
real _create_entities() call path; against the unfixed source it reproduces
the exact TypeError above. Two further tests monkeypatch the parent
__init__ to pin the cross-version contract (hass forwarded when accepted,
omitted when rejected) independent of the installed HA version.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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