Pass config entry to Mill coordinator (#149942)

This commit is contained in:
Joost Lekkerkerker
2025-08-04 13:20:30 +02:00
committed by GitHub
parent 39b651e075
commit 3d27d501b1
3 changed files with 17 additions and 5 deletions

View File

@@ -43,6 +43,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
historic_data_coordinator = MillHistoricDataUpdateCoordinator(
hass,
entry,
mill_data_connection=mill_data_connection,
)
historic_data_coordinator.async_add_listener(lambda: None)

View File

@@ -60,6 +60,7 @@ class MillHistoricDataUpdateCoordinator(DataUpdateCoordinator):
def __init__(
self,
hass: HomeAssistant,
config_entry: ConfigEntry,
*,
mill_data_connection: Mill,
) -> None:
@@ -70,6 +71,7 @@ class MillHistoricDataUpdateCoordinator(DataUpdateCoordinator):
hass,
_LOGGER,
name="MillHistoricDataUpdateCoordinator",
config_entry=config_entry,
)
async def _async_update_data(self):

View File

@@ -11,12 +11,15 @@ from homeassistant.components.recorder.statistics import statistics_during_perio
from homeassistant.core import HomeAssistant
from homeassistant.util import dt as dt_util
from tests.common import MockConfigEntry
from tests.components.recorder.common import async_wait_recording_done
async def test_mill_historic_data(recorder_mock: Recorder, hass: HomeAssistant) -> None:
"""Test historic data from Mill."""
entry = MockConfigEntry(domain=DOMAIN)
data = {
dt_util.parse_datetime("2024-12-03T00:00:00+01:00"): 2,
dt_util.parse_datetime("2024-12-03T01:00:00+01:00"): 3,
@@ -31,7 +34,7 @@ async def test_mill_historic_data(recorder_mock: Recorder, hass: HomeAssistant)
statistic_id = f"{DOMAIN}:energy_dev_id"
coordinator = MillHistoricDataUpdateCoordinator(
hass, mill_data_connection=mill_data_connection
hass, entry, mill_data_connection=mill_data_connection
)
await coordinator._async_update_data()
await async_wait_recording_done(hass)
@@ -96,6 +99,8 @@ async def test_mill_historic_data_no_heater(
) -> None:
"""Test historic data from Mill."""
entry = MockConfigEntry(domain=DOMAIN)
data = {
dt_util.parse_datetime("2024-12-03T00:00:00+01:00"): 2,
dt_util.parse_datetime("2024-12-03T01:00:00+01:00"): 3,
@@ -110,7 +115,7 @@ async def test_mill_historic_data_no_heater(
statistic_id = f"{DOMAIN}:energy_dev_id"
coordinator = MillHistoricDataUpdateCoordinator(
hass, mill_data_connection=mill_data_connection
hass, entry, mill_data_connection=mill_data_connection
)
await coordinator._async_update_data()
await async_wait_recording_done(hass)
@@ -133,6 +138,8 @@ async def test_mill_historic_data_no_data(
) -> None:
"""Test historic data from Mill."""
entry = MockConfigEntry(domain=DOMAIN)
data = {
dt_util.parse_datetime("2024-12-03T00:00:00+01:00"): 2,
dt_util.parse_datetime("2024-12-03T01:00:00+01:00"): 3,
@@ -145,7 +152,7 @@ async def test_mill_historic_data_no_data(
mill_data_connection.fetch_historic_energy_usage = AsyncMock(return_value=data)
coordinator = MillHistoricDataUpdateCoordinator(
hass, mill_data_connection=mill_data_connection
hass, entry, mill_data_connection=mill_data_connection
)
await coordinator._async_update_data()
await async_wait_recording_done(hass)
@@ -168,7 +175,7 @@ async def test_mill_historic_data_no_data(
mill_data_connection.fetch_historic_energy_usage = AsyncMock(return_value=None)
coordinator = MillHistoricDataUpdateCoordinator(
hass, mill_data_connection=mill_data_connection
hass, entry, mill_data_connection=mill_data_connection
)
await coordinator._async_update_data()
await async_wait_recording_done(hass)
@@ -192,6 +199,8 @@ async def test_mill_historic_data_invalid_data(
) -> None:
"""Test historic data from Mill."""
entry = MockConfigEntry(domain=DOMAIN)
data = {
dt_util.parse_datetime("2024-12-03T00:00:00+01:00"): None,
dt_util.parse_datetime("2024-12-03T01:00:00+01:00"): 3,
@@ -206,7 +215,7 @@ async def test_mill_historic_data_invalid_data(
statistic_id = f"{DOMAIN}:energy_dev_id"
coordinator = MillHistoricDataUpdateCoordinator(
hass, mill_data_connection=mill_data_connection
hass, entry, mill_data_connection=mill_data_connection
)
await coordinator._async_update_data()
await async_wait_recording_done(hass)