mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Explicitly pass in the config_entry in apsystems coordinator init (#137708)
explicitly pass in the config_entry in apsystems coordinator init
This commit is contained in:
parent
239408aa5d
commit
2f0e661569
@ -2,16 +2,13 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from APsystemsEZ1 import APsystemsEZ1M
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DEFAULT_PORT
|
||||
from .coordinator import ApSystemsDataCoordinator
|
||||
from .coordinator import ApSystemsConfigEntry, ApSystemsData, ApSystemsDataCoordinator
|
||||
|
||||
PLATFORMS: list[Platform] = [
|
||||
Platform.BINARY_SENSOR,
|
||||
@ -21,17 +18,6 @@ PLATFORMS: list[Platform] = [
|
||||
]
|
||||
|
||||
|
||||
@dataclass
|
||||
class ApSystemsData:
|
||||
"""Store runtime data."""
|
||||
|
||||
coordinator: ApSystemsDataCoordinator
|
||||
device_id: str
|
||||
|
||||
|
||||
type ApSystemsConfigEntry = ConfigEntry[ApSystemsData]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ApSystemsConfigEntry) -> bool:
|
||||
"""Set up this integration using UI."""
|
||||
api = APsystemsEZ1M(
|
||||
@ -40,7 +26,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ApSystemsConfigEntry) ->
|
||||
timeout=8,
|
||||
enable_debounce=True,
|
||||
)
|
||||
coordinator = ApSystemsDataCoordinator(hass, api)
|
||||
coordinator = ApSystemsDataCoordinator(hass, entry, api)
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
assert entry.unique_id
|
||||
entry.runtime_data = ApSystemsData(
|
||||
@ -51,6 +37,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ApSystemsConfigEntry) ->
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ApSystemsConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
@ -17,8 +17,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from . import ApSystemsConfigEntry, ApSystemsData
|
||||
from .coordinator import ApSystemsDataCoordinator
|
||||
from .coordinator import ApSystemsConfigEntry, ApSystemsData, ApSystemsDataCoordinator
|
||||
from .entity import ApSystemsEntity
|
||||
|
||||
|
||||
|
@ -12,6 +12,7 @@ from APsystemsEZ1 import (
|
||||
ReturnOutputData,
|
||||
)
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
@ -26,16 +27,34 @@ class ApSystemsSensorData:
|
||||
alarm_info: ReturnAlarmInfo
|
||||
|
||||
|
||||
@dataclass
|
||||
class ApSystemsData:
|
||||
"""Store runtime data."""
|
||||
|
||||
coordinator: ApSystemsDataCoordinator
|
||||
device_id: str
|
||||
|
||||
|
||||
type ApSystemsConfigEntry = ConfigEntry[ApSystemsData]
|
||||
|
||||
|
||||
class ApSystemsDataCoordinator(DataUpdateCoordinator[ApSystemsSensorData]):
|
||||
"""Coordinator used for all sensors."""
|
||||
|
||||
config_entry: ApSystemsConfigEntry
|
||||
device_version: str
|
||||
|
||||
def __init__(self, hass: HomeAssistant, api: APsystemsEZ1M) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: ApSystemsConfigEntry,
|
||||
api: APsystemsEZ1M,
|
||||
) -> None:
|
||||
"""Initialize my coordinator."""
|
||||
super().__init__(
|
||||
hass,
|
||||
LOGGER,
|
||||
config_entry=config_entry,
|
||||
name="APSystems Data",
|
||||
update_interval=timedelta(seconds=12),
|
||||
)
|
||||
|
@ -5,8 +5,8 @@ from __future__ import annotations
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from . import ApSystemsData
|
||||
from .const import DOMAIN
|
||||
from .coordinator import ApSystemsData
|
||||
|
||||
|
||||
class ApSystemsEntity(Entity):
|
||||
|
@ -10,7 +10,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import DiscoveryInfoType
|
||||
|
||||
from . import ApSystemsConfigEntry, ApSystemsData
|
||||
from .coordinator import ApSystemsConfigEntry, ApSystemsData
|
||||
from .entity import ApSystemsEntity
|
||||
|
||||
|
||||
|
@ -19,8 +19,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import DiscoveryInfoType, StateType
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from . import ApSystemsConfigEntry, ApSystemsData
|
||||
from .coordinator import ApSystemsDataCoordinator
|
||||
from .coordinator import ApSystemsConfigEntry, ApSystemsData, ApSystemsDataCoordinator
|
||||
from .entity import ApSystemsEntity
|
||||
|
||||
|
||||
|
@ -11,7 +11,7 @@ from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ApSystemsConfigEntry, ApSystemsData
|
||||
from .coordinator import ApSystemsConfigEntry, ApSystemsData
|
||||
from .entity import ApSystemsEntity
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user