mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Explicitly pass in the config_entry in smlight coordinator (#137943)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
cc37ff9221
commit
9110557e36
@ -2,16 +2,18 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass
|
|
||||||
|
|
||||||
from pysmlight import Api2, Info, Radio
|
from pysmlight import Api2, Info, Radio
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import CONF_HOST, Platform
|
from homeassistant.const import CONF_HOST, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
|
||||||
from .coordinator import SmDataUpdateCoordinator, SmFirmwareUpdateCoordinator
|
from .coordinator import (
|
||||||
|
SmConfigEntry,
|
||||||
|
SmDataUpdateCoordinator,
|
||||||
|
SmFirmwareUpdateCoordinator,
|
||||||
|
SmlightData,
|
||||||
|
)
|
||||||
|
|
||||||
PLATFORMS: list[Platform] = [
|
PLATFORMS: list[Platform] = [
|
||||||
Platform.BINARY_SENSOR,
|
Platform.BINARY_SENSOR,
|
||||||
@ -22,25 +24,12 @@ PLATFORMS: list[Platform] = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@dataclass(kw_only=True)
|
|
||||||
class SmlightData:
|
|
||||||
"""Coordinator data class."""
|
|
||||||
|
|
||||||
data: SmDataUpdateCoordinator
|
|
||||||
firmware: SmFirmwareUpdateCoordinator
|
|
||||||
|
|
||||||
|
|
||||||
type SmConfigEntry = ConfigEntry[SmlightData]
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: SmConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: SmConfigEntry) -> bool:
|
||||||
"""Set up SMLIGHT Zigbee from a config entry."""
|
"""Set up SMLIGHT Zigbee from a config entry."""
|
||||||
client = Api2(host=entry.data[CONF_HOST], session=async_get_clientsession(hass))
|
client = Api2(host=entry.data[CONF_HOST], session=async_get_clientsession(hass))
|
||||||
|
|
||||||
data_coordinator = SmDataUpdateCoordinator(hass, entry.data[CONF_HOST], client)
|
data_coordinator = SmDataUpdateCoordinator(hass, entry, client)
|
||||||
firmware_coordinator = SmFirmwareUpdateCoordinator(
|
firmware_coordinator = SmFirmwareUpdateCoordinator(hass, entry, client)
|
||||||
hass, entry.data[CONF_HOST], client
|
|
||||||
)
|
|
||||||
|
|
||||||
await data_coordinator.async_config_entry_first_refresh()
|
await data_coordinator.async_config_entry_first_refresh()
|
||||||
await firmware_coordinator.async_config_entry_first_refresh()
|
await firmware_coordinator.async_config_entry_first_refresh()
|
||||||
|
@ -14,13 +14,12 @@ from homeassistant.components.binary_sensor import (
|
|||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
BinarySensorEntityDescription,
|
BinarySensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import EntityCategory
|
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 .const import SCAN_INTERNET_INTERVAL
|
from .const import SCAN_INTERNET_INTERVAL
|
||||||
from .coordinator import SmDataUpdateCoordinator
|
from .coordinator import SmConfigEntry, SmDataUpdateCoordinator
|
||||||
from .entity import SmEntity
|
from .entity import SmEntity
|
||||||
|
|
||||||
SCAN_INTERVAL = SCAN_INTERNET_INTERVAL
|
SCAN_INTERVAL = SCAN_INTERNET_INTERVAL
|
||||||
@ -56,7 +55,7 @@ SENSORS = [
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: SmConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up SMLIGHT sensor based on a config entry."""
|
"""Set up SMLIGHT sensor based on a config entry."""
|
||||||
|
@ -14,14 +14,13 @@ from homeassistant.components.button import (
|
|||||||
ButtonEntity,
|
ButtonEntity,
|
||||||
ButtonEntityDescription,
|
ButtonEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import EntityCategory
|
from homeassistant.const import EntityCategory
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import SmDataUpdateCoordinator
|
from .coordinator import SmConfigEntry, SmDataUpdateCoordinator
|
||||||
from .entity import SmEntity
|
from .entity import SmEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -65,7 +64,7 @@ ROUTER = SmButtonDescription(
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: SmConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up SMLIGHT buttons based on a config entry."""
|
"""Set up SMLIGHT buttons based on a config entry."""
|
||||||
|
@ -4,14 +4,14 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
from pysmlight import Api2, Info, Sensors
|
from pysmlight import Api2, Info, Sensors
|
||||||
from pysmlight.const import Settings, SettingsProp
|
from pysmlight.const import Settings, SettingsProp
|
||||||
from pysmlight.exceptions import SmlightAuthError, SmlightConnectionError
|
from pysmlight.exceptions import SmlightAuthError, SmlightConnectionError
|
||||||
from pysmlight.models import FirmwareList
|
from pysmlight.models import FirmwareList
|
||||||
|
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||||
from homeassistant.helpers import issue_registry as ir
|
from homeassistant.helpers import issue_registry as ir
|
||||||
@ -21,8 +21,13 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
|
|||||||
|
|
||||||
from .const import DOMAIN, LOGGER, SCAN_FIRMWARE_INTERVAL, SCAN_INTERVAL
|
from .const import DOMAIN, LOGGER, SCAN_FIRMWARE_INTERVAL, SCAN_INTERVAL
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from . import SmConfigEntry
|
@dataclass(kw_only=True)
|
||||||
|
class SmlightData:
|
||||||
|
"""Coordinator data class."""
|
||||||
|
|
||||||
|
data: SmDataUpdateCoordinator
|
||||||
|
firmware: SmFirmwareUpdateCoordinator
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -42,17 +47,23 @@ class SmFwData:
|
|||||||
zb_firmware: list[FirmwareList]
|
zb_firmware: list[FirmwareList]
|
||||||
|
|
||||||
|
|
||||||
|
type SmConfigEntry = ConfigEntry[SmlightData]
|
||||||
|
|
||||||
|
|
||||||
class SmBaseDataUpdateCoordinator[_DataT](DataUpdateCoordinator[_DataT]):
|
class SmBaseDataUpdateCoordinator[_DataT](DataUpdateCoordinator[_DataT]):
|
||||||
"""Base Coordinator for SMLIGHT."""
|
"""Base Coordinator for SMLIGHT."""
|
||||||
|
|
||||||
config_entry: SmConfigEntry
|
config_entry: SmConfigEntry
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, host: str, client: Api2) -> None:
|
def __init__(
|
||||||
|
self, hass: HomeAssistant, config_entry: SmConfigEntry, client: Api2
|
||||||
|
) -> None:
|
||||||
"""Initialize the coordinator."""
|
"""Initialize the coordinator."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
LOGGER,
|
LOGGER,
|
||||||
name=f"{DOMAIN}_{host}",
|
config_entry=config_entry,
|
||||||
|
name=f"{DOMAIN}_{config_entry.data[CONF_HOST]}",
|
||||||
update_interval=SCAN_INTERVAL,
|
update_interval=SCAN_INTERVAL,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -133,9 +144,11 @@ class SmDataUpdateCoordinator(SmBaseDataUpdateCoordinator[SmData]):
|
|||||||
class SmFirmwareUpdateCoordinator(SmBaseDataUpdateCoordinator[SmFwData]):
|
class SmFirmwareUpdateCoordinator(SmBaseDataUpdateCoordinator[SmFwData]):
|
||||||
"""Class to manage fetching SMLIGHT firmware update data from cloud."""
|
"""Class to manage fetching SMLIGHT firmware update data from cloud."""
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, host: str, client: Api2) -> None:
|
def __init__(
|
||||||
|
self, hass: HomeAssistant, config_entry: SmConfigEntry, client: Api2
|
||||||
|
) -> None:
|
||||||
"""Initialize the coordinator."""
|
"""Initialize the coordinator."""
|
||||||
super().__init__(hass, host, client)
|
super().__init__(hass, config_entry, client)
|
||||||
|
|
||||||
self.update_interval = SCAN_FIRMWARE_INTERVAL
|
self.update_interval = SCAN_FIRMWARE_INTERVAL
|
||||||
# only one update can run at a time (core or zibgee)
|
# only one update can run at a time (core or zibgee)
|
||||||
|
@ -8,7 +8,7 @@ from pysmlight.const import Actions
|
|||||||
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import SmConfigEntry
|
from .coordinator import SmConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def async_get_config_entry_diagnostics(
|
async def async_get_config_entry_diagnostics(
|
||||||
|
@ -21,9 +21,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
from . import SmConfigEntry
|
|
||||||
from .const import UPTIME_DEVIATION
|
from .const import UPTIME_DEVIATION
|
||||||
from .coordinator import SmDataUpdateCoordinator
|
from .coordinator import SmConfigEntry, SmDataUpdateCoordinator
|
||||||
from .entity import SmEntity
|
from .entity import SmEntity
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,8 +19,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 SmConfigEntry
|
from .coordinator import SmConfigEntry, SmDataUpdateCoordinator
|
||||||
from .coordinator import SmDataUpdateCoordinator
|
|
||||||
from .entity import SmEntity
|
from .entity import SmEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -22,9 +22,9 @@ from homeassistant.core import HomeAssistant, callback
|
|||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import SmConfigEntry, get_radio
|
from . import get_radio
|
||||||
from .const import LOGGER
|
from .const import LOGGER
|
||||||
from .coordinator import SmFirmwareUpdateCoordinator, SmFwData
|
from .coordinator import SmConfigEntry, SmFirmwareUpdateCoordinator, SmFwData
|
||||||
from .entity import SmEntity
|
from .entity import SmEntity
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user