diff --git a/homeassistant/components/energyzero/diagnostics.py b/homeassistant/components/energyzero/diagnostics.py index 5e3e402efbf..3b0c05b7368 100644 --- a/homeassistant/components/energyzero/diagnostics.py +++ b/homeassistant/components/energyzero/diagnostics.py @@ -50,6 +50,7 @@ async def async_get_config_entry_diagnostics( "highest_price_time": coordinator.data.energy_today.highest_price_time, "lowest_price_time": coordinator.data.energy_today.lowest_price_time, "percentage_of_max": coordinator.data.energy_today.pct_of_max_price, + "hours_priced_equal_or_lower": coordinator.data.energy_today.hours_priced_equal_or_lower, }, "gas": { "current_hour_price": get_gas_price(coordinator.data, 0), diff --git a/homeassistant/components/energyzero/sensor.py b/homeassistant/components/energyzero/sensor.py index 2d3a8954220..2468e5e68bf 100644 --- a/homeassistant/components/energyzero/sensor.py +++ b/homeassistant/components/energyzero/sensor.py @@ -13,7 +13,13 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CURRENCY_EURO, PERCENTAGE, UnitOfEnergy, UnitOfVolume +from homeassistant.const import ( + CURRENCY_EURO, + PERCENTAGE, + UnitOfEnergy, + UnitOfTime, + UnitOfVolume, +) from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -114,6 +120,14 @@ SENSORS: tuple[EnergyZeroSensorEntityDescription, ...] = ( icon="mdi:percent", value_fn=lambda data: data.energy_today.pct_of_max_price, ), + EnergyZeroSensorEntityDescription( + key="hours_priced_equal_or_lower", + translation_key="hours_priced_equal_or_lower", + service_type="today_energy", + native_unit_of_measurement=UnitOfTime.HOURS, + icon="mdi:clock", + value_fn=lambda data: data.energy_today.hours_priced_equal_or_lower, + ), ) diff --git a/homeassistant/components/energyzero/strings.json b/homeassistant/components/energyzero/strings.json index 93fb264b01d..a27ce236c28 100644 --- a/homeassistant/components/energyzero/strings.json +++ b/homeassistant/components/energyzero/strings.json @@ -37,9 +37,6 @@ }, "hours_priced_equal_or_lower": { "name": "Hours priced equal or lower than current - today" - }, - "hours_priced_equal_or_higher": { - "name": "Hours priced equal or higher than current - today" } } } diff --git a/tests/components/energyzero/snapshots/test_diagnostics.ambr b/tests/components/energyzero/snapshots/test_diagnostics.ambr index 488e01e8d18..90c11ecfc6f 100644 --- a/tests/components/energyzero/snapshots/test_diagnostics.ambr +++ b/tests/components/energyzero/snapshots/test_diagnostics.ambr @@ -5,6 +5,7 @@ 'average_price': 0.37, 'current_hour_price': 0.49, 'highest_price_time': '2022-12-07T16:00:00+00:00', + 'hours_priced_equal_or_lower': 23, 'lowest_price_time': '2022-12-07T02:00:00+00:00', 'max_price': 0.55, 'min_price': 0.26, @@ -26,6 +27,7 @@ 'average_price': 0.37, 'current_hour_price': 0.49, 'highest_price_time': '2022-12-07T16:00:00+00:00', + 'hours_priced_equal_or_lower': 23, 'lowest_price_time': '2022-12-07T02:00:00+00:00', 'max_price': 0.55, 'min_price': 0.26, diff --git a/tests/components/energyzero/snapshots/test_sensor.ambr b/tests/components/energyzero/snapshots/test_sensor.ambr index 619813c52c1..e51aef980d1 100644 --- a/tests/components/energyzero/snapshots/test_sensor.ambr +++ b/tests/components/energyzero/snapshots/test_sensor.ambr @@ -651,6 +651,71 @@ 'via_device_id': None, }) # --- +# name: test_sensor[sensor.energyzero_today_energy_hours_priced_equal_or_lower-today_energy_hours_priced_equal_or_lower-today_energy] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'attribution': 'Data provided by EnergyZero', + 'friendly_name': 'Energy market price Hours priced equal or lower than current - today', + 'icon': 'mdi:clock', + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.energyzero_today_energy_hours_priced_equal_or_lower', + 'last_changed': , + 'last_updated': , + 'state': '23', + }) +# --- +# name: test_sensor[sensor.energyzero_today_energy_hours_priced_equal_or_lower-today_energy_hours_priced_equal_or_lower-today_energy].1 + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.energyzero_today_energy_hours_priced_equal_or_lower', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': 'mdi:clock', + 'original_name': 'Hours priced equal or lower than current - today', + 'platform': 'energyzero', + 'supported_features': 0, + 'translation_key': 'hours_priced_equal_or_lower', + 'unit_of_measurement': , + }) +# --- +# name: test_sensor[sensor.energyzero_today_energy_hours_priced_equal_or_lower-today_energy_hours_priced_equal_or_lower-today_energy].2 + DeviceRegistryEntrySnapshot({ + 'area_id': None, + 'config_entries': , + 'configuration_url': None, + 'connections': set({ + }), + 'disabled_by': None, + 'entry_type': , + 'hw_version': None, + 'id': , + 'is_new': False, + 'manufacturer': 'EnergyZero', + 'model': None, + 'name': 'Energy market price', + 'name_by_user': None, + 'suggested_area': None, + 'sw_version': None, + 'via_device_id': None, + }) +# --- # name: test_sensor[sensor.energyzero_today_energy_max_price-today_energy_max_price-today_energy] StateSnapshot({ 'attributes': ReadOnlyDict({ diff --git a/tests/components/energyzero/test_sensor.py b/tests/components/energyzero/test_sensor.py index 466e754df27..6c7eec9d5d8 100644 --- a/tests/components/energyzero/test_sensor.py +++ b/tests/components/energyzero/test_sensor.py @@ -41,6 +41,11 @@ pytestmark = [pytest.mark.freeze_time("2022-12-07 15:00:00")] "today_energy_highest_price_time", "today_energy", ), + ( + "sensor.energyzero_today_energy_hours_priced_equal_or_lower", + "today_energy_hours_priced_equal_or_lower", + "today_energy", + ), ( "sensor.energyzero_today_gas_current_hour_price", "today_gas_current_hour_price",