Skip to content

Refuse to load on Home Assistant older than 2026.8.0 with a clear error - #1619

Open
IDavinciCode wants to merge 1 commit into
custom-components:masterfrom
IDavinciCode:fix/minimum-ha-version-guard
Open

IDavinciCode wants to merge 1 commit into
custom-components:masterfrom
IDavinciCode:fix/minimum-ha-version-guard

Conversation

@IDavinciCode

Copy link
Copy Markdown

Fixes #1613

hacs.json declares Home Assistant 2026.8.0 as the minimum, but nothing in the integration enforces it. On an older Home Assistant the first error a user sees is a raw ImportError: cannot import name 'UnitOfDensity' from const.py (or an AttributeError for async_get_device_by_identifier), with no hint that the version is the problem.

This adds the guard proposed in the issue: MIN_HA_VERSION = "2026.8.0" in __init__.py, checked after the homeassistant.* imports and before the local imports (which pull in const.py). On an older version it raises one ImportError that names the required version, the running version and both remedies. Importing the config flow runs the package __init__ first, so the same check covers it.

Before, with Home Assistant reporting 2026.1.3 and UnitOfDensity absent:
ImportError: cannot import name 'UnitOfDensity' from 'homeassistant.const'

After:
ImportError: Passive BLE Monitor requires Home Assistant 2026.8.0 or newer, but this instance runs 2026.1.3. Update Home Assistant, or install a ble_monitor release that supports 2026.1.3.

Tests: test/test_ha_version.py checks that an older version is refused with both versions in the message, that 2026.8.0 and newer (including a beta) load, and that MIN_HA_VERSION equals the minimum in hacs.json, so the two cannot drift apart. The full suite passes apart from test_obj3003_timestamps_are_utc, which fails the same way on master on my Windows machine (time zone). isort and codespell are clean.

🤖 Generated with Claude Code

hacs.json declares 2026.8.0 as the minimum, but nothing in the
integration enforces it. On an older Home Assistant the first thing a
user sees is a raw ImportError for UnitOfDensity from const.py (or an
AttributeError for async_get_device_by_identifier), with no hint that
the version is the problem.

Check the running version in __init__.py before the local imports and
raise one ImportError that names the required version, the running
version and both remedies. The floor is a constant kept equal to
hacs.json, and a test asserts the two agree.

Fixes custom-components#1613

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Add a minimum-HA-version guard: below HA 2026.8 the failure is ImportError/AttributeError, not "requires HA 2026.8+"

1 participant