chore: retro-review PR #85 — refactor(integration): typed runtime data via PriceHawkData (Phase 7 PR-1)#117
Closed
Artic0din wants to merge 1 commit into
Closed
Conversation
…PR-1) Retire ``hass.data[DOMAIN][entry_id]`` for coordinator storage. Introduce ``custom_components/pricehawk/data.py`` with ``PriceHawkData`` dataclass and ``PriceHawkConfigEntry = ConfigEntry[PriceHawkData]`` type alias. The coordinator now lives on ``entry.runtime_data``. Bundled architectural fixes surfaced by the migration: * ``async_unload_entry`` reordered: ``async_unload_platforms`` runs FIRST. On failure, coordinator + runtime_data are left intact so HA can retry. Previously the coordinator was torn down before checking whether platform-unload succeeded. * Multi-entry service deregistration is now sourced from ``hass.config_entries.async_entries(DOMAIN)`` with explicit filter of the unloading entry. The previous sentinel (``if not hass.data.get(DOMAIN)``) became unreachable garbage after ``hass.data[DOMAIN]`` was removed — production-breaking for any user with two PriceHawk entries. * Service handlers (``analyze_csv``, ``backfill_history``, ``rank_alternatives``) now re-resolve the coordinator via ``_resolve_coordinator()`` on every invocation, instead of closing over the setup-scope ``coordinator`` local. Pre-existing latent bug: ``OptionsFlowWithReload`` (HA 2026.3+) replaces the entry's coordinator on options-save reload, but a closure-captured handler kept pointing at the dead instance. Now version-safe across reloads. * ``sensor.py`` uses ``assert data is not None`` to narrow ``Optional[PriceHawkData]`` for mypy and loud-fail any test fixture that violates the platform-setup lifecycle. No user-facing change. Foundation for Phase 8 Silver-compliance handlers (reauth, reconfigure, diagnostics) which all consume ``entry.runtime_data``. 7 regression tests added in ``tests/test_runtime_data.py``: * ``test_setup_writes_runtime_data`` * ``test_unload_runs_platform_unload_first`` * ``test_unload_does_not_touch_hass_data`` * ``test_multi_entry_service_lifecycle`` * ``test_options_flow_reload_cycle`` * ``test_service_handlers_resolve_fresh_coordinator`` * ``test_no_legacy_hass_data_reads`` (static grep against legacy patterns) Test suite: 808 → 815 passed. Decisions logged: D-P7-1 (typed-entry alias), D-P7-2 (handler re-resolution), D-P7-3 (unload reorder), D-P7-4 (multi-entry sentinel). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Owner
Author
|
@claude review |
|
Claude encountered an error after 7m 38s —— View job I'll analyze this and get back to you. |
Owner
Author
|
Retro-review complete. Findings (if any) tracked in fix/retro-review-batch (#143) or noted in .planning/retro-review-findings.md. Closing synthetic PR + cleaning branches. |
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.

Synthetic retro-review of merged PR #85. Diff = original
7a504c2..6984c4b(same as original PR). Do NOT merge; close after @claude review posts.