Fix AtonStorageIntegrationSensor construction for HA 2026.8 (IntegrationSensor dropped hass again) - #58
Open
proscar87 wants to merge 1 commit into
Conversation
…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>
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.
Root cause
AtonStorageIntegrationSensor(custom_components/atonstorage/sensor.py) subclasseshomeassistant.components.integration.sensor.IntegrationSensorand always forwardshasspositionally tosuper().__init__()(lines 596/612, added in #51 for HA 2025.8, which madehassa 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 removeshassfromIntegrationSensor.__init__entirely and makes every remaining parameter keyword-only:So on 2026.8+,
AtonStorageIntegrationSensor.__init__'ssuper().__init__(hass, integration_method=..., ...)now raises:This matches the traceback in #57 exactly (line-for-line, down to
sensor.py:618/sensor.py:501in that report). That issue was closed today by the reporter without a fix landing — the code onmasteris still broken as of this PR.Why it's not in HA's changelog
IntegrationSensoris 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 aTypeErrorat entity-setup time once a user upgrades, exactly as in #57.Fix
Detect at runtime, via
inspect.signature(IntegrationSensor.__init__), whetherhassis still an accepted parameter, and only forward it then — instead of assuming either direction. This is the second time this constructor'shasshandling has flipped (required in 2025.8, removed again in 2026.8), so a version-independent check avoids having to chase every future core change:hassis passed as a keyword (never positionally) to the parent, since positionalhassis exactly what the 2026.8 keyword-only signature rejects too.Diff is scoped to
AtonStorageIntegrationSensor.__init__(+ theimport 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#716kamaradclimber/heishamon-homeassistant#389(sameIntegrationSensorsubclassing pattern)kamaradclimber/geovelo-homeassistant#33(UtilityMeterSensor, samehass-removal shape)TarasKhust/ecoflow-api-mqtt#71(IntegrationSensor, same shape)bramstroker/homeassistant-powercalcandOlen/homeassistant-plant#500already carry their own version-independent guard for the same upstream change.What I validated
tests/dir, no pytest config). Addedtests/test_integration_sensor_hass_2026_8.pyand a minimalpytest.ini.test_integration_sensor_constructs_against_real_ha) constructsAtonStorageIntegrationSensorfor real, against the actually-installedIntegrationSensor(HA 2026.8.0, pinned viapip install homeassistant==2026.8.0in my test environment), using a realhomeassistant.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 exactTypeErrorfrom Errors after upgrading to HA 2026.08 #57 against the unfixed source, and passes once the fix is applied.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.flake8 --config=.flake8 custom_components/atonstorage/sensor.py: clean, matching the repo's existing lint config.What I did NOT validate
IntegrationSensorinstalled; the pre-2026.8 contract is covered only via the monkeypatch stand-in test, not a second real HA install.🤖 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.