Use runtime data in Yale Smart Alarm (#116548)
parent
ae6a497cd1
commit
ef2ae7b600
|
@ -9,11 +9,13 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .const import COORDINATOR, DOMAIN, LOGGER, PLATFORMS
|
||||
from .const import LOGGER, PLATFORMS
|
||||
from .coordinator import YaleDataUpdateCoordinator
|
||||
|
||||
YaleConfigEntry = ConfigEntry["YaleDataUpdateCoordinator"]
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: YaleConfigEntry) -> bool:
|
||||
"""Set up Yale from a config entry."""
|
||||
|
||||
coordinator = YaleDataUpdateCoordinator(hass, entry)
|
||||
|
@ -21,9 +23,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
raise ConfigEntryAuthFailed
|
||||
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {
|
||||
COORDINATOR: coordinator,
|
||||
}
|
||||
entry.runtime_data = coordinator
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
entry.async_on_unload(entry.add_update_listener(update_listener))
|
||||
|
@ -38,11 +38,7 @@ async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
|||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
|
||||
if await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
return True
|
||||
return False
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
|
|
@ -14,26 +14,24 @@ from homeassistant.components.alarm_control_panel import (
|
|||
AlarmControlPanelEntity,
|
||||
AlarmControlPanelEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from .const import COORDINATOR, DOMAIN, STATE_MAP, YALE_ALL_ERRORS
|
||||
from . import YaleConfigEntry
|
||||
from .const import DOMAIN, STATE_MAP, YALE_ALL_ERRORS
|
||||
from .coordinator import YaleDataUpdateCoordinator
|
||||
from .entity import YaleAlarmEntity
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
hass: HomeAssistant, entry: YaleConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up the alarm entry."""
|
||||
|
||||
async_add_entities(
|
||||
[YaleAlarmDevice(coordinator=hass.data[DOMAIN][entry.entry_id][COORDINATOR])]
|
||||
)
|
||||
async_add_entities([YaleAlarmDevice(coordinator=entry.runtime_data)])
|
||||
|
||||
|
||||
class YaleAlarmDevice(YaleAlarmEntity, AlarmControlPanelEntity):
|
||||
|
|
|
@ -7,12 +7,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 COORDINATOR, DOMAIN
|
||||
from . import YaleConfigEntry
|
||||
from .coordinator import YaleDataUpdateCoordinator
|
||||
from .entity import YaleAlarmEntity, YaleEntity
|
||||
|
||||
|
@ -45,13 +44,11 @@ SENSOR_TYPES = (
|
|||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
hass: HomeAssistant, entry: YaleConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up the Yale binary sensor entry."""
|
||||
|
||||
coordinator: YaleDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
||||
COORDINATOR
|
||||
]
|
||||
coordinator = entry.runtime_data
|
||||
sensors: list[YaleDoorSensor | YaleProblemSensor] = [
|
||||
YaleDoorSensor(coordinator, data) for data in coordinator.data["door_windows"]
|
||||
]
|
||||
|
|
|
@ -5,11 +5,10 @@ from __future__ import annotations
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import COORDINATOR, DOMAIN
|
||||
from . import YaleConfigEntry
|
||||
from .coordinator import YaleDataUpdateCoordinator
|
||||
from .entity import YaleAlarmEntity
|
||||
|
||||
|
@ -23,14 +22,12 @@ BUTTON_TYPES = (
|
|||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: YaleConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the button from a config entry."""
|
||||
|
||||
coordinator: YaleDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
||||
COORDINATOR
|
||||
]
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
async_add_entities(
|
||||
[YalePanicButton(coordinator, description) for description in BUTTON_TYPES]
|
||||
|
|
|
@ -26,7 +26,6 @@ MANUFACTURER = "Yale"
|
|||
MODEL = "main"
|
||||
|
||||
DOMAIN = "yale_smart_alarm"
|
||||
COORDINATOR = "coordinator"
|
||||
|
||||
DEFAULT_SCAN_INTERVAL = 15
|
||||
|
||||
|
|
|
@ -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 COORDINATOR, DOMAIN
|
||||
from .coordinator import YaleDataUpdateCoordinator
|
||||
from . import YaleConfigEntry
|
||||
|
||||
TO_REDACT = {
|
||||
"address",
|
||||
|
@ -24,12 +22,10 @@ TO_REDACT = {
|
|||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
hass: HomeAssistant, entry: YaleConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator: YaleDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
||||
COORDINATOR
|
||||
]
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
assert coordinator.yale
|
||||
get_all_data = await hass.async_add_executor_job(coordinator.yale.get_all)
|
||||
|
|
|
@ -5,15 +5,14 @@ from __future__ import annotations
|
|||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from homeassistant.components.lock import LockEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_CODE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import YaleConfigEntry
|
||||
from .const import (
|
||||
CONF_LOCK_CODE_DIGITS,
|
||||
COORDINATOR,
|
||||
DEFAULT_LOCK_CODE_DIGITS,
|
||||
DOMAIN,
|
||||
YALE_ALL_ERRORS,
|
||||
|
@ -23,13 +22,11 @@ from .entity import YaleEntity
|
|||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
hass: HomeAssistant, entry: YaleConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up the Yale lock entry."""
|
||||
|
||||
coordinator: YaleDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
|
||||
COORDINATOR
|
||||
]
|
||||
coordinator = entry.runtime_data
|
||||
code_format = entry.options.get(CONF_LOCK_CODE_DIGITS, DEFAULT_LOCK_CODE_DIGITS)
|
||||
|
||||
async_add_entities(
|
||||
|
|
Loading…
Reference in New Issue