mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Explicitly pass in the config_entry in weheat coordinator (#137868)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
a59d829e6a
commit
07e9d80607
@ -8,7 +8,6 @@ import aiohttp
|
|||||||
from weheat.abstractions.discovery import HeatPumpDiscovery
|
from weheat.abstractions.discovery import HeatPumpDiscovery
|
||||||
from weheat.exceptions import UnauthorizedException
|
from weheat.exceptions import UnauthorizedException
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import CONF_ACCESS_TOKEN, Platform
|
from homeassistant.const import CONF_ACCESS_TOKEN, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
@ -19,12 +18,10 @@ from homeassistant.helpers.config_entry_oauth2_flow import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from .const import API_URL, LOGGER
|
from .const import API_URL, LOGGER
|
||||||
from .coordinator import WeheatDataUpdateCoordinator
|
from .coordinator import WeheatConfigEntry, WeheatDataUpdateCoordinator
|
||||||
|
|
||||||
PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.SENSOR]
|
PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.SENSOR]
|
||||||
|
|
||||||
type WeheatConfigEntry = ConfigEntry[list[WeheatDataUpdateCoordinator]]
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: WeheatConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: WeheatConfigEntry) -> bool:
|
||||||
"""Set up Weheat from a config entry."""
|
"""Set up Weheat from a config entry."""
|
||||||
@ -58,7 +55,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: WeheatConfigEntry) -> bo
|
|||||||
for pump_info in discovered_heat_pumps:
|
for pump_info in discovered_heat_pumps:
|
||||||
LOGGER.debug("Adding %s", pump_info)
|
LOGGER.debug("Adding %s", pump_info)
|
||||||
# for each pump, add a coordinator
|
# for each pump, add a coordinator
|
||||||
new_coordinator = WeheatDataUpdateCoordinator(hass, session, pump_info)
|
new_coordinator = WeheatDataUpdateCoordinator(hass, entry, session, pump_info)
|
||||||
|
|
||||||
await new_coordinator.async_config_entry_first_refresh()
|
await new_coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
|
@ -14,8 +14,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from . import WeheatConfigEntry
|
from .coordinator import WeheatConfigEntry, WeheatDataUpdateCoordinator
|
||||||
from .coordinator import WeheatDataUpdateCoordinator
|
|
||||||
from .entity import WeheatEntity
|
from .entity import WeheatEntity
|
||||||
|
|
||||||
# Coordinator is used to centralize the data updates
|
# Coordinator is used to centralize the data updates
|
||||||
|
@ -13,6 +13,7 @@ from weheat.exceptions import (
|
|||||||
UnauthorizedException,
|
UnauthorizedException,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_ACCESS_TOKEN
|
from homeassistant.const import CONF_ACCESS_TOKEN
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||||
@ -30,13 +31,18 @@ EXCEPTIONS = (
|
|||||||
ApiException,
|
ApiException,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type WeheatConfigEntry = ConfigEntry[list[WeheatDataUpdateCoordinator]]
|
||||||
|
|
||||||
|
|
||||||
class WeheatDataUpdateCoordinator(DataUpdateCoordinator[HeatPump]):
|
class WeheatDataUpdateCoordinator(DataUpdateCoordinator[HeatPump]):
|
||||||
"""A custom coordinator for the Weheat heatpump integration."""
|
"""A custom coordinator for the Weheat heatpump integration."""
|
||||||
|
|
||||||
|
config_entry: WeheatConfigEntry
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
config_entry: WeheatConfigEntry,
|
||||||
session: OAuth2Session,
|
session: OAuth2Session,
|
||||||
heat_pump: HeatPumpDiscovery.HeatPumpInfo,
|
heat_pump: HeatPumpDiscovery.HeatPumpInfo,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -44,6 +50,7 @@ class WeheatDataUpdateCoordinator(DataUpdateCoordinator[HeatPump]):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
logger=LOGGER,
|
logger=LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name=DOMAIN,
|
name=DOMAIN,
|
||||||
update_interval=timedelta(seconds=UPDATE_INTERVAL),
|
update_interval=timedelta(seconds=UPDATE_INTERVAL),
|
||||||
)
|
)
|
||||||
|
@ -22,13 +22,12 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from . import WeheatConfigEntry
|
|
||||||
from .const import (
|
from .const import (
|
||||||
DISPLAY_PRECISION_COP,
|
DISPLAY_PRECISION_COP,
|
||||||
DISPLAY_PRECISION_WATER_TEMP,
|
DISPLAY_PRECISION_WATER_TEMP,
|
||||||
DISPLAY_PRECISION_WATTS,
|
DISPLAY_PRECISION_WATTS,
|
||||||
)
|
)
|
||||||
from .coordinator import WeheatDataUpdateCoordinator
|
from .coordinator import WeheatConfigEntry, WeheatDataUpdateCoordinator
|
||||||
from .entity import WeheatEntity
|
from .entity import WeheatEntity
|
||||||
|
|
||||||
# Coordinator is used to centralize the data updates
|
# Coordinator is used to centralize the data updates
|
||||||
|
Loading…
x
Reference in New Issue
Block a user