mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Migrate lyric to use runtime_data (#147475)
This commit is contained in:
parent
91e7b75a44
commit
10d1affd81
@ -4,7 +4,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from aiolyric import Lyric
|
from aiolyric import Lyric
|
||||||
|
|
||||||
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 import (
|
from homeassistant.helpers import (
|
||||||
@ -19,14 +18,14 @@ from .api import (
|
|||||||
OAuth2SessionLyric,
|
OAuth2SessionLyric,
|
||||||
)
|
)
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import LyricDataUpdateCoordinator
|
from .coordinator import LyricConfigEntry, LyricDataUpdateCoordinator
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||||
|
|
||||||
PLATFORMS = [Platform.CLIMATE, Platform.SENSOR]
|
PLATFORMS = [Platform.CLIMATE, Platform.SENSOR]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: LyricConfigEntry) -> bool:
|
||||||
"""Set up Honeywell Lyric from a config entry."""
|
"""Set up Honeywell Lyric from a config entry."""
|
||||||
implementation = (
|
implementation = (
|
||||||
await config_entry_oauth2_flow.async_get_config_entry_implementation(
|
await config_entry_oauth2_flow.async_get_config_entry_implementation(
|
||||||
@ -53,17 +52,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
# Fetch initial data so we have data when entities subscribe
|
# Fetch initial data so we have data when entities subscribe
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
entry.runtime_data = coordinator
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: LyricConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
if unload_ok:
|
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
|
||||||
|
@ -24,7 +24,6 @@ from homeassistant.components.climate import (
|
|||||||
HVACAction,
|
HVACAction,
|
||||||
HVACMode,
|
HVACMode,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
PRECISION_HALVES,
|
PRECISION_HALVES,
|
||||||
@ -38,7 +37,6 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
|||||||
from homeassistant.helpers.typing import VolDictType
|
from homeassistant.helpers.typing import VolDictType
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
DOMAIN,
|
|
||||||
LYRIC_EXCEPTIONS,
|
LYRIC_EXCEPTIONS,
|
||||||
PRESET_HOLD_UNTIL,
|
PRESET_HOLD_UNTIL,
|
||||||
PRESET_NO_HOLD,
|
PRESET_NO_HOLD,
|
||||||
@ -46,7 +44,7 @@ from .const import (
|
|||||||
PRESET_TEMPORARY_HOLD,
|
PRESET_TEMPORARY_HOLD,
|
||||||
PRESET_VACATION_HOLD,
|
PRESET_VACATION_HOLD,
|
||||||
)
|
)
|
||||||
from .coordinator import LyricDataUpdateCoordinator
|
from .coordinator import LyricConfigEntry, LyricDataUpdateCoordinator
|
||||||
from .entity import LyricDeviceEntity
|
from .entity import LyricDeviceEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -121,11 +119,11 @@ SCHEMA_HOLD_TIME: VolDictType = {
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: LyricConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Honeywell Lyric climate platform based on a config entry."""
|
"""Set up the Honeywell Lyric climate platform based on a config entry."""
|
||||||
coordinator: LyricDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator = entry.runtime_data
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
(
|
(
|
||||||
|
@ -20,16 +20,18 @@ from .api import OAuth2SessionLyric
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
type LyricConfigEntry = ConfigEntry[LyricDataUpdateCoordinator]
|
||||||
|
|
||||||
|
|
||||||
class LyricDataUpdateCoordinator(DataUpdateCoordinator[Lyric]):
|
class LyricDataUpdateCoordinator(DataUpdateCoordinator[Lyric]):
|
||||||
"""Data update coordinator for Honeywell Lyric."""
|
"""Data update coordinator for Honeywell Lyric."""
|
||||||
|
|
||||||
config_entry: ConfigEntry
|
config_entry: LyricConfigEntry
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: LyricConfigEntry,
|
||||||
oauth_session: OAuth2SessionLyric,
|
oauth_session: OAuth2SessionLyric,
|
||||||
lyric: Lyric,
|
lyric: Lyric,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -16,7 +16,6 @@ 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
|
||||||
@ -24,14 +23,13 @@ from homeassistant.helpers.typing import StateType
|
|||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
DOMAIN,
|
|
||||||
PRESET_HOLD_UNTIL,
|
PRESET_HOLD_UNTIL,
|
||||||
PRESET_NO_HOLD,
|
PRESET_NO_HOLD,
|
||||||
PRESET_PERMANENT_HOLD,
|
PRESET_PERMANENT_HOLD,
|
||||||
PRESET_TEMPORARY_HOLD,
|
PRESET_TEMPORARY_HOLD,
|
||||||
PRESET_VACATION_HOLD,
|
PRESET_VACATION_HOLD,
|
||||||
)
|
)
|
||||||
from .coordinator import LyricDataUpdateCoordinator
|
from .coordinator import LyricConfigEntry, LyricDataUpdateCoordinator
|
||||||
from .entity import LyricAccessoryEntity, LyricDeviceEntity
|
from .entity import LyricAccessoryEntity, LyricDeviceEntity
|
||||||
|
|
||||||
LYRIC_SETPOINT_STATUS_NAMES = {
|
LYRIC_SETPOINT_STATUS_NAMES = {
|
||||||
@ -159,11 +157,11 @@ def get_datetime_from_future_time(time_str: str) -> datetime:
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: LyricConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Honeywell Lyric sensor platform based on a config entry."""
|
"""Set up the Honeywell Lyric sensor platform based on a config entry."""
|
||||||
coordinator: LyricDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator = entry.runtime_data
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
LyricSensor(
|
LyricSensor(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user