mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Migrate linear_garage_door to use runtime_data (#147351)
Migrate linear_garage_door to use runtime_data/HassKey
This commit is contained in:
parent
27565df86f
commit
e1d5d312b8
@ -2,18 +2,17 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
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 issue_registry as ir
|
from homeassistant.helpers import issue_registry as ir
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import LinearUpdateCoordinator
|
from .coordinator import LinearConfigEntry, LinearUpdateCoordinator
|
||||||
|
|
||||||
PLATFORMS: list[Platform] = [Platform.COVER, Platform.LIGHT]
|
PLATFORMS: list[Platform] = [Platform.COVER, Platform.LIGHT]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: LinearConfigEntry) -> bool:
|
||||||
"""Set up Linear Garage Door from a config entry."""
|
"""Set up Linear Garage Door from a config entry."""
|
||||||
|
|
||||||
ir.async_create_issue(
|
ir.async_create_issue(
|
||||||
@ -35,21 +34,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
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: LinearConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
|
||||||
|
|
||||||
|
|
||||||
async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
async def async_remove_entry(hass: HomeAssistant, entry: LinearConfigEntry) -> None:
|
||||||
"""Remove a config entry."""
|
"""Remove a config entry."""
|
||||||
if not hass.config_entries.async_loaded_entries(DOMAIN):
|
if not hass.config_entries.async_loaded_entries(DOMAIN):
|
||||||
ir.async_delete_issue(hass, DOMAIN, DOMAIN)
|
ir.async_delete_issue(hass, DOMAIN, DOMAIN)
|
||||||
|
@ -19,6 +19,8 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
type LinearConfigEntry = ConfigEntry[LinearUpdateCoordinator]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class LinearDevice:
|
class LinearDevice:
|
||||||
@ -32,9 +34,9 @@ class LinearUpdateCoordinator(DataUpdateCoordinator[dict[str, LinearDevice]]):
|
|||||||
"""DataUpdateCoordinator for Linear."""
|
"""DataUpdateCoordinator for Linear."""
|
||||||
|
|
||||||
_devices: list[dict[str, Any]] | None = None
|
_devices: list[dict[str, Any]] | None = None
|
||||||
config_entry: ConfigEntry
|
config_entry: LinearConfigEntry
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
def __init__(self, hass: HomeAssistant, config_entry: LinearConfigEntry) -> None:
|
||||||
"""Initialize DataUpdateCoordinator for Linear."""
|
"""Initialize DataUpdateCoordinator for Linear."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
|
@ -8,12 +8,10 @@ from homeassistant.components.cover import (
|
|||||||
CoverEntity,
|
CoverEntity,
|
||||||
CoverEntityFeature,
|
CoverEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .coordinator import LinearConfigEntry
|
||||||
from .coordinator import LinearUpdateCoordinator
|
|
||||||
from .entity import LinearEntity
|
from .entity import LinearEntity
|
||||||
|
|
||||||
SUPPORTED_SUBDEVICES = ["GDO"]
|
SUPPORTED_SUBDEVICES = ["GDO"]
|
||||||
@ -23,11 +21,11 @@ SCAN_INTERVAL = timedelta(seconds=10)
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: LinearConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Linear Garage Door cover."""
|
"""Set up Linear Garage Door cover."""
|
||||||
coordinator: LinearUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator = config_entry.runtime_data
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
LinearCoverEntity(coordinator, device_id, device_data.name, sub_device_id)
|
LinearCoverEntity(coordinator, device_id, device_data.name, sub_device_id)
|
||||||
|
@ -6,21 +6,19 @@ from dataclasses import asdict
|
|||||||
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.const import CONF_EMAIL, CONF_PASSWORD
|
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .coordinator import LinearConfigEntry
|
||||||
from .coordinator import LinearUpdateCoordinator
|
|
||||||
|
|
||||||
TO_REDACT = {CONF_PASSWORD, CONF_EMAIL}
|
TO_REDACT = {CONF_PASSWORD, CONF_EMAIL}
|
||||||
|
|
||||||
|
|
||||||
async def async_get_config_entry_diagnostics(
|
async def async_get_config_entry_diagnostics(
|
||||||
hass: HomeAssistant, entry: ConfigEntry
|
hass: HomeAssistant, entry: LinearConfigEntry
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Return diagnostics for a config entry."""
|
"""Return diagnostics for a config entry."""
|
||||||
coordinator: LinearUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator = entry.runtime_data
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"entry": async_redact_data(entry.as_dict(), TO_REDACT),
|
"entry": async_redact_data(entry.as_dict(), TO_REDACT),
|
||||||
|
@ -5,12 +5,10 @@ from typing import Any
|
|||||||
from linear_garage_door import Linear
|
from linear_garage_door import Linear
|
||||||
|
|
||||||
from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity
|
from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .coordinator import LinearConfigEntry
|
||||||
from .coordinator import LinearUpdateCoordinator
|
|
||||||
from .entity import LinearEntity
|
from .entity import LinearEntity
|
||||||
|
|
||||||
SUPPORTED_SUBDEVICES = ["Light"]
|
SUPPORTED_SUBDEVICES = ["Light"]
|
||||||
@ -18,11 +16,11 @@ SUPPORTED_SUBDEVICES = ["Light"]
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: LinearConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Linear Garage Door cover."""
|
"""Set up Linear Garage Door cover."""
|
||||||
coordinator: LinearUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator = config_entry.runtime_data
|
||||||
data = coordinator.data
|
data = coordinator.data
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user