mirror of
https://github.com/home-assistant/core.git
synced 2025-07-31 01:07:10 +00:00
Migrate lookin to use runtime_data (#147479)
This commit is contained in:
parent
7031167895
commit
066e840e06
@ -19,7 +19,6 @@ from aiolookin import (
|
|||||||
)
|
)
|
||||||
from aiolookin.models import UDPCommandType, UDPEvent
|
from aiolookin.models import UDPCommandType, UDPEvent
|
||||||
|
|
||||||
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, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
@ -34,7 +33,7 @@ from .const import (
|
|||||||
TYPE_TO_PLATFORM,
|
TYPE_TO_PLATFORM,
|
||||||
)
|
)
|
||||||
from .coordinator import LookinDataUpdateCoordinator, LookinPushCoordinator
|
from .coordinator import LookinDataUpdateCoordinator, LookinPushCoordinator
|
||||||
from .models import LookinData
|
from .models import LookinConfigEntry, LookinData
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -91,7 +90,7 @@ class LookinUDPManager:
|
|||||||
self._subscriptions = None
|
self._subscriptions = None
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: LookinConfigEntry) -> bool:
|
||||||
"""Set up lookin from a config entry."""
|
"""Set up lookin from a config entry."""
|
||||||
domain_data = hass.data.setdefault(DOMAIN, {})
|
domain_data = hass.data.setdefault(DOMAIN, {})
|
||||||
host = entry.data[CONF_HOST]
|
host = entry.data[CONF_HOST]
|
||||||
@ -172,7 +171,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.data[DOMAIN][entry.entry_id] = LookinData(
|
entry.runtime_data = LookinData(
|
||||||
host=host,
|
host=host,
|
||||||
lookin_udp_subs=lookin_udp_subs,
|
lookin_udp_subs=lookin_udp_subs,
|
||||||
lookin_device=lookin_device,
|
lookin_device=lookin_device,
|
||||||
@ -187,10 +186,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: LookinConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
|
|
||||||
if not hass.config_entries.async_loaded_entries(DOMAIN):
|
if not hass.config_entries.async_loaded_entries(DOMAIN):
|
||||||
manager: LookinUDPManager = hass.data[DOMAIN][UDP_MANAGER]
|
manager: LookinUDPManager = hass.data[DOMAIN][UDP_MANAGER]
|
||||||
@ -199,7 +197,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
async def async_remove_config_entry_device(
|
async def async_remove_config_entry_device(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, device_entry: dr.DeviceEntry
|
hass: HomeAssistant, entry: LookinConfigEntry, device_entry: dr.DeviceEntry
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Remove lookin config entry from a device."""
|
"""Remove lookin config entry from a device."""
|
||||||
data: LookinData = hass.data[DOMAIN][entry.entry_id]
|
data: LookinData = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
@ -20,7 +20,6 @@ from homeassistant.components.climate import (
|
|||||||
ClimateEntityFeature,
|
ClimateEntityFeature,
|
||||||
HVACMode,
|
HVACMode,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
PRECISION_WHOLE,
|
PRECISION_WHOLE,
|
||||||
@ -30,10 +29,10 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN, TYPE_TO_PLATFORM
|
from .const import TYPE_TO_PLATFORM
|
||||||
from .coordinator import LookinDataUpdateCoordinator
|
from .coordinator import LookinDataUpdateCoordinator
|
||||||
from .entity import LookinCoordinatorEntity
|
from .entity import LookinCoordinatorEntity
|
||||||
from .models import LookinData
|
from .models import LookinConfigEntry, LookinData
|
||||||
|
|
||||||
LOOKIN_FAN_MODE_IDX_TO_HASS: Final = [FAN_AUTO, FAN_LOW, FAN_MIDDLE, FAN_HIGH]
|
LOOKIN_FAN_MODE_IDX_TO_HASS: Final = [FAN_AUTO, FAN_LOW, FAN_MIDDLE, FAN_HIGH]
|
||||||
LOOKIN_SWING_MODE_IDX_TO_HASS: Final = [SWING_OFF, SWING_BOTH]
|
LOOKIN_SWING_MODE_IDX_TO_HASS: Final = [SWING_OFF, SWING_BOTH]
|
||||||
@ -64,11 +63,11 @@ LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: LookinConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the climate platform for lookin from a config entry."""
|
"""Set up the climate platform for lookin from a config entry."""
|
||||||
lookin_data: LookinData = hass.data[DOMAIN][config_entry.entry_id]
|
lookin_data = config_entry.runtime_data
|
||||||
entities = []
|
entities = []
|
||||||
|
|
||||||
for remote in lookin_data.devices:
|
for remote in lookin_data.devices:
|
||||||
|
@ -6,13 +6,16 @@ from collections.abc import Awaitable, Callable
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
|
|
||||||
from .const import NEVER_TIME, POLLING_FALLBACK_SECONDS
|
from .const import NEVER_TIME, POLLING_FALLBACK_SECONDS
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .models import LookinConfigEntry
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -44,12 +47,12 @@ class LookinPushCoordinator:
|
|||||||
class LookinDataUpdateCoordinator[_DataT](DataUpdateCoordinator[_DataT]):
|
class LookinDataUpdateCoordinator[_DataT](DataUpdateCoordinator[_DataT]):
|
||||||
"""DataUpdateCoordinator to gather data for a specific lookin devices."""
|
"""DataUpdateCoordinator to gather data for a specific lookin devices."""
|
||||||
|
|
||||||
config_entry: ConfigEntry
|
config_entry: LookinConfigEntry
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: LookinConfigEntry,
|
||||||
push_coordinator: LookinPushCoordinator,
|
push_coordinator: LookinPushCoordinator,
|
||||||
name: str,
|
name: str,
|
||||||
update_interval: timedelta | None = None,
|
update_interval: timedelta | None = None,
|
||||||
|
@ -6,25 +6,24 @@ import logging
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.light import ColorMode, LightEntity
|
from homeassistant.components.light import ColorMode, LightEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN, TYPE_TO_PLATFORM
|
from .const import TYPE_TO_PLATFORM
|
||||||
from .entity import LookinPowerPushRemoteEntity
|
from .entity import LookinPowerPushRemoteEntity
|
||||||
from .models import LookinData
|
from .models import LookinConfigEntry
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: LookinConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the light platform for lookin from a config entry."""
|
"""Set up the light platform for lookin from a config entry."""
|
||||||
lookin_data: LookinData = hass.data[DOMAIN][config_entry.entry_id]
|
lookin_data = config_entry.runtime_data
|
||||||
entities = []
|
entities = []
|
||||||
|
|
||||||
for remote in lookin_data.devices:
|
for remote in lookin_data.devices:
|
||||||
|
@ -12,15 +12,14 @@ from homeassistant.components.media_player import (
|
|||||||
MediaPlayerEntityFeature,
|
MediaPlayerEntityFeature,
|
||||||
MediaPlayerState,
|
MediaPlayerState,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN, TYPE_TO_PLATFORM
|
from .const import TYPE_TO_PLATFORM
|
||||||
from .coordinator import LookinDataUpdateCoordinator
|
from .coordinator import LookinDataUpdateCoordinator
|
||||||
from .entity import LookinPowerPushRemoteEntity
|
from .entity import LookinPowerPushRemoteEntity
|
||||||
from .models import LookinData
|
from .models import LookinConfigEntry, LookinData
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -43,11 +42,11 @@ _FUNCTION_NAME_TO_FEATURE = {
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: LookinConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the media_player platform for lookin from a config entry."""
|
"""Set up the media_player platform for lookin from a config entry."""
|
||||||
lookin_data: LookinData = hass.data[DOMAIN][config_entry.entry_id]
|
lookin_data = config_entry.runtime_data
|
||||||
entities = []
|
entities = []
|
||||||
|
|
||||||
for remote in lookin_data.devices:
|
for remote in lookin_data.devices:
|
||||||
|
@ -13,8 +13,12 @@ from aiolookin import (
|
|||||||
Remote,
|
Remote,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
|
||||||
from .coordinator import LookinDataUpdateCoordinator
|
from .coordinator import LookinDataUpdateCoordinator
|
||||||
|
|
||||||
|
type LookinConfigEntry = ConfigEntry[LookinData]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class LookinData:
|
class LookinData:
|
||||||
|
@ -10,14 +10,12 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import PERCENTAGE, UnitOfTemperature
|
from homeassistant.const import PERCENTAGE, UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN
|
|
||||||
from .entity import LookinDeviceCoordinatorEntity
|
from .entity import LookinDeviceCoordinatorEntity
|
||||||
from .models import LookinData
|
from .models import LookinConfigEntry, LookinData
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -42,11 +40,11 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: LookinConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up lookin sensors from the config entry."""
|
"""Set up lookin sensors from the config entry."""
|
||||||
lookin_data: LookinData = hass.data[DOMAIN][config_entry.entry_id]
|
lookin_data = config_entry.runtime_data
|
||||||
|
|
||||||
if lookin_data.lookin_device.model >= 2:
|
if lookin_data.lookin_device.model >= 2:
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user