mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Explicitly pass in the config_entry in powerfox coordinator (#138037)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
cb3a7dc503
commit
f8169f1110
@ -6,18 +6,15 @@ import asyncio
|
|||||||
|
|
||||||
from powerfox import Powerfox, PowerfoxConnectionError
|
from powerfox import Powerfox, PowerfoxConnectionError
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform
|
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
|
||||||
from .coordinator import PowerfoxDataUpdateCoordinator
|
from .coordinator import PowerfoxConfigEntry, PowerfoxDataUpdateCoordinator
|
||||||
|
|
||||||
PLATFORMS: list[Platform] = [Platform.SENSOR]
|
PLATFORMS: list[Platform] = [Platform.SENSOR]
|
||||||
|
|
||||||
type PowerfoxConfigEntry = ConfigEntry[list[PowerfoxDataUpdateCoordinator]]
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: PowerfoxConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: PowerfoxConfigEntry) -> bool:
|
||||||
"""Set up Powerfox from a config entry."""
|
"""Set up Powerfox from a config entry."""
|
||||||
@ -34,7 +31,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: PowerfoxConfigEntry) ->
|
|||||||
raise ConfigEntryNotReady from err
|
raise ConfigEntryNotReady from err
|
||||||
|
|
||||||
coordinators: list[PowerfoxDataUpdateCoordinator] = [
|
coordinators: list[PowerfoxDataUpdateCoordinator] = [
|
||||||
PowerfoxDataUpdateCoordinator(hass, client, device) for device in devices
|
PowerfoxDataUpdateCoordinator(hass, entry, client, device) for device in devices
|
||||||
]
|
]
|
||||||
|
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
|
@ -18,15 +18,18 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
|
|||||||
|
|
||||||
from .const import DOMAIN, LOGGER, SCAN_INTERVAL
|
from .const import DOMAIN, LOGGER, SCAN_INTERVAL
|
||||||
|
|
||||||
|
type PowerfoxConfigEntry = ConfigEntry[list[PowerfoxDataUpdateCoordinator]]
|
||||||
|
|
||||||
|
|
||||||
class PowerfoxDataUpdateCoordinator(DataUpdateCoordinator[Poweropti]):
|
class PowerfoxDataUpdateCoordinator(DataUpdateCoordinator[Poweropti]):
|
||||||
"""Class to manage fetching Powerfox data from the API."""
|
"""Class to manage fetching Powerfox data from the API."""
|
||||||
|
|
||||||
config_entry: ConfigEntry
|
config_entry: PowerfoxConfigEntry
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
config_entry: PowerfoxConfigEntry,
|
||||||
client: Powerfox,
|
client: Powerfox,
|
||||||
device: Device,
|
device: Device,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -34,6 +37,7 @@ class PowerfoxDataUpdateCoordinator(DataUpdateCoordinator[Poweropti]):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
LOGGER,
|
LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name=DOMAIN,
|
name=DOMAIN,
|
||||||
update_interval=SCAN_INTERVAL,
|
update_interval=SCAN_INTERVAL,
|
||||||
)
|
)
|
||||||
|
@ -9,7 +9,7 @@ from powerfox import HeatMeter, PowerMeter, WaterMeter
|
|||||||
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import PowerfoxConfigEntry, PowerfoxDataUpdateCoordinator
|
from .coordinator import PowerfoxConfigEntry, PowerfoxDataUpdateCoordinator
|
||||||
|
|
||||||
|
|
||||||
async def async_get_config_entry_diagnostics(
|
async def async_get_config_entry_diagnostics(
|
||||||
|
@ -17,8 +17,7 @@ from homeassistant.const import UnitOfEnergy, UnitOfPower, UnitOfVolume
|
|||||||
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 PowerfoxConfigEntry
|
from .coordinator import PowerfoxConfigEntry, PowerfoxDataUpdateCoordinator
|
||||||
from .coordinator import PowerfoxDataUpdateCoordinator
|
|
||||||
from .entity import PowerfoxEntity
|
from .entity import PowerfoxEntity
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user