Skip to content

refactor: _safe_fetch helper + price-sensor MRO cleanup - #12

Merged
mrebbert merged 1 commit into
mainfrom
feature/refactor-sweep-053
Aug 12, 2026
Merged

refactor: _safe_fetch helper + price-sensor MRO cleanup#12
mrebbert merged 1 commit into
mainfrom
feature/refactor-sweep-053

Conversation

@mrebbert

Copy link
Copy Markdown
Owner

Summary

Two-candidate refactor sweep from the post-0.1.53 audit — both preserve behaviour, both fully covered by the existing tests.

  • _safe_fetch(label, fn) in `init.py`: folded the three copies of the setup-time `try SDK call; except → warn + return None` shape into one helper. Applied to `get_details`, `get_subscriptions`, `get_impact_overview`. Net −9 lines; the next setup-time fetch is one line, not five.
  • OneKomma5PriceSensor MRO: added `_DescriptionValueSensor` to the MRO and dropped the byte-equivalent `native_value` override. The custom `extra_state_attributes` (only fires for `current_electricity_price`) stays because the mixin's default returns None. Net −6 lines, and no more "why does this class copy the mixin?" reader stumble.

Test plan

  • Full suite green (`.venv/bin/pytest -q` → 226 passed).
  • mypy + ruff clean.
  • Live-deployed on homie; smoke-tested three sensors that exercise both changes: `sensor.heizungskeller_1k5_tagesersparnis` still carries `co2_saved_kg`, `sensor.1k5_aktueller_strompreis` still has state + full forecast/grid-cost attributes, `sensor.markus_rebbert_dynamic_pulse_price_guarantee` still resolves.

Rejected from the same audit (memory in `~/.claude/projects/-Users-markus-Sources-1komma5-ha/`): base-coordinator `_on_data` hook (bigger blast radius, better as its own PR); EV entity ctor consolidation (blast across 5 modules, defer).

- Extract `_safe_fetch(label, fn)` in __init__.py: fold the three copies
  of `try SDK call; except: warn+None` into one helper. Applied to the
  system-details, subscriptions, and impact-overview fetches.
- Add `_DescriptionValueSensor` to `OneKomma5PriceSensor` MRO and drop
  the byte-equivalent `native_value` override; the custom
  `extra_state_attributes` (only fires for current-price) stays as-is.

Both changes preserve behaviour — full suite green, live-verified on
homie (daily_savings co2_saved_kg, aktueller_strompreis forecast +
attributes, DP price-guarantee sensor).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@mrebbert
mrebbert merged commit 64c25d8 into main Aug 12, 2026
8 checks passed
@mrebbert
mrebbert deleted the feature/refactor-sweep-053 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