mirror of
https://github.com/home-assistant/core.git
synced 2025-08-16 19:11:42 +02:00
Pass config entry to Mill coordinator (#149942)
This commit is contained in:
committed by
GitHub
parent
39b651e075
commit
3d27d501b1
@@ -43,6 +43,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
historic_data_coordinator = MillHistoricDataUpdateCoordinator(
|
historic_data_coordinator = MillHistoricDataUpdateCoordinator(
|
||||||
hass,
|
hass,
|
||||||
|
entry,
|
||||||
mill_data_connection=mill_data_connection,
|
mill_data_connection=mill_data_connection,
|
||||||
)
|
)
|
||||||
historic_data_coordinator.async_add_listener(lambda: None)
|
historic_data_coordinator.async_add_listener(lambda: None)
|
||||||
|
@@ -60,6 +60,7 @@ class MillHistoricDataUpdateCoordinator(DataUpdateCoordinator):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
*,
|
*,
|
||||||
mill_data_connection: Mill,
|
mill_data_connection: Mill,
|
||||||
) -> None:
|
) -> None:
|
||||||
@@ -70,6 +71,7 @@ class MillHistoricDataUpdateCoordinator(DataUpdateCoordinator):
|
|||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
name="MillHistoricDataUpdateCoordinator",
|
name="MillHistoricDataUpdateCoordinator",
|
||||||
|
config_entry=config_entry,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _async_update_data(self):
|
async def _async_update_data(self):
|
||||||
|
@@ -11,12 +11,15 @@ from homeassistant.components.recorder.statistics import statistics_during_perio
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
from tests.components.recorder.common import async_wait_recording_done
|
from tests.components.recorder.common import async_wait_recording_done
|
||||||
|
|
||||||
|
|
||||||
async def test_mill_historic_data(recorder_mock: Recorder, hass: HomeAssistant) -> None:
|
async def test_mill_historic_data(recorder_mock: Recorder, hass: HomeAssistant) -> None:
|
||||||
"""Test historic data from Mill."""
|
"""Test historic data from Mill."""
|
||||||
|
|
||||||
|
entry = MockConfigEntry(domain=DOMAIN)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
dt_util.parse_datetime("2024-12-03T00:00:00+01:00"): 2,
|
dt_util.parse_datetime("2024-12-03T00:00:00+01:00"): 2,
|
||||||
dt_util.parse_datetime("2024-12-03T01:00:00+01:00"): 3,
|
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"
|
statistic_id = f"{DOMAIN}:energy_dev_id"
|
||||||
|
|
||||||
coordinator = MillHistoricDataUpdateCoordinator(
|
coordinator = MillHistoricDataUpdateCoordinator(
|
||||||
hass, mill_data_connection=mill_data_connection
|
hass, entry, mill_data_connection=mill_data_connection
|
||||||
)
|
)
|
||||||
await coordinator._async_update_data()
|
await coordinator._async_update_data()
|
||||||
await async_wait_recording_done(hass)
|
await async_wait_recording_done(hass)
|
||||||
@@ -96,6 +99,8 @@ async def test_mill_historic_data_no_heater(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test historic data from Mill."""
|
"""Test historic data from Mill."""
|
||||||
|
|
||||||
|
entry = MockConfigEntry(domain=DOMAIN)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
dt_util.parse_datetime("2024-12-03T00:00:00+01:00"): 2,
|
dt_util.parse_datetime("2024-12-03T00:00:00+01:00"): 2,
|
||||||
dt_util.parse_datetime("2024-12-03T01:00:00+01:00"): 3,
|
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"
|
statistic_id = f"{DOMAIN}:energy_dev_id"
|
||||||
|
|
||||||
coordinator = MillHistoricDataUpdateCoordinator(
|
coordinator = MillHistoricDataUpdateCoordinator(
|
||||||
hass, mill_data_connection=mill_data_connection
|
hass, entry, mill_data_connection=mill_data_connection
|
||||||
)
|
)
|
||||||
await coordinator._async_update_data()
|
await coordinator._async_update_data()
|
||||||
await async_wait_recording_done(hass)
|
await async_wait_recording_done(hass)
|
||||||
@@ -133,6 +138,8 @@ async def test_mill_historic_data_no_data(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test historic data from Mill."""
|
"""Test historic data from Mill."""
|
||||||
|
|
||||||
|
entry = MockConfigEntry(domain=DOMAIN)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
dt_util.parse_datetime("2024-12-03T00:00:00+01:00"): 2,
|
dt_util.parse_datetime("2024-12-03T00:00:00+01:00"): 2,
|
||||||
dt_util.parse_datetime("2024-12-03T01:00:00+01:00"): 3,
|
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)
|
mill_data_connection.fetch_historic_energy_usage = AsyncMock(return_value=data)
|
||||||
|
|
||||||
coordinator = MillHistoricDataUpdateCoordinator(
|
coordinator = MillHistoricDataUpdateCoordinator(
|
||||||
hass, mill_data_connection=mill_data_connection
|
hass, entry, mill_data_connection=mill_data_connection
|
||||||
)
|
)
|
||||||
await coordinator._async_update_data()
|
await coordinator._async_update_data()
|
||||||
await async_wait_recording_done(hass)
|
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)
|
mill_data_connection.fetch_historic_energy_usage = AsyncMock(return_value=None)
|
||||||
|
|
||||||
coordinator = MillHistoricDataUpdateCoordinator(
|
coordinator = MillHistoricDataUpdateCoordinator(
|
||||||
hass, mill_data_connection=mill_data_connection
|
hass, entry, mill_data_connection=mill_data_connection
|
||||||
)
|
)
|
||||||
await coordinator._async_update_data()
|
await coordinator._async_update_data()
|
||||||
await async_wait_recording_done(hass)
|
await async_wait_recording_done(hass)
|
||||||
@@ -192,6 +199,8 @@ async def test_mill_historic_data_invalid_data(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test historic data from Mill."""
|
"""Test historic data from Mill."""
|
||||||
|
|
||||||
|
entry = MockConfigEntry(domain=DOMAIN)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
dt_util.parse_datetime("2024-12-03T00:00:00+01:00"): None,
|
dt_util.parse_datetime("2024-12-03T00:00:00+01:00"): None,
|
||||||
dt_util.parse_datetime("2024-12-03T01:00:00+01:00"): 3,
|
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"
|
statistic_id = f"{DOMAIN}:energy_dev_id"
|
||||||
|
|
||||||
coordinator = MillHistoricDataUpdateCoordinator(
|
coordinator = MillHistoricDataUpdateCoordinator(
|
||||||
hass, mill_data_connection=mill_data_connection
|
hass, entry, mill_data_connection=mill_data_connection
|
||||||
)
|
)
|
||||||
await coordinator._async_update_data()
|
await coordinator._async_update_data()
|
||||||
await async_wait_recording_done(hass)
|
await async_wait_recording_done(hass)
|
||||||
|
Reference in New Issue
Block a user