mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Explicitly pass in the config_entry in iskra coordinator (#138134)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
2dbf475d6f
commit
b6afe130fc
@ -6,7 +6,6 @@ from pyiskra.adapters import Modbus, RestAPI
|
|||||||
from pyiskra.devices import Device
|
from pyiskra.devices import Device
|
||||||
from pyiskra.exceptions import DeviceConnectionError, DeviceNotSupported, NotAuthorised
|
from pyiskra.exceptions import DeviceConnectionError, DeviceNotSupported, NotAuthorised
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_ADDRESS,
|
CONF_ADDRESS,
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
@ -21,14 +20,11 @@ from homeassistant.exceptions import ConfigEntryNotReady
|
|||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
from .const import DOMAIN, MANUFACTURER
|
from .const import DOMAIN, MANUFACTURER
|
||||||
from .coordinator import IskraDataUpdateCoordinator
|
from .coordinator import IskraConfigEntry, IskraDataUpdateCoordinator
|
||||||
|
|
||||||
PLATFORMS: list[Platform] = [Platform.SENSOR]
|
PLATFORMS: list[Platform] = [Platform.SENSOR]
|
||||||
|
|
||||||
|
|
||||||
type IskraConfigEntry = ConfigEntry[list[IskraDataUpdateCoordinator]]
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: IskraConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: IskraConfigEntry) -> bool:
|
||||||
"""Set up iskra device from a config entry."""
|
"""Set up iskra device from a config entry."""
|
||||||
conf = entry.data
|
conf = entry.data
|
||||||
@ -79,11 +75,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: IskraConfigEntry) -> boo
|
|||||||
)
|
)
|
||||||
|
|
||||||
coordinators = [
|
coordinators = [
|
||||||
IskraDataUpdateCoordinator(hass, child_device)
|
IskraDataUpdateCoordinator(hass, entry, child_device)
|
||||||
for child_device in base_device.get_child_devices()
|
for child_device in base_device.get_child_devices()
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
coordinators = [IskraDataUpdateCoordinator(hass, base_device)]
|
coordinators = [IskraDataUpdateCoordinator(hass, entry, base_device)]
|
||||||
|
|
||||||
for coordinator in coordinators:
|
for coordinator in coordinators:
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
@ -11,6 +11,7 @@ from pyiskra.exceptions import (
|
|||||||
NotAuthorised,
|
NotAuthorised,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
@ -18,21 +19,26 @@ from .const import DOMAIN
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
type IskraConfigEntry = ConfigEntry[list[IskraDataUpdateCoordinator]]
|
||||||
|
|
||||||
|
|
||||||
class IskraDataUpdateCoordinator(DataUpdateCoordinator[None]):
|
class IskraDataUpdateCoordinator(DataUpdateCoordinator[None]):
|
||||||
"""Class to manage fetching Iskra data."""
|
"""Class to manage fetching Iskra data."""
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, device: Device) -> None:
|
config_entry: IskraConfigEntry
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, hass: HomeAssistant, config_entry: IskraConfigEntry, device: Device
|
||||||
|
) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
self.device = device
|
self.device = device
|
||||||
|
|
||||||
update_interval = timedelta(seconds=60)
|
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name=DOMAIN,
|
name=DOMAIN,
|
||||||
update_interval=update_interval,
|
update_interval=timedelta(seconds=60),
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _async_update_data(self) -> None:
|
async def _async_update_data(self) -> None:
|
||||||
|
@ -26,7 +26,6 @@ from homeassistant.const import (
|
|||||||
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 IskraConfigEntry
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_FREQUENCY,
|
ATTR_FREQUENCY,
|
||||||
ATTR_NON_RESETTABLE_COUNTER,
|
ATTR_NON_RESETTABLE_COUNTER,
|
||||||
@ -44,7 +43,7 @@ from .const import (
|
|||||||
ATTR_TOTAL_APPARENT_POWER,
|
ATTR_TOTAL_APPARENT_POWER,
|
||||||
ATTR_TOTAL_REACTIVE_POWER,
|
ATTR_TOTAL_REACTIVE_POWER,
|
||||||
)
|
)
|
||||||
from .coordinator import IskraDataUpdateCoordinator
|
from .coordinator import IskraConfigEntry, IskraDataUpdateCoordinator
|
||||||
from .entity import IskraEntity
|
from .entity import IskraEntity
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user