From 8c3dab199e4248752643dc10a41b958ee15a6f20 Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Sun, 9 Feb 2025 21:10:21 +0100 Subject: [PATCH] Explicitly pass in the config_entry in homewizard coordinator (#138152) explicitly pass in the config_entry in coordinator --- .../components/homewizard/__init__.py | 8 +++----- homeassistant/components/homewizard/button.py | 3 +-- .../components/homewizard/coordinator.py | 19 ++++++++++++++++--- .../components/homewizard/diagnostics.py | 2 +- homeassistant/components/homewizard/number.py | 3 +-- homeassistant/components/homewizard/sensor.py | 3 +-- homeassistant/components/homewizard/switch.py | 3 +-- 7 files changed, 24 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/homewizard/__init__.py b/homeassistant/components/homewizard/__init__.py index 36c9681dcd2..3831146aed8 100644 --- a/homeassistant/components/homewizard/__init__.py +++ b/homeassistant/components/homewizard/__init__.py @@ -7,7 +7,7 @@ from homewizard_energy import ( has_v2_api, ) -from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntry +from homeassistant.config_entries import SOURCE_REAUTH from homeassistant.const import CONF_IP_ADDRESS, CONF_TOKEN from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady @@ -15,9 +15,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from .const import DOMAIN, PLATFORMS -from .coordinator import HWEnergyDeviceUpdateCoordinator - -type HomeWizardConfigEntry = ConfigEntry[HWEnergyDeviceUpdateCoordinator] +from .coordinator import HomeWizardConfigEntry, HWEnergyDeviceUpdateCoordinator async def async_setup_entry(hass: HomeAssistant, entry: HomeWizardConfigEntry) -> bool: @@ -42,7 +40,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: HomeWizardConfigEntry) - if is_battery: await async_check_v2_support_and_create_issue(hass, entry) - coordinator = HWEnergyDeviceUpdateCoordinator(hass, api) + coordinator = HWEnergyDeviceUpdateCoordinator(hass, entry, api) try: await coordinator.async_config_entry_first_refresh() diff --git a/homeassistant/components/homewizard/button.py b/homeassistant/components/homewizard/button.py index b86f797ec2d..d4484ee4be3 100644 --- a/homeassistant/components/homewizard/button.py +++ b/homeassistant/components/homewizard/button.py @@ -5,8 +5,7 @@ from homeassistant.const import EntityCategory from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import HomeWizardConfigEntry -from .coordinator import HWEnergyDeviceUpdateCoordinator +from .coordinator import HomeWizardConfigEntry, HWEnergyDeviceUpdateCoordinator from .entity import HomeWizardEntity from .helpers import homewizard_exception_handler diff --git a/homeassistant/components/homewizard/coordinator.py b/homeassistant/components/homewizard/coordinator.py index 92beb99ad2c..e87381c5fa9 100644 --- a/homeassistant/components/homewizard/coordinator.py +++ b/homeassistant/components/homewizard/coordinator.py @@ -13,6 +13,8 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda from .const import DOMAIN, LOGGER, UPDATE_INTERVAL +type HomeWizardConfigEntry = ConfigEntry[HWEnergyDeviceUpdateCoordinator] + class HWEnergyDeviceUpdateCoordinator(DataUpdateCoordinator[DeviceResponseEntry]): """Gather data for the energy device.""" @@ -20,11 +22,22 @@ class HWEnergyDeviceUpdateCoordinator(DataUpdateCoordinator[DeviceResponseEntry] api: HomeWizardEnergy api_disabled: bool = False - config_entry: ConfigEntry + config_entry: HomeWizardConfigEntry - def __init__(self, hass: HomeAssistant, api: HomeWizardEnergy) -> None: + def __init__( + self, + hass: HomeAssistant, + config_entry: HomeWizardConfigEntry, + api: HomeWizardEnergy, + ) -> None: """Initialize update coordinator.""" - super().__init__(hass, LOGGER, name=DOMAIN, update_interval=UPDATE_INTERVAL) + super().__init__( + hass, + LOGGER, + config_entry=config_entry, + name=DOMAIN, + update_interval=UPDATE_INTERVAL, + ) self.api = api async def _async_update_data(self) -> DeviceResponseEntry: diff --git a/homeassistant/components/homewizard/diagnostics.py b/homeassistant/components/homewizard/diagnostics.py index 12bd25671e0..a3ae2555173 100644 --- a/homeassistant/components/homewizard/diagnostics.py +++ b/homeassistant/components/homewizard/diagnostics.py @@ -9,7 +9,7 @@ from homeassistant.components.diagnostics import async_redact_data from homeassistant.const import CONF_IP_ADDRESS from homeassistant.core import HomeAssistant -from . import HomeWizardConfigEntry +from .coordinator import HomeWizardConfigEntry TO_REDACT = { CONF_IP_ADDRESS, diff --git a/homeassistant/components/homewizard/number.py b/homeassistant/components/homewizard/number.py index 5806295fc81..e936657f254 100644 --- a/homeassistant/components/homewizard/number.py +++ b/homeassistant/components/homewizard/number.py @@ -7,8 +7,7 @@ from homeassistant.const import PERCENTAGE, EntityCategory from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import HomeWizardConfigEntry -from .coordinator import HWEnergyDeviceUpdateCoordinator +from .coordinator import HomeWizardConfigEntry, HWEnergyDeviceUpdateCoordinator from .entity import HomeWizardEntity from .helpers import homewizard_exception_handler diff --git a/homeassistant/components/homewizard/sensor.py b/homeassistant/components/homewizard/sensor.py index f6f5588956c..5f3133fa9ba 100644 --- a/homeassistant/components/homewizard/sensor.py +++ b/homeassistant/components/homewizard/sensor.py @@ -37,9 +37,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType from homeassistant.util.dt import utcnow -from . import HomeWizardConfigEntry from .const import DOMAIN -from .coordinator import HWEnergyDeviceUpdateCoordinator +from .coordinator import HomeWizardConfigEntry, HWEnergyDeviceUpdateCoordinator from .entity import HomeWizardEntity PARALLEL_UPDATES = 1 diff --git a/homeassistant/components/homewizard/switch.py b/homeassistant/components/homewizard/switch.py index 8ebb56433b1..9f6b3ddd81f 100644 --- a/homeassistant/components/homewizard/switch.py +++ b/homeassistant/components/homewizard/switch.py @@ -18,8 +18,7 @@ from homeassistant.const import EntityCategory from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import HomeWizardConfigEntry -from .coordinator import HWEnergyDeviceUpdateCoordinator +from .coordinator import HomeWizardConfigEntry, HWEnergyDeviceUpdateCoordinator from .entity import HomeWizardEntity from .helpers import homewizard_exception_handler