Skip to content

refactor(coordinator): _on_data hook — collapse 4 _async_update_data overrides - #13

Merged
mrebbert merged 1 commit into
mainfrom
feature/coordinator-on-data-hook
Aug 12, 2026
Merged

refactor(coordinator): _on_data hook — collapse 4 _async_update_data overrides#13
mrebbert merged 1 commit into
mainfrom
feature/coordinator-on-data-hook

Conversation

@mrebbert

Copy link
Copy Markdown
Owner

Summary

Third candidate from the post-0.1.53 refactor audit. Live/Price/Optimization/Notifications each duplicated the same 5-line skeleton:

```python
async def _async_update_data(self) -> T:
data = await super()._async_update_data()
self._side_effect(data)
return data
```

Base coordinator now calls `await self._on_data(data)` after every successful fetch (default is a no-op). Each subclass keeps its existing side-effect method (EMS repair, negative-price bus events, decision events, notification persist + Store) and wires it via a 2-line `_on_data` override.

Net −3 lines but the real win is uniformity: one documented extension point for "post-fetch side effects" instead of four copies of the same wrapper template.

Test plan

  • Full suite green (`.venv/bin/pytest -q` → 226 passed).
  • mypy + ruff clean.
  • Live-deployed on homie; integration loads clean, `sensor.1k5_aktueller_strompreis` refreshes (price coord fires bus events on the new hook), no coordinator errors in the HA error log.

Notes

  • No behavioural change: same fetch pipeline, same side effects fire in the same order, same errors surface as `UpdateFailed` via the base try/except.
  • No tests reference the removed `_async_update_data` overrides directly — tests exercise the public bus events / repair issues, which still fire.
  • Independent of refactor: _safe_fetch helper + price-sensor MRO cleanup #12 (touches coordinator.py only; no overlap).

…te_data overrides

Live/Price/Optimization/Notifications each duplicated the same 5-line
skeleton: `data = await super()._async_update_data(); self._side_effect(data); return data`.

Base coordinator now calls `await self._on_data(data)` after every
successful fetch (default hook is a no-op). Each subclass keeps the
same side-effect method (EMS repair, negative-price bus events,
decision events, notification persist) and wires it via a 2-line
`_on_data` override — the boilerplate goes away.

No behavioural change: same fetch pipeline, same side effects fire in
the same order, same errors surface as UpdateFailed via the base
try/except. Suite green (226); live-verified on homie — integration
loads clean, live + price coordinators refresh, no coordinator errors
in the HA log.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@mrebbert
mrebbert merged commit ad3a53e into main Aug 12, 2026
8 checks passed
@mrebbert
mrebbert deleted the feature/coordinator-on-data-hook branch August 12, 2026 05:06
mrebbert pushed a commit that referenced this pull request Aug 12, 2026
Three PRs (#12/#13/#14) landed post-#11 with no user-visible change —
document them under `[Unreleased] > Changed` so the eventual release
captures them alongside the co2_saved_kg addition.

Per feedback-release-notes-scope memory: refactor mentions stay in
CHANGELOG only; release-notes/v0.1.53.md (when created at release
time) stays user-facing.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

1 participant