feat(home-assistant): split HSEM into 7 per-subsystem devices - #910
Draft
woopstar wants to merge 1 commit into
Draft
feat(home-assistant): split HSEM into 7 per-subsystem devices#910woopstar wants to merge 1 commit into
woopstar wants to merge 1 commit into
Conversation
Splits the single HSEM device into Controller, Battery & Energy, Hourly Consumption Profile, Financial, Forecast, EV Primary, and EV Secondary devices, so each subsystem can be scoped independently in dashboards, automations, and Areas instead of sharing one ~220-entity device page. - Add devices.py (HSEMDevice enum + get_device_info dispatcher) and wire every entity class's device_info to its target device via a new _hsem_device attribute on HSEMEntity (fixed per-class or resolved per-instance for EV primary/secondary and OCPP charger_index pairs). - Drop redundant "Second"/"2" name markers from EV/OCPP entity names (utils/sensornames/ev.py, ocpp.py, translations/en.json) now that the device name disambiguates them. - Add a one-time entity-registry migration (device_migration.py) that reassigns device_id for pre-existing entities, gated by a migration-version flag on the config entry so it runs exactly once. unique_id is never touched. - Update docs/sensors-reference.md, docs/home.md, and AGENTS.md for the new topology. - Add tests/test_device_split.py (per-entity device_info assertions, unique_id classification, migration idempotency/rename behavior). Fixes #875 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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
Splits the single HSEM Home Assistant device into 7 per-subsystem devices: Controller, Battery & Energy, Hourly Consumption Profile, Financial, Forecast, EV Primary, and EV Secondary. Previously every entity (~220+, including the 168 dynamically-created per-hour-block entities) shared one device page, making it impossible to scope automations/dashboards or Areas around a single subsystem.
What changed
custom_components/hsem/devices.py(new) —HSEMDeviceenum (7 members) andget_device_info(entry_id, device)dispatcher.CONTROLLERkeeps the original(DOMAIN, entry_id)identifier for backward compatibility; every other device gets(DOMAIN, f"{entry_id}_<device>").entity.py—HSEMEntity.device_infonow dispatches via aself._hsem_deviceattribute (defaults toCONTROLLER). Every entity subclass sets it — as a fixed class-level device for single-device entities, or resolved per-instance for entities that come in EV primary/secondary pairs (EV target-SoC number, EV calculated-power/current-limit sensors, OCPP charger sensors keyed bycharger_index, and description-driven switches/times).utils/sensornames/ev.py/ocpp.py+translations/en.json— EV Secondary and OCPP entity names drop the redundant"Second"/"2"marker (e.g."OCPP Charger Status"→"Charger Status", rendered as "EV Secondary Charger Status" via_attr_has_entity_name).unique_idandentity_idgetters are untouched.device_migration.py(new) — one-time entity-registry migration run at the end ofasync_setup_entry.classify_entity_device(unique_id)offline-classifies each pre-existing registry entry from its frozenunique_id(mirroring the live_hsem_deviceassignments) and reassignsdevice_idviaentity_registry.async_update_entity. Gated by ahsem_device_migration_versionflag stored inentry.dataso it runs exactly once per config entry;unique_idis never touched. Also implements (and tests) thenew_entity_idrename primitive HA's recorder uses to follow long-term statistics, even though no current entity needs a rename (entity_id getters were kept frozen — only names and device attachment changed).docs/sensors-reference.md(new "Devices" section with the full mapping table),docs/home.md(Devices section + upgrade note),AGENTS.md(Home Assistant Compliance → Device Topology subsection).Device → entity mapping
charger_index=1charger_index=2Tests
tests/test_device_split.py(new):devices.pyDeviceInfo construction, per-entitydevice_infodispatch (one test per device including dynamic dispatch cases),classify_entity_deviceunique_id classification (parametrized across every entity family), andasync_migrate_devices(device reassignment, already-correct-device no-op, second-run no-op, entity_id rename primitive, unique_id-never-touched guard).tests/custom_sensors/test_ocpp_per_ev.pyupdated for the newget_ocpp_charger_power_sensor_name()signature/output.Test & lint results
Breaking change
device_idneed to be re-pointed to the new devices.unique_ids and entity history/long-term statistics are preserved automatically — the migration never touchesunique_id, and noentity_idactually changes in this PR (only display names and device attachment).Known limitations / out of scope
Fixes #875