Repository navigation
Standardize power meter EnergySensor name and entity ID across HA versions - #1112
Open
Moustachauve wants to merge 6 commits into
Open
Moustachauve wants to merge 6 commits into
Moustachauve wants to merge 6 commits into
Conversation
EnergySensor previously subclassed Home Assistant Core's private IntegrationSensor class directly to estimate cumulative energy from device power readings. Because IntegrationSensor is an internal helper entity rather than a public base class, upstream constructor changes in Home Assistant 2026.2 and 2026.11 repeatedly broke Hilo setups and required fragile version-checking branches, entity registry workarounds to resolve the source power entity_id, and state machine listeners. Have EnergySensor inherit directly from HiloEntity and RestoreSensor instead, computing the Left-Riemann sum in-process whenever the underlying HiloDevice updates (via SignalR or coordinator polling) as well as on a 5-minute fallback timer for constant-power periods. Accumulating directly from the in-memory device power attribute removes all coupling to homeassistant.components.integration, preserves existing entity unique_ids and restored states (including seamless fallback for states persisted by IntegrationSensor), and retains full Decimal precision across intervals while rounding native_value to 2 decimal places.
tests/test_sensor.py previously constructed mock Hilo and HiloDevice instances manually in each test and asserted individual entity metadata properties in Python code. Use setup_with_selected_platforms with Platform.SENSOR and Syrupy snapshots (snapshot_platform) instead, matching the testing pattern used across the switch and light platform tests while exercising the full sensor platform setup and retaining 100% coverage of EnergySensor.
Home Assistant 2026.3+ (Python 3.14) prepends the device name to original_name and friendly_name on entities whose name does not already start with the device name (such as Gateway sensors), causing full- platform snapshots to diverge from Home Assistant 2026.2 (Python 3.13). Additionally, leaving invalid power values on the shared Smart Plug device at test teardown caused PowerSensor.state to raise during the Python 3.13 teardown coordinator refresh. Scope test_energy_sensor_entities snapshots to the EnergySensor entities and restore valid device power before teardown so the test suite passes on both Python 3.13 and Python 3.14.
…sions
Previously, EnergySensor set _attr_name to the internal constant
"hilo_energy_total" on Meter devices so older Home Assistant versions
(<= 2026.2, Python 3.13) would derive the entity ID
sensor.hilo_energy_total required by UtilityManager,
HiloCostTotalSensor, and check_tarif. Starting in Home Assistant
2026.3+ (Python 3.14), the entity registry always prepends the device
name when _attr_name does not already begin with the device name,
causing the meter energy sensor to be created with a device-prefixed
entity ID (such as sensor.smartenergymeter_hilo_energy_total) and
divergent friendly_name values across Python 3.13 and 3.14. In
addition, the migration in __init__.py ran after platform setup and
only checked the hardcoded "sensor.meter00_hilo_energy_total" entity
ID, leaving meters with any other device name unmigrated.
Use f"{device.name} Hilo Energy" as the entity name for all
EnergySensor instances so the display name starts with the device name
and remains identical across Home Assistant versions, while setting
self.entity_id = f"sensor.{HILO_ENERGY_TOTAL}" on Meter devices so new
installs register sensor.hilo_energy_total directly during platform
setup. Expand energy_entity_renames in async_setup_entry to
dynamically include all Meter devices and run it before forwarding
platform setups so existing installations on Home Assistant 2026.3+
migrate to sensor.hilo_energy_total before UtilityManager and
check_tarif run.
Moustachauve
force-pushed
the
fix/power-meter-energy-sensor-name
branch
from
October 30, 2026 01:49
3cf6eaa to
9e51433
Compare
Moustachauve
marked this pull request as ready for review
October 30, 2026 01:51
Commit 8803d86 (PR dvd-dev#1001) added "Disconnected": false to the Thermostat 1 fixture entry in tests/fixtures/all_devices.json so the baseboard thermostat starts online during test setup. As a result, sensor.thermostat_1_hilo_energy initializes to "0.00" rather than "unavailable".
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.
Note
This PR is stacked on top of #1107.
Previously,
EnergySensorset_attr_nameto the internal constant"hilo_energy_total"onMeterdevices so older Home Assistant versions (<= 2026.2, Python 3.13) would derive the entity IDsensor.hilo_energy_totalrequired byUtilityManager,HiloCostTotalSensor, andcheck_tarif. Starting in Home Assistant 2026.3+ (Python 3.14), the entity registry always prepends the device name when_attr_namedoes not already begin with the device name, causing the meter energy sensor to be created with a device-prefixed entity ID (such assensor.smartenergymeter_hilo_energy_total) and divergentfriendly_namevalues across Python 3.13 and 3.14. In addition, the migration in__init__.pyran after platform setup and only checked the hardcoded"sensor.meter00_hilo_energy_total"entity ID, leaving meters with any other device name unmigrated.Use
f"{device.name} Hilo Energy"as the entity name for allEnergySensorinstances so the display name starts with the device name and remains identical across Home Assistant versions, while settingself.entity_id = f"sensor.{HILO_ENERGY_TOTAL}"onMeterdevices so new installs registersensor.hilo_energy_totaldirectly during platform setup. Expandenergy_entity_renamesinasync_setup_entryto dynamically include allMeterdevices and run it before forwarding platform setups so existing installations on Home Assistant 2026.3+ migrate tosensor.hilo_energy_totalbeforeUtilityManagerandcheck_tarifrun.