Repository navigation
Modernize integration to current Home Assistant standards - #45
Merged
dvejsada merged 4 commits intoOct 3, 2026
Merged
Conversation
Refactor the integration to follow current Home Assistant architecture and config-flow standards. - Add DataUpdateCoordinator (coordinator.py) and drop the custom hub/callback pattern; all entities are now CoordinatorEntity, so a single centralized poll drives every entity and availability is handled automatically (previously the whole board stopped updating if the "updated" sensor was disabled). - Store the coordinator on entry.runtime_data with a typed PIDConfigEntry instead of hass.data[DOMAIN]; removes the untyped dict access across every platform. - Use Home Assistant's shared aiohttp session instead of opening a new ClientSession on every request; wrap client errors as CannotConnect. - manifest: drop aiohttp/attrs from requirements (both ship with core), add integration_type "device", bump version to 3.0.0. - Config flow: VERSION = 1 (was the invalid float 0.1), remove the deprecated/incorrect CONNECTION_CLASS, use ConfigFlowResult, set a unique_id per stop and abort on duplicates, and map the unknown-error case to a real translation key. - Add an options flow (departures, calendar events, walking offset) reading options with a fallback to data so existing entries keep working without migration, and reload on change. - Add a reauth flow: the coordinator raises ConfigEntryAuthFailed on an invalid key so users can enter a new one instead of re-adding. - Smaller fixes: dt.now() instead of ZoneInfo, fix the infotext icon to use is_on, type system_health_info, add strings.json, and extend all translations (en/cs/de/sk) with options/reauth/unknown keys (also fixes a cs.json cal_events key typo). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ww8phBs758zj4tCrato36c
- Rename the coordinator's `name` property to `board_name`. DataUpdateCoordinator.__init__ assigns self.name, so the read-only property raised AttributeError and no departure board could be set up. - Departure sensors and the calendar are unavailable instead of raising IndexError on every poll when the API returns fewer departures than configured (e.g. at night). - Remove departure entities left over after the number of departures is lowered in the options. - Give entries created before unique IDs existed the stop ID as unique ID, so adding the same stop again is detected; existing duplicates are left as they are. - Raise the minimum Home Assistant version in hacs.json to 2024.11 (runtime_data, coordinator config_entry, options flow config_entry). - Readme: minimum version, link to the PID Departures Card repository. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BtKZ4PW3A6jeHULgkzuGUc
Requirements, setup fields including the walking offset, options and re-authentication, a list of entities and departure attributes, when entities are unavailable, upgrading from version 2, and troubleshooting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BtKZ4PW3A6jeHULgkzuGUc
HACS installs the integration from pid_departures.zip attached to the release (zip_release in hacs.json), which was uploaded by hand so far. The workflow checks that the release tag matches the manifest version, zips the contents of the integration folder (the same layout as previous releases) and attaches it to the release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BtKZ4PW3A6jeHULgkzuGUc
This was referenced Oct 3, 2026
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
This PR implements Part A (modernization) of the review — bringing the integration in line with current Home Assistant architecture and config-flow standards. No new user-facing features are added here (that's Part B); this is a structural modernization. Behaviour is preserved, with more robust updating and config management.
Integration version bumped 2.1.0 → 3.0.0 (internal refactor; entities and unique IDs are unchanged, so existing installs upgrade in place).
What changed
A1 —
DataUpdateCoordinator(newcoordinator.py)Replaces the hand-rolled hub +
register_callback/publish_updatespattern. Every entity is now aCoordinatorEntity, so a single centralized poll drives all entities and availability is handled automatically. Previously the entire board stopped refreshing if the "updated" sensor was disabled (it was the only polling entity) — that fragility is gone.A2 —
entry.runtime_dataThe coordinator is stored on
entry.runtime_datawith a typedPIDConfigEntryinstead ofhass.data[DOMAIN], removing ~all the# type: ignore[Any]dict lookups across the platforms.A3 — Shared aiohttp session + manifest
dep_board_apinow uses Home Assistant's sharedasync_get_clientsessioninstead of opening a brand-newClientSessionon every request; client/timeout errors are wrapped asCannotConnect.manifest.json: droppedaiohttp/attrsfromrequirements(both ship with core), addedintegration_type: "device", bumped version.A4 — Config-flow correctness
VERSION = 1(was the invalid float0.1).CONNECTION_CLASS.FlowResult→ConfigFlowResult.unique_idper stop and aborts on duplicates.A5 — Options + reauth flows
data, so existing entries keep working with no migration; the entry reloads on change.ConfigEntryAuthFailedon an invalid key, so an expired key can be replaced via the standard re-auth prompt instead of deleting and re-adding the board.A6 — Smaller standards fixes
homeassistant.util.dt.now()instead of a hardcodedZoneInfo("Europe/Prague").is_on(was reading the wrong attribute).system_health_info.strings.json(source of truth) and extended all translations (en/cs/de/sk) with the newoptions/reauth/unknown/already_configuredkeys. Also fixed a pre-existingcs.jsonkey typo (cal_events_count→cal_events_number).Testing
python -m py_compilepasses on all modules.pyflakesis clean (no unused imports / undefined names).config_entry=kwarg,runtime_data,ConfigFlowResult,async_update_reload_and_abort,async_get_options_flow).Follow-up fixes (7791fb8)
nameproperty is renamed toboard_name:DataUpdateCoordinator.__init__assignsself.name, so the read-only property raisedAttributeErrorand no departure board could be set up.IndexErroron every poll.hacs.jsonraised from 2023.8 to 2024.11 (runtime_data, coordinatorconfig_entry, options flowconfig_entry).v3.0.0), buildspid_departures.zipwith the same layout as previous releases and attaches it, so it no longer has to be uploaded by hand. HACS installs from this zip.Tested in Home Assistant 2026.2.3
A test suite (kept outside the repo) loads the integration with
pytest-homeassistant-custom-componentand a mocked Golemio API. The original commit fails setup withAttributeError: property 'name' ... has no setter; with the fixes all 10 tests pass, with no deprecation warnings: setup and entity attributes, fewer departures than configured, no departures, a failed poll and recovery, lowering the number of departures in options, unique ID migration (single and duplicate entries), reauth on an invalid key, reauth with a new key, and a duplicate stop being rejected.hassfest passes.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Ww8phBs758zj4tCrato36c
Generated by Claude Code
Generated by Claude Code