Skip to content

Modernize integration to current Home Assistant standards - #45

Open
dvejsada wants to merge 1 commit into
masterfrom
claude/integration-modernization-overview-9na1xc
Open

Modernize integration to current Home Assistant standards#45
dvejsada wants to merge 1 commit 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.
  • FlowResultConfigFlowResult.
  • 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_countcal_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).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Ww8phBs758zj4tCrato36c


Generated by Claude Code

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
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