mirror of
https://github.com/home-assistant/core.git
synced 2025-07-07 13:27:09 +00:00
Migrate lutron to use runtime_data (#147198)
This commit is contained in:
parent
313eaff14e
commit
1b60ea8951
@ -29,6 +29,8 @@ ATTR_ACTION = "action"
|
||||
ATTR_FULL_ID = "full_id"
|
||||
ATTR_UUID = "uuid"
|
||||
|
||||
type LutronConfigEntry = ConfigEntry[LutronData]
|
||||
|
||||
|
||||
@dataclass(slots=True, kw_only=True)
|
||||
class LutronData:
|
||||
@ -44,7 +46,9 @@ class LutronData:
|
||||
switches: list[tuple[str, Output]]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, config_entry: LutronConfigEntry
|
||||
) -> bool:
|
||||
"""Set up the Lutron integration."""
|
||||
|
||||
host = config_entry.data[CONF_HOST]
|
||||
@ -169,7 +173,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||
name="Main repeater",
|
||||
)
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})[config_entry.entry_id] = entry_data
|
||||
config_entry.runtime_data = entry_data
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
||||
|
||||
@ -222,6 +226,6 @@ def _async_check_device_identifiers(
|
||||
)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: LutronConfigEntry) -> bool:
|
||||
"""Clean up resources and entities associated with the integration."""
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
@ -3,7 +3,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from pylutron import OccupancyGroup
|
||||
@ -12,19 +11,16 @@ from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import DOMAIN, LutronData
|
||||
from . import LutronConfigEntry
|
||||
from .entity import LutronDevice
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: LutronConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Lutron binary_sensor platform.
|
||||
@ -32,7 +28,7 @@ async def async_setup_entry(
|
||||
Adds occupancy groups from the Main Repeater associated with the
|
||||
config_entry as binary_sensor entities.
|
||||
"""
|
||||
entry_data: LutronData = hass.data[DOMAIN][config_entry.entry_id]
|
||||
entry_data = config_entry.runtime_data
|
||||
async_add_entities(
|
||||
[
|
||||
LutronOccupancySensor(area_name, device, entry_data.client)
|
||||
|
@ -9,12 +9,7 @@ from urllib.error import HTTPError
|
||||
from pylutron import Lutron
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import (
|
||||
ConfigEntry,
|
||||
ConfigFlow,
|
||||
ConfigFlowResult,
|
||||
OptionsFlow,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult, OptionsFlow
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.selector import (
|
||||
@ -23,6 +18,7 @@ from homeassistant.helpers.selector import (
|
||||
NumberSelectorMode,
|
||||
)
|
||||
|
||||
from . import LutronConfigEntry
|
||||
from .const import CONF_DEFAULT_DIMMER_LEVEL, DEFAULT_DIMMER_LEVEL, DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -83,7 +79,7 @@ class LutronConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
@staticmethod
|
||||
@callback
|
||||
def async_get_options_flow(
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: LutronConfigEntry,
|
||||
) -> OptionsFlowHandler:
|
||||
"""Get the options flow for this handler."""
|
||||
return OptionsFlowHandler()
|
||||
|
@ -13,11 +13,10 @@ from homeassistant.components.cover import (
|
||||
CoverEntity,
|
||||
CoverEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import DOMAIN, LutronData
|
||||
from . import LutronConfigEntry
|
||||
from .entity import LutronDevice
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -25,7 +24,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: LutronConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Lutron cover platform.
|
||||
@ -33,7 +32,7 @@ async def async_setup_entry(
|
||||
Adds shades from the Main Repeater associated with the config_entry as
|
||||
cover entities.
|
||||
"""
|
||||
entry_data: LutronData = hass.data[DOMAIN][config_entry.entry_id]
|
||||
entry_data = config_entry.runtime_data
|
||||
async_add_entities(
|
||||
[
|
||||
LutronCover(area_name, device, entry_data.client)
|
||||
|
@ -5,13 +5,12 @@ from enum import StrEnum
|
||||
from pylutron import Button, Keypad, Lutron, LutronEvent
|
||||
|
||||
from homeassistant.components.event import EventEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_ID
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.util import slugify
|
||||
|
||||
from . import ATTR_ACTION, ATTR_FULL_ID, ATTR_UUID, DOMAIN, LutronData
|
||||
from . import ATTR_ACTION, ATTR_FULL_ID, ATTR_UUID, LutronConfigEntry
|
||||
from .entity import LutronKeypad
|
||||
|
||||
|
||||
@ -32,11 +31,11 @@ LEGACY_EVENT_TYPES: dict[LutronEventType, str] = {
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: LutronConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Lutron event platform."""
|
||||
entry_data: LutronData = hass.data[DOMAIN][config_entry.entry_id]
|
||||
entry_data = config_entry.runtime_data
|
||||
|
||||
async_add_entities(
|
||||
LutronEventEntity(area_name, keypad, button, entry_data.client)
|
||||
|
@ -2,25 +2,21 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from pylutron import Output
|
||||
|
||||
from homeassistant.components.fan import FanEntity, FanEntityFeature
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import DOMAIN, LutronData
|
||||
from . import LutronConfigEntry
|
||||
from .entity import LutronDevice
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: LutronConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Lutron fan platform.
|
||||
@ -28,7 +24,7 @@ async def async_setup_entry(
|
||||
Adds fan controls from the Main Repeater associated with the config_entry as
|
||||
fan entities.
|
||||
"""
|
||||
entry_data: LutronData = hass.data[DOMAIN][config_entry.entry_id]
|
||||
entry_data = config_entry.runtime_data
|
||||
async_add_entities(
|
||||
[
|
||||
LutronFan(area_name, device, entry_data.client)
|
||||
|
@ -19,14 +19,14 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import DOMAIN, LutronData
|
||||
from . import LutronConfigEntry
|
||||
from .const import CONF_DEFAULT_DIMMER_LEVEL, DEFAULT_DIMMER_LEVEL
|
||||
from .entity import LutronDevice
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: LutronConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Lutron light platform.
|
||||
@ -34,7 +34,7 @@ async def async_setup_entry(
|
||||
Adds dimmers from the Main Repeater associated with the config_entry as
|
||||
light entities.
|
||||
"""
|
||||
entry_data: LutronData = hass.data[DOMAIN][config_entry.entry_id]
|
||||
entry_data = config_entry.runtime_data
|
||||
|
||||
async_add_entities(
|
||||
(
|
||||
|
@ -7,17 +7,16 @@ from typing import Any
|
||||
from pylutron import Button, Keypad, Lutron
|
||||
|
||||
from homeassistant.components.scene import Scene
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import DOMAIN, LutronData
|
||||
from . import LutronConfigEntry
|
||||
from .entity import LutronKeypad
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: LutronConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Lutron scene platform.
|
||||
@ -25,7 +24,7 @@ async def async_setup_entry(
|
||||
Adds scenes from the Main Repeater associated with the config_entry as
|
||||
scene entities.
|
||||
"""
|
||||
entry_data: LutronData = hass.data[DOMAIN][config_entry.entry_id]
|
||||
entry_data = config_entry.runtime_data
|
||||
|
||||
async_add_entities(
|
||||
LutronScene(area_name, keypad, device, entry_data.client)
|
||||
|
@ -8,17 +8,16 @@ from typing import Any
|
||||
from pylutron import Button, Keypad, Led, Lutron, Output
|
||||
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import DOMAIN, LutronData
|
||||
from . import LutronConfigEntry
|
||||
from .entity import LutronDevice, LutronKeypad
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: LutronConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Lutron switch platform.
|
||||
@ -26,7 +25,7 @@ async def async_setup_entry(
|
||||
Adds switches from the Main Repeater associated with the config_entry as
|
||||
switch entities.
|
||||
"""
|
||||
entry_data: LutronData = hass.data[DOMAIN][config_entry.entry_id]
|
||||
entry_data = config_entry.runtime_data
|
||||
entities: list[SwitchEntity] = []
|
||||
|
||||
# Add Lutron Switches
|
||||
|
Loading…
x
Reference in New Issue
Block a user