mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 00:37:13 +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 homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import (
|
||||
@ -19,14 +18,14 @@ from .api import (
|
||||
OAuth2SessionLyric,
|
||||
)
|
||||
from .const import DOMAIN
|
||||
from .coordinator import LyricDataUpdateCoordinator
|
||||
from .coordinator import LyricConfigEntry, LyricDataUpdateCoordinator
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
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."""
|
||||
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
|
||||
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)
|
||||
|
||||
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_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
if unload_ok:
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
return unload_ok
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
@ -24,7 +24,6 @@ from homeassistant.components.climate import (
|
||||
HVACAction,
|
||||
HVACMode,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_TEMPERATURE,
|
||||
PRECISION_HALVES,
|
||||
@ -38,7 +37,6 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.typing import VolDictType
|
||||
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
LYRIC_EXCEPTIONS,
|
||||
PRESET_HOLD_UNTIL,
|
||||
PRESET_NO_HOLD,
|
||||
@ -46,7 +44,7 @@ from .const import (
|
||||
PRESET_TEMPORARY_HOLD,
|
||||
PRESET_VACATION_HOLD,
|
||||
)
|
||||
from .coordinator import LyricDataUpdateCoordinator
|
||||
from .coordinator import LyricConfigEntry, LyricDataUpdateCoordinator
|
||||
from .entity import LyricDeviceEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -121,11 +119,11 @@ SCHEMA_HOLD_TIME: VolDictType = {
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: LyricConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""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(
|
||||
(
|
||||
|
@ -20,16 +20,18 @@ from .api import OAuth2SessionLyric
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
type LyricConfigEntry = ConfigEntry[LyricDataUpdateCoordinator]
|
||||
|
||||
|
||||
class LyricDataUpdateCoordinator(DataUpdateCoordinator[Lyric]):
|
||||
"""Data update coordinator for Honeywell Lyric."""
|
||||
|
||||
config_entry: ConfigEntry
|
||||
config_entry: LyricConfigEntry
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: LyricConfigEntry,
|
||||
oauth_session: OAuth2SessionLyric,
|
||||
lyric: Lyric,
|
||||
) -> None:
|
||||
|
@ -16,7 +16,6 @@ from homeassistant.components.sensor import (
|
||||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import PERCENTAGE, UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant
|
||||
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 .const import (
|
||||
DOMAIN,
|
||||
PRESET_HOLD_UNTIL,
|
||||
PRESET_NO_HOLD,
|
||||
PRESET_PERMANENT_HOLD,
|
||||
PRESET_TEMPORARY_HOLD,
|
||||
PRESET_VACATION_HOLD,
|
||||
)
|
||||
from .coordinator import LyricDataUpdateCoordinator
|
||||
from .coordinator import LyricConfigEntry, LyricDataUpdateCoordinator
|
||||
from .entity import LyricAccessoryEntity, LyricDeviceEntity
|
||||
|
||||
LYRIC_SETPOINT_STATUS_NAMES = {
|
||||
@ -159,11 +157,11 @@ def get_datetime_from_future_time(time_str: str) -> datetime:
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: LyricConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""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(
|
||||
LyricSensor(
|
||||
|
Loading…
x
Reference in New Issue
Block a user