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