Migrate hunterdouglas_powerview to use entry.runtime_data (#121887)
This commit is contained in:
parent
2dec7136c8
commit
62613af033
10 changed files with 46 additions and 69 deletions
|
@ -9,7 +9,6 @@ from aiopvapi.rooms import Rooms
|
|||
from aiopvapi.scenes import Scenes
|
||||
from aiopvapi.shades import Shades
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_API_VERSION, CONF_HOST, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
|
@ -18,7 +17,7 @@ import homeassistant.helpers.config_validation as cv
|
|||
|
||||
from .const import DOMAIN, HUB_EXCEPTIONS
|
||||
from .coordinator import PowerviewShadeUpdateCoordinator
|
||||
from .model import PowerviewDeviceInfo, PowerviewEntryData
|
||||
from .model import PowerviewConfigEntry, PowerviewDeviceInfo, PowerviewEntryData
|
||||
from .shade_data import PowerviewShadeData
|
||||
|
||||
PARALLEL_UPDATES = 1
|
||||
|
@ -36,7 +35,7 @@ PLATFORMS = [
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: PowerviewConfigEntry) -> bool:
|
||||
"""Set up Hunter Douglas PowerView from a config entry."""
|
||||
|
||||
config = entry.data
|
||||
|
@ -100,7 +99,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
# populate raw shade data into the coordinator for diagnostics
|
||||
coordinator.data.store_group_data(shade_data)
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = PowerviewEntryData(
|
||||
entry.runtime_data = PowerviewEntryData(
|
||||
api=pv_request,
|
||||
room_data=room_data.processed,
|
||||
scene_data=scene_data.processed,
|
||||
|
@ -126,8 +125,6 @@ async def async_get_device_info(hub: Hub) -> PowerviewDeviceInfo:
|
|||
)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: PowerviewConfigEntry) -> 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)
|
||||
|
|
|
@ -20,15 +20,13 @@ from homeassistant.components.button import (
|
|||
ButtonEntity,
|
||||
ButtonEntityDescription,
|
||||
)
|
||||
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 .coordinator import PowerviewShadeUpdateCoordinator
|
||||
from .entity import ShadeEntity
|
||||
from .model import PowerviewDeviceInfo, PowerviewEntryData
|
||||
from .model import PowerviewConfigEntry, PowerviewDeviceInfo
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
|
@ -75,13 +73,11 @@ BUTTONS_SHADE: Final = [
|
|||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: PowerviewConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the hunter douglas advanced feature buttons."""
|
||||
|
||||
pv_entry: PowerviewEntryData = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
pv_entry = entry.runtime_data
|
||||
entities: list[ButtonEntity] = []
|
||||
for shade in pv_entry.shade_data.values():
|
||||
room_name = getattr(pv_entry.room_data.get(shade.room_id), ATTR_NAME, "")
|
||||
|
|
|
@ -25,15 +25,14 @@ from homeassistant.components.cover import (
|
|||
CoverEntity,
|
||||
CoverEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import async_call_later
|
||||
|
||||
from .const import DOMAIN, STATE_ATTRIBUTE_ROOM_NAME
|
||||
from .const import STATE_ATTRIBUTE_ROOM_NAME
|
||||
from .coordinator import PowerviewShadeUpdateCoordinator
|
||||
from .entity import ShadeEntity
|
||||
from .model import PowerviewDeviceInfo, PowerviewEntryData
|
||||
from .model import PowerviewConfigEntry, PowerviewDeviceInfo
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -49,12 +48,13 @@ SCAN_INTERVAL = timedelta(minutes=10)
|
|||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
hass: HomeAssistant,
|
||||
entry: PowerviewConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the hunter douglas shades."""
|
||||
|
||||
pv_entry: PowerviewEntryData = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator: PowerviewShadeUpdateCoordinator = pv_entry.coordinator
|
||||
pv_entry = entry.runtime_data
|
||||
coordinator = pv_entry.coordinator
|
||||
|
||||
async def _async_initial_refresh() -> None:
|
||||
"""Force position refresh shortly after adding.
|
||||
|
|
|
@ -3,20 +3,18 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from dataclasses import asdict
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import attr
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_CONFIGURATION_URL, CONF_HOST
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers.device_registry import DeviceEntry
|
||||
|
||||
from .const import DOMAIN, REDACT_HUB_ADDRESS, REDACT_MAC_ADDRESS, REDACT_SERIAL_NUMBER
|
||||
from .model import PowerviewEntryData
|
||||
from .const import REDACT_HUB_ADDRESS, REDACT_MAC_ADDRESS, REDACT_SERIAL_NUMBER
|
||||
from .model import PowerviewConfigEntry
|
||||
|
||||
REDACT_CONFIG = {
|
||||
CONF_HOST,
|
||||
|
@ -26,11 +24,9 @@ REDACT_CONFIG = {
|
|||
ATTR_CONFIGURATION_URL,
|
||||
}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
hass: HomeAssistant, entry: PowerviewConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
data = _async_get_diagnostics(hass, entry)
|
||||
|
@ -47,7 +43,7 @@ async def async_get_config_entry_diagnostics(
|
|||
|
||||
|
||||
async def async_get_device_diagnostics(
|
||||
hass: HomeAssistant, entry: ConfigEntry, device: DeviceEntry
|
||||
hass: HomeAssistant, entry: PowerviewConfigEntry, device: DeviceEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a device entry."""
|
||||
data = _async_get_diagnostics(hass, entry)
|
||||
|
@ -65,10 +61,10 @@ async def async_get_device_diagnostics(
|
|||
@callback
|
||||
def _async_get_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: PowerviewConfigEntry,
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
pv_entry: PowerviewEntryData = hass.data[DOMAIN][entry.entry_id]
|
||||
pv_entry = entry.runtime_data
|
||||
shade_data = pv_entry.coordinator.data.get_all_raw_data()
|
||||
hub_info = async_redact_data(asdict(pv_entry.device_info), REDACT_CONFIG)
|
||||
return {"hub_info": hub_info, "shade_data": shade_data}
|
||||
|
|
|
@ -9,8 +9,12 @@ from aiopvapi.resources.room import Room
|
|||
from aiopvapi.resources.scene import Scene
|
||||
from aiopvapi.resources.shade import BaseShade
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
|
||||
from .coordinator import PowerviewShadeUpdateCoordinator
|
||||
|
||||
type PowerviewConfigEntry = ConfigEntry[PowerviewEntryData]
|
||||
|
||||
|
||||
@dataclass
|
||||
class PowerviewEntryData:
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
import logging
|
||||
from typing import Final
|
||||
|
||||
from aiopvapi.helpers.constants import ATTR_NAME, MOTION_VELOCITY
|
||||
|
@ -13,17 +12,13 @@ from homeassistant.components.number import (
|
|||
NumberMode,
|
||||
RestoreNumber,
|
||||
)
|
||||
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 .coordinator import PowerviewShadeUpdateCoordinator
|
||||
from .entity import ShadeEntity
|
||||
from .model import PowerviewDeviceInfo, PowerviewEntryData
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
from .model import PowerviewConfigEntry, PowerviewDeviceInfo
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
|
@ -57,12 +52,12 @@ NUMBERS: Final = (
|
|||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
hass: HomeAssistant,
|
||||
entry: PowerviewConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the hunter douglas number entities."""
|
||||
|
||||
pv_entry: PowerviewEntryData = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
pv_entry = entry.runtime_data
|
||||
entities: list[PowerViewNumber] = []
|
||||
for shade in pv_entry.shade_data.values():
|
||||
room_name = getattr(pv_entry.room_data.get(shade.room_id), ATTR_NAME, "")
|
||||
|
|
|
@ -9,14 +9,13 @@ from aiopvapi.helpers.constants import ATTR_NAME
|
|||
from aiopvapi.resources.scene import Scene as PvScene
|
||||
|
||||
from homeassistant.components.scene import Scene
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN, STATE_ATTRIBUTE_ROOM_NAME
|
||||
from .const import STATE_ATTRIBUTE_ROOM_NAME
|
||||
from .coordinator import PowerviewShadeUpdateCoordinator
|
||||
from .entity import HDEntity
|
||||
from .model import PowerviewDeviceInfo, PowerviewEntryData
|
||||
from .model import PowerviewConfigEntry, PowerviewDeviceInfo
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -24,12 +23,12 @@ RESYNC_DELAY = 60
|
|||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
hass: HomeAssistant,
|
||||
entry: PowerviewConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up powerview scene entries."""
|
||||
|
||||
pv_entry: PowerviewEntryData = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
pv_entry = entry.runtime_data
|
||||
pvscenes: list[PowerViewScene] = []
|
||||
for scene in pv_entry.scene_data.values():
|
||||
room_name = getattr(pv_entry.room_data.get(scene.room_id), ATTR_NAME, "")
|
||||
|
|
|
@ -4,24 +4,19 @@ from __future__ import annotations
|
|||
|
||||
from collections.abc import Callable, Coroutine
|
||||
from dataclasses import dataclass
|
||||
import logging
|
||||
from typing import Any, Final
|
||||
|
||||
from aiopvapi.helpers.constants import ATTR_NAME, FUNCTION_SET_POWER
|
||||
from aiopvapi.resources.shade import BaseShade
|
||||
|
||||
from homeassistant.components.select import SelectEntity, SelectEntityDescription
|
||||
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 .coordinator import PowerviewShadeUpdateCoordinator
|
||||
from .entity import ShadeEntity
|
||||
from .model import PowerviewDeviceInfo, PowerviewEntryData
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
from .model import PowerviewConfigEntry, PowerviewDeviceInfo
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
|
@ -57,12 +52,12 @@ DROPDOWNS: Final = [
|
|||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
hass: HomeAssistant,
|
||||
entry: PowerviewConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the hunter douglas select entities."""
|
||||
|
||||
pv_entry: PowerviewEntryData = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
pv_entry = entry.runtime_data
|
||||
entities: list[PowerViewSelect] = []
|
||||
for shade in pv_entry.shade_data.values():
|
||||
if not shade.has_battery_info():
|
||||
|
|
|
@ -13,15 +13,13 @@ from homeassistant.components.sensor import (
|
|||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import PERCENTAGE, SIGNAL_STRENGTH_DECIBELS, EntityCategory
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import PowerviewShadeUpdateCoordinator
|
||||
from .entity import ShadeEntity
|
||||
from .model import PowerviewDeviceInfo, PowerviewEntryData
|
||||
from .model import PowerviewConfigEntry, PowerviewDeviceInfo
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
|
@ -79,12 +77,12 @@ SENSORS: Final = [
|
|||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
hass: HomeAssistant,
|
||||
entry: PowerviewConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the hunter douglas sensor entities."""
|
||||
|
||||
pv_entry: PowerviewEntryData = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
pv_entry = entry.runtime_data
|
||||
entities: list[PowerViewSensor] = []
|
||||
for shade in pv_entry.shade_data.values():
|
||||
room_name = getattr(pv_entry.room_data.get(shade.room_id), ATTR_NAME, "")
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from dataclasses import fields
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from aiopvapi.resources.model import PowerviewData
|
||||
|
@ -11,8 +10,6 @@ from aiopvapi.resources.shade import BaseShade, ShadePosition
|
|||
|
||||
from .util import async_map_data_by_id
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
POSITION_FIELDS = [field for field in fields(ShadePosition) if field.name != "velocity"]
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue