Skip to content

refactor(ev): pass ev object directly to EV entity ctors - #14

Merged
mrebbert merged 1 commit into
mainfrom
feature/ev-entity-ctor-cleanup
Aug 12, 2026
Merged

refactor(ev): pass ev object directly to EV entity ctors#14
mrebbert merged 1 commit into
mainfrom
feature/ev-entity-ctor-cleanup

Conversation

@mrebbert

Copy link
Copy Markdown
Owner

Summary

Fourth (and last) candidate from the post-0.1.53 refactor audit.

Every EV setup site unpacked `ev.id()`, `ev.manufacturer()`, `ev.model()` into three positional args, then passed them to the constructor which reassembled them into a `DeviceInfo`. Two subclasses (`Select` / `Time`) additionally accepted the whole `ev_charger` and stored it on `self._ev_charger` — a field that was never read (all reads route through the parent's `_get_ev()`).

  • `OneKomma5EVEntity` now takes the `ev` object directly and reads `.id()` / `.manufacturer()` / `.model()` internally.
  • `Sensor` / `Number` / `Select` / `Time` subclasses drop three positional args each.
  • The two dead `self._ev_charger` fields are gone.

Net −86 lines across 6 files (mostly disappearing setup boilerplate).

Stability contract

Unique-id and `stable_object_id` formulas are unchanged (`f"{system_id}{ev.id()}{suffix}"`) — statistics, automations, and existing `entity_id`s all survive.

Test plan

  • Full suite green (`.venv/bin/pytest -q` → 226 passed).
  • mypy + ruff clean.
  • Live-deployed on homie; all four EV entity platforms still register with correct state:
    • `select.volkswagen_id_4_lademodus` → `quick_charge`
    • `time.volkswagen_id_4_abfahrtzeit` → `06:30:00`
    • `number.volkswagen_id_4_ziel_akkustand` → `80.0`
    • `sensor.volkswagen_id_4_ziel_akkustand` → `80.0`, `sensor.garage_elektrofahrzeug_batteriekapazitat` → `77.0`, and more.

Independence

Touches EV entity plumbing only. No overlap with #12 (`init.py` + price-sensor MRO) or #13 (`coordinator.py`).

Every EV setup site unpacked ev.id(), ev.manufacturer(), ev.model()
into three positional args, then passed them to the constructor which
reassembled them into a DeviceInfo. Two subclasses (Select / Time)
additionally accepted the whole ev_charger and stored it on
self._ev_charger — a field that was never read (all reads route
through the parent's _get_ev()).

OneKomma5EVEntity now takes the ev object directly and reads
.id() / .manufacturer() / .model() internally. The four subclasses
(Sensor / Number / Select / Time) drop three positional args each,
and the two dead self._ev_charger fields are gone.

Unique-id and stable_object_id formulas are unchanged
(f"{system_id}_{ev.id()}_{suffix}") — statistics, automations, and
existing entity_ids all survive.

Suite green (226); live-verified on homie — all four EV entity
platforms (select.<>_lademodus, time.<>_abfahrtzeit,
number.<>_ziel_akkustand, sensor.<>_ziel_akkustand + friends) still
register with correct state.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@mrebbert
mrebbert merged commit ca1bb9b into main Aug 12, 2026
8 checks passed
@mrebbert
mrebbert deleted the feature/ev-entity-ctor-cleanup branch August 12, 2026 05:08
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