Migrate tedee to `entry.runtime_data` (#118246)
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>pull/118249/head
parent
b61919ec71
commit
70820c1702
|
@ -33,8 +33,10 @@ PLATFORMS = [
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
type TedeeConfigEntry = ConfigEntry[TedeeApiCoordinator]
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: TedeeConfigEntry) -> bool:
|
||||
"""Integration setup."""
|
||||
|
||||
coordinator = TedeeApiCoordinator(hass)
|
||||
|
@ -51,7 +53,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
serial_number=coordinator.bridge.serial,
|
||||
)
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
||||
entry.runtime_data = coordinator
|
||||
|
||||
async def unregister_webhook(_: Any) -> None:
|
||||
await coordinator.async_unregister_webhook()
|
||||
|
@ -100,11 +102,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
|
||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
return unload_ok
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
def get_webhook_handler(
|
||||
|
|
|
@ -11,12 +11,11 @@ from homeassistant.components.binary_sensor import (
|
|||
BinarySensorEntity,
|
||||
BinarySensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from . import TedeeConfigEntry
|
||||
from .entity import TedeeDescriptionEntity
|
||||
|
||||
|
||||
|
@ -53,11 +52,11 @@ ENTITIES: tuple[TedeeBinarySensorEntityDescription, ...] = (
|
|||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: TedeeConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Tedee sensor entity."""
|
||||
coordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
async_add_entities(
|
||||
TedeeBinarySensorEntity(lock, coordinator, entity_description)
|
||||
|
|
|
@ -5,11 +5,9 @@ from __future__ import annotations
|
|||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import TedeeApiCoordinator
|
||||
from . import TedeeConfigEntry
|
||||
|
||||
TO_REDACT = {
|
||||
"lock_id",
|
||||
|
@ -17,10 +15,10 @@ TO_REDACT = {
|
|||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
hass: HomeAssistant, entry: TedeeConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator: TedeeApiCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator = entry.runtime_data
|
||||
# dict has sensitive info as key, redact manually
|
||||
data = {
|
||||
index: lock.to_dict()
|
||||
|
|
|
@ -5,23 +5,22 @@ from typing import Any
|
|||
from pytedee_async import TedeeClientException, TedeeLock, TedeeLockState
|
||||
|
||||
from homeassistant.components.lock import LockEntity, LockEntityFeature
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from . import TedeeConfigEntry
|
||||
from .coordinator import TedeeApiCoordinator
|
||||
from .entity import TedeeEntity
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: TedeeConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Tedee lock entity."""
|
||||
coordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
entities: list[TedeeLockEntity] = []
|
||||
for lock in coordinator.data.values():
|
||||
|
|
|
@ -11,12 +11,11 @@ from homeassistant.components.sensor import (
|
|||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import PERCENTAGE, EntityCategory, UnitOfTime
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from . import TedeeConfigEntry
|
||||
from .entity import TedeeDescriptionEntity
|
||||
|
||||
|
||||
|
@ -50,11 +49,11 @@ ENTITIES: tuple[TedeeSensorEntityDescription, ...] = (
|
|||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: TedeeConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Tedee sensor entity."""
|
||||
coordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
async_add_entities(
|
||||
TedeeSensorEntity(lock, coordinator, entity_description)
|
||||
|
|
Loading…
Reference in New Issue