Explicitly pass in the config_entry in plugwise coordinator (#138039)

explicitly pass in the config_entry in coordinator
This commit is contained in:
Michael 2025-02-09 17:31:12 +01:00 committed by GitHub
parent 8382577ccb
commit ed3160344d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 15 additions and 22 deletions

View File

@ -4,22 +4,19 @@ from __future__ import annotations
from typing import Any from typing import Any
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform from homeassistant.const import Platform
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.helpers import device_registry as dr, entity_registry as er
from .const import DOMAIN, LOGGER, PLATFORMS from .const import DOMAIN, LOGGER, PLATFORMS
from .coordinator import PlugwiseDataUpdateCoordinator from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
type PlugwiseConfigEntry = ConfigEntry[PlugwiseDataUpdateCoordinator]
async def async_setup_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) -> bool:
"""Set up Plugwise components from a config entry.""" """Set up Plugwise components from a config entry."""
await er.async_migrate_entries(hass, entry.entry_id, async_migrate_entity_entry) await er.async_migrate_entries(hass, entry.entry_id, async_migrate_entity_entry)
coordinator = PlugwiseDataUpdateCoordinator(hass) coordinator = PlugwiseDataUpdateCoordinator(hass, entry)
await coordinator.async_config_entry_first_refresh() await coordinator.async_config_entry_first_refresh()
migrate_sensor_entities(hass, coordinator) migrate_sensor_entities(hass, coordinator)

View File

@ -17,8 +17,7 @@ from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import PlugwiseConfigEntry from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
from .coordinator import PlugwiseDataUpdateCoordinator
from .entity import PlugwiseEntity from .entity import PlugwiseEntity
SEVERITIES = ["other", "info", "warning", "error"] SEVERITIES = ["other", "info", "warning", "error"]

View File

@ -7,9 +7,8 @@ from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import PlugwiseConfigEntry
from .const import REBOOT from .const import REBOOT
from .coordinator import PlugwiseDataUpdateCoordinator from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
from .entity import PlugwiseEntity from .entity import PlugwiseEntity
from .util import plugwise_command from .util import plugwise_command

View File

@ -18,9 +18,8 @@ from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ServiceValidationError from homeassistant.exceptions import ServiceValidationError
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import PlugwiseConfigEntry
from .const import DOMAIN, MASTER_THERMOSTATS from .const import DOMAIN, MASTER_THERMOSTATS
from .coordinator import PlugwiseDataUpdateCoordinator from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
from .entity import PlugwiseEntity from .entity import PlugwiseEntity
from .util import plugwise_command from .util import plugwise_command

View File

@ -24,19 +24,22 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
from .const import DEFAULT_PORT, DEFAULT_USERNAME, DOMAIN, LOGGER from .const import DEFAULT_PORT, DEFAULT_USERNAME, DOMAIN, LOGGER
type PlugwiseConfigEntry = ConfigEntry[PlugwiseDataUpdateCoordinator]
class PlugwiseDataUpdateCoordinator(DataUpdateCoordinator[dict[str, GwEntityData]]): class PlugwiseDataUpdateCoordinator(DataUpdateCoordinator[dict[str, GwEntityData]]):
"""Class to manage fetching Plugwise data from single endpoint.""" """Class to manage fetching Plugwise data from single endpoint."""
_connected: bool = False _connected: bool = False
config_entry: ConfigEntry config_entry: PlugwiseConfigEntry
def __init__(self, hass: HomeAssistant) -> None: def __init__(self, hass: HomeAssistant, config_entry: PlugwiseConfigEntry) -> None:
"""Initialize the coordinator.""" """Initialize the coordinator."""
super().__init__( super().__init__(
hass, hass,
LOGGER, LOGGER,
config_entry=config_entry,
name=DOMAIN, name=DOMAIN,
update_interval=timedelta(seconds=60), update_interval=timedelta(seconds=60),
# Don't refresh immediately, give the device time to process # Don't refresh immediately, give the device time to process

View File

@ -6,7 +6,7 @@ from typing import Any
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from . import PlugwiseConfigEntry from .coordinator import PlugwiseConfigEntry
async def async_get_config_entry_diagnostics( async def async_get_config_entry_diagnostics(

View File

@ -14,9 +14,8 @@ from homeassistant.const import EntityCategory, UnitOfTemperature
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import PlugwiseConfigEntry
from .const import NumberType from .const import NumberType
from .coordinator import PlugwiseDataUpdateCoordinator from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
from .entity import PlugwiseEntity from .entity import PlugwiseEntity
from .util import plugwise_command from .util import plugwise_command

View File

@ -9,9 +9,8 @@ from homeassistant.const import STATE_ON, EntityCategory
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import PlugwiseConfigEntry
from .const import SelectOptionsType, SelectType from .const import SelectOptionsType, SelectType
from .coordinator import PlugwiseDataUpdateCoordinator from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
from .entity import PlugwiseEntity from .entity import PlugwiseEntity
from .util import plugwise_command from .util import plugwise_command

View File

@ -27,8 +27,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import PlugwiseConfigEntry from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
from .coordinator import PlugwiseDataUpdateCoordinator
from .entity import PlugwiseEntity from .entity import PlugwiseEntity
# Coordinator is used to centralize the data updates # Coordinator is used to centralize the data updates

View File

@ -16,8 +16,7 @@ from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import PlugwiseConfigEntry from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator
from .coordinator import PlugwiseDataUpdateCoordinator
from .entity import PlugwiseEntity from .entity import PlugwiseEntity
from .util import plugwise_command from .util import plugwise_command