Modernize integration to current Home Assistant standards - #45
Open
dvejsada wants to merge 1 commit into
Open
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
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).🤖 Generated with Claude Code
https://claude.ai/code/session_01Ww8phBs758zj4tCrato36c
Generated by Claude Code