Skip to content

Modernize integration to current Home Assistant standards - #45

Merged
dvejsada merged 4 commits into
masterfrom
claude/integration-modernization-overview-9na1xc
Oct 3, 2026
Merged

dvejsada merged 4 commits into
masterfrom
claude/integration-modernization-overview-9na1xc

Conversation

@dvejsada

@dvejsada dvejsada commented Jul 8, 2026 •

Copy link
Copy Markdown
Owner

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 (new coordinator.py)

Replaces the hand-rolled hub + register_callback/publish_updates pattern. Every entity is now a CoordinatorEntity, 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_data

The coordinator is stored on entry.runtime_data with a typed PIDConfigEntry instead of hass.data[DOMAIN], removing ~all the # type: ignore[Any] dict lookups across the platforms.

A3 — Shared aiohttp session + manifest

  • dep_board_api now uses Home Assistant's shared async_get_clientsession instead of opening a brand-new ClientSession on every request; client/timeout errors are wrapped as CannotConnect.
  • manifest.json: dropped aiohttp/attrs from requirements (both ship with core), added integration_type: "device", bumped version.

A4 — Config-flow correctness

  • VERSION = 1 (was the invalid float 0.1).
  • Removed the deprecated and incorrect CONNECTION_CLASS.
  • FlowResult → ConfigFlowResult.
  • Sets a unique_id per stop and aborts on duplicates.
  • The unknown-error branch now uses a real translation key instead of a raw string.

A5 — Options + reauth flows

  • Options flow for the tunables (departures, calendar events, walking offset). Reads options with a fallback to data, so existing entries keep working with no migration; the entry reloads on change.
  • Reauth flow: the coordinator raises ConfigEntryAuthFailed on 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 hardcoded ZoneInfo("Europe/Prague").
  • Infotext binary-sensor icon now derives from is_on (was reading the wrong attribute).
  • Typed system_health_info.
  • Added strings.json (source of truth) and extended all translations (en/cs/de/sk) with the new options/reauth/unknown/already_configured keys. Also fixed a pre-existing cs.json key typo (cal_events_count → cal_events_number).

Testing

  • python -m py_compile passes on all modules.
  • pyflakes is clean (no unused imports / undefined names).
  • Home Assistant requires Python 3.13, which isn't available in this environment, so a full runtime/hassfest run wasn't possible locally — hassfest runs in CI. HA API usage was reviewed against current APIs (coordinator config_entry= kwarg, runtime_data, ConfigFlowResult, async_update_reload_and_abort, async_get_options_flow).

Follow-up fixes (7791fb8)

  • Setup crash fixed. The coordinator's name property is renamed to board_name: DataUpdateCoordinator.__init__ assigns self.name, so the read-only property raised AttributeError and no departure board could be set up.
  • Fewer departures than configured (e.g. at night): departure sensors and the calendar are now unavailable instead of raising IndexError on every poll.
  • Options: departure entities left over after lowering the number of departures are removed.
  • Unique IDs for existing entries: entries created before this PR get the stop ID as unique ID, so adding the same stop again is detected. Stops that were already added twice are left as they are.
  • Minimum Home Assistant version in hacs.json raised from 2023.8 to 2024.11 (runtime_data, coordinator config_entry, options flow config_entry).
  • Readme: minimum version, and a link to the PID Departures Card repository.
  • Release workflow: publishing a release checks that the tag matches the manifest version (v3.0.0), builds pid_departures.zip with the same layout as previous releases and attaches it, so it no longer has to be uploaded by hand. HACS installs from this zip.
  • Readme rewritten for version 3: setup fields, options, re-authentication, entities and attributes, upgrading, troubleshooting.

Tested in Home Assistant 2026.2.3

A test suite (kept outside the repo) loads the integration with pytest-homeassistant-custom-component and a mocked Golemio API. The original commit fails setup with AttributeError: 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

claude added 4 commits July 8, 2026 17:24
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
@dvejsada
dvejsada merged commit a69f58c into master Oct 3, 2026
2 checks passed
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.

2 participants