From 9c0d3609ab8f3f1ccdf6ffd141ec87688f60d407 Mon Sep 17 00:00:00 2001 From: Klaas Schoute Date: Mon, 7 Sep 2026 12:01:54 +0200 Subject: [PATCH] Make EnergyZero electricity sensor semantics interval-neutral (#181492) --- homeassistant/components/energyzero/sensor.py | 13 +++---------- .../components/energyzero/strings.json | 8 +++++++- .../energyzero/snapshots/test_sensor.ambr | 19 +++++++++---------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/energyzero/sensor.py b/homeassistant/components/energyzero/sensor.py index 9db9d78c9bbe..1d65a4340656 100644 --- a/homeassistant/components/energyzero/sensor.py +++ b/homeassistant/components/energyzero/sensor.py @@ -12,13 +12,7 @@ from homeassistant.components.sensor import ( SensorEntityDescription, SensorStateClass, ) -from homeassistant.const import ( - CURRENCY_EURO, - PERCENTAGE, - UnitOfEnergy, - UnitOfTime, - UnitOfVolume, -) +from homeassistant.const import CURRENCY_EURO, PERCENTAGE, UnitOfEnergy, UnitOfVolume from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback @@ -60,7 +54,7 @@ SENSORS: tuple[EnergyZeroSensorEntityDescription, ...] = ( ), EnergyZeroSensorEntityDescription( key="current_hour_price", - translation_key="current_hour_price", + translation_key="current_price", service_type="today_energy", state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=f"{CURRENCY_EURO}/{UnitOfEnergy.KILO_WATT_HOUR}", @@ -69,7 +63,7 @@ SENSORS: tuple[EnergyZeroSensorEntityDescription, ...] = ( ), EnergyZeroSensorEntityDescription( key="next_hour_price", - translation_key="next_hour_price", + translation_key="next_price", service_type="today_energy", native_unit_of_measurement=f"{CURRENCY_EURO}/{UnitOfEnergy.KILO_WATT_HOUR}", suggested_display_precision=3, @@ -128,7 +122,6 @@ SENSORS: tuple[EnergyZeroSensorEntityDescription, ...] = ( key="hours_priced_equal_or_lower", translation_key="hours_priced_equal_or_lower", service_type="today_energy", - native_unit_of_measurement=UnitOfTime.HOURS, value_fn=lambda data: data.energy_today.time_ranges_priced_equal_or_lower, ), ) diff --git a/homeassistant/components/energyzero/strings.json b/homeassistant/components/energyzero/strings.json index 6731ac588204..8232cc62e01d 100644 --- a/homeassistant/components/energyzero/strings.json +++ b/homeassistant/components/energyzero/strings.json @@ -17,11 +17,14 @@ "current_hour_price": { "name": "Current hour" }, + "current_price": { + "name": "Current price" + }, "highest_price_time": { "name": "Time of highest price - today" }, "hours_priced_equal_or_lower": { - "name": "Hours priced equal or lower than current - today" + "name": "Periods priced equal or lower" }, "lowest_price_time": { "name": "Time of lowest price - today" @@ -35,6 +38,9 @@ "next_hour_price": { "name": "Next hour" }, + "next_price": { + "name": "Next price" + }, "percentage_of_max": { "name": "Current percentage of highest price - today" } diff --git a/tests/components/energyzero/snapshots/test_sensor.ambr b/tests/components/energyzero/snapshots/test_sensor.ambr index cf33cc9dac12..9b5389ed5437 100644 --- a/tests/components/energyzero/snapshots/test_sensor.ambr +++ b/tests/components/energyzero/snapshots/test_sensor.ambr @@ -86,12 +86,12 @@ }), 'original_device_class': None, 'original_icon': None, - 'original_name': 'Current hour', + 'original_name': 'Current price', 'platform': 'energyzero', 'previous_unique_id': None, 'suggested_object_id': 'energyzero_today_energy_current_hour_price', 'supported_features': 0, - 'translation_key': 'current_hour_price', + 'translation_key': 'current_price', 'unique_id': '12345_today_energy_current_hour_price', 'unit_of_measurement': '€/kWh', }) @@ -100,7 +100,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ : 'Data provided by EnergyZero', - : 'Energy market price Current hour', + : 'Energy market price Current price', : , : '€/kWh', }), @@ -191,22 +191,21 @@ }), 'original_device_class': None, 'original_icon': None, - 'original_name': 'Hours priced equal or lower than current - today', + 'original_name': 'Periods priced equal or lower', 'platform': 'energyzero', 'previous_unique_id': None, 'suggested_object_id': 'energyzero_today_energy_hours_priced_equal_or_lower', 'supported_features': 0, 'translation_key': 'hours_priced_equal_or_lower', 'unique_id': '12345_today_energy_hours_priced_equal_or_lower', - 'unit_of_measurement': , + 'unit_of_measurement': None, }) # --- # name: test_sensor[sensor.energyzero_today_energy_hours_priced_equal_or_lower-state] StateSnapshot({ 'attributes': ReadOnlyDict({ : 'Data provided by EnergyZero', - : 'Energy market price Hours priced equal or lower than current - today', - : , + : 'Energy market price Periods priced equal or lower', }), 'context': , 'entity_id': 'sensor.energyzero_today_energy_hours_priced_equal_or_lower', @@ -408,12 +407,12 @@ }), 'original_device_class': None, 'original_icon': None, - 'original_name': 'Next hour', + 'original_name': 'Next price', 'platform': 'energyzero', 'previous_unique_id': None, 'suggested_object_id': 'energyzero_today_energy_next_hour_price', 'supported_features': 0, - 'translation_key': 'next_hour_price', + 'translation_key': 'next_price', 'unique_id': '12345_today_energy_next_hour_price', 'unit_of_measurement': '€/kWh', }) @@ -422,7 +421,7 @@ StateSnapshot({ 'attributes': ReadOnlyDict({ : 'Data provided by EnergyZero', - : 'Energy market price Next hour', + : 'Energy market price Next price', : '€/kWh', }), 'context': ,