Fix EnergyZero market price regression (#181230)

This commit is contained in:
Klaas Schoute
2026-09-18 10:09:31 +00:00
committed by Franck Nijhof
parent 798ae4c83a
commit 220d255960
5 changed files with 78 additions and 23 deletions
@@ -10,6 +10,7 @@ from energyzero import (
EnergyZeroConnectionError,
EnergyZeroNoDataError,
Interval,
PriceType,
)
from homeassistant.config_entries import ConfigEntry
@@ -61,12 +62,14 @@ class EnergyZeroDataUpdateCoordinator(DataUpdateCoordinator[EnergyZeroData]):
start_date=today,
end_date=today,
interval=Interval.HOUR,
price_type=PriceType.MARKET_WITH_VAT,
local_tz=local_tz,
)
try:
gas_today = await self.energyzero.get_gas_prices(
start_date=today,
end_date=today,
price_type=PriceType.MARKET_WITH_VAT,
local_tz=local_tz,
)
except EnergyZeroNoDataError:
@@ -79,6 +82,7 @@ class EnergyZeroDataUpdateCoordinator(DataUpdateCoordinator[EnergyZeroData]):
start_date=tomorrow,
end_date=tomorrow,
interval=Interval.HOUR,
price_type=PriceType.MARKET_WITH_VAT,
local_tz=local_tz,
)
except EnergyZeroNoDataError:
@@ -2,15 +2,15 @@
# name: test_diagnostics_no_gas_today
dict({
'energy': dict({
'average_price': 0.25694034895833334,
'current_hour_price': 0.28275885,
'average_price': 0.14609224895833334,
'current_hour_price': 0.17191075,
'highest_price_time': '2026-04-10T18:00:00+00:00',
'hours_priced_equal_or_lower': 20,
'lowest_price_time': '2026-04-11T06:00:00+00:00',
'max_price': 0.399000525,
'min_price': 0.188351625,
'next_hour_price': 0.2629693,
'percentage_of_max': 70.87,
'max_price': 0.288152425,
'min_price': 0.077503525,
'next_hour_price': 0.1521212,
'percentage_of_max': 59.66,
}),
'entry': dict({
'title': 'energy',
@@ -24,15 +24,15 @@
# name: test_entry_diagnostics
dict({
'energy': dict({
'average_price': 0.25694034895833334,
'current_hour_price': 0.28275885,
'average_price': 0.14609224895833334,
'current_hour_price': 0.17191075,
'highest_price_time': '2026-04-10T18:00:00+00:00',
'hours_priced_equal_or_lower': 20,
'lowest_price_time': '2026-04-11T06:00:00+00:00',
'max_price': 0.399000525,
'min_price': 0.188351625,
'next_hour_price': 0.2629693,
'percentage_of_max': 70.87,
'max_price': 0.288152425,
'min_price': 0.077503525,
'next_hour_price': 0.1521212,
'percentage_of_max': 59.66,
}),
'entry': dict({
'title': 'energy',
@@ -51,7 +51,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '0.256940348958333',
'state': '0.141981021875',
})
# ---
# name: test_sensor[sensor.energyzero_today_energy_current_hour_price-entry]
@@ -109,7 +109,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '0.28275885',
'state': '0.17191075',
})
# ---
# name: test_sensor[sensor.energyzero_today_energy_highest_price_time-entry]
@@ -265,7 +265,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '2026-04-11T06:00:00+00:00',
'state': '2026-04-10T01:00:00+00:00',
})
# ---
# name: test_sensor[sensor.energyzero_today_energy_max_price-entry]
@@ -320,7 +320,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '0.399000525',
'state': '0.288152425',
})
# ---
# name: test_sensor[sensor.energyzero_today_energy_min_price-entry]
@@ -375,7 +375,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '0.188351625',
'state': '0.08713815',
})
# ---
# name: test_sensor[sensor.energyzero_today_energy_next_hour_price-entry]
@@ -430,7 +430,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '0.2629693',
'state': '0.1521212',
})
# ---
# name: test_sensor[sensor.energyzero_today_energy_percentage_of_max-entry]
@@ -482,7 +482,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '70.87',
'state': '59.66',
})
# ---
# name: test_sensor[sensor.energyzero_today_gas_current_hour_price-entry]
@@ -540,7 +540,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
'state': '0.5468407201224',
})
# ---
# name: test_sensor[sensor.energyzero_today_gas_next_hour_price-entry]
@@ -595,6 +595,6 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
'state': '0.5468407201224',
})
# ---
+44 -2
View File
@@ -1,8 +1,10 @@
"""Tests for the EnergyZero integration."""
from unittest.mock import MagicMock, patch
from datetime import date
from unittest.mock import MagicMock, call, patch
from zoneinfo import ZoneInfo
from energyzero import EnergyZeroConnectionError
from energyzero import EnergyZeroConnectionError, Interval, PriceType
import pytest
from homeassistant.config_entries import ConfigEntryState
@@ -11,6 +13,46 @@ from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
@pytest.mark.freeze_time("2026-04-10 20:32:59")
async def test_coordinator_requests_market_prices_with_vat(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_energyzero: MagicMock,
) -> None:
"""Test the coordinator requests the backwards-compatible price stream."""
mock_config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
local_tz = ZoneInfo(hass.config.time_zone)
today = date(2026, 4, 10)
tomorrow = date(2026, 4, 11)
mock_energyzero.get_electricity_prices.assert_has_awaits(
[
call(
start_date=today,
end_date=today,
interval=Interval.HOUR,
price_type=PriceType.MARKET_WITH_VAT,
local_tz=local_tz,
),
call(
start_date=tomorrow,
end_date=tomorrow,
interval=Interval.HOUR,
price_type=PriceType.MARKET_WITH_VAT,
local_tz=local_tz,
),
]
)
mock_energyzero.get_gas_prices.assert_awaited_once_with(
start_date=today,
end_date=today,
price_type=PriceType.MARKET_WITH_VAT,
local_tz=local_tz,
)
@pytest.mark.usefixtures("mock_energyzero")
async def test_load_unload_config_entry(
hass: HomeAssistant, mock_config_entry: MockConfigEntry
@@ -29,9 +29,18 @@ async def test_sensor(
snapshot: SnapshotAssertion,
) -> None:
"""Test the EnergyZero - Energy sensors."""
await hass.config.async_set_time_zone("Europe/Amsterdam")
with patch("homeassistant.components.energyzero.PLATFORMS", ["sensor"]):
await setup_integration(hass, mock_config_entry)
gas_state = hass.states.get("sensor.energyzero_today_gas_current_hour_price")
assert gas_state
assert gas_state.state == "0.5468407201224"
energy_state = hass.states.get("sensor.energyzero_today_energy_current_hour_price")
assert energy_state
assert energy_state.state == "0.17191075"
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)