mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Migrate myuplink to runtime_data (#118960)
This commit is contained in:
parent
2a4f7439a2
commit
3d8fc96592
@ -30,10 +30,13 @@ PLATFORMS: list[Platform] = [
|
|||||||
Platform.UPDATE,
|
Platform.UPDATE,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
type MyUplinkConfigEntry = ConfigEntry[MyUplinkDataCoordinator]
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant, config_entry: MyUplinkConfigEntry
|
||||||
|
) -> bool:
|
||||||
"""Set up myUplink from a config entry."""
|
"""Set up myUplink from a config entry."""
|
||||||
hass.data.setdefault(DOMAIN, {})
|
|
||||||
|
|
||||||
implementation = (
|
implementation = (
|
||||||
await config_entry_oauth2_flow.async_get_config_entry_implementation(
|
await config_entry_oauth2_flow.async_get_config_entry_implementation(
|
||||||
@ -59,7 +62,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||||||
api = MyUplinkAPI(auth)
|
api = MyUplinkAPI(auth)
|
||||||
coordinator = MyUplinkDataCoordinator(hass, api)
|
coordinator = MyUplinkDataCoordinator(hass, api)
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
hass.data[DOMAIN][config_entry.entry_id] = coordinator
|
config_entry.runtime_data = coordinator
|
||||||
|
|
||||||
# Update device registry
|
# Update device registry
|
||||||
create_devices(hass, config_entry, coordinator)
|
create_devices(hass, config_entry, coordinator)
|
||||||
@ -71,10 +74,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||||||
|
|
||||||
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."""
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@ -100,11 +100,11 @@ def create_devices(
|
|||||||
|
|
||||||
|
|
||||||
async def async_remove_config_entry_device(
|
async def async_remove_config_entry_device(
|
||||||
hass: HomeAssistant, config_entry: ConfigEntry, device_entry: DeviceEntry
|
hass: HomeAssistant, config_entry: MyUplinkConfigEntry, device_entry: DeviceEntry
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Remove myuplink config entry from a device."""
|
"""Remove myuplink config entry from a device."""
|
||||||
|
|
||||||
myuplink_data: MyUplinkDataCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
myuplink_data = config_entry.runtime_data
|
||||||
return not device_entry.identifiers.intersection(
|
return not device_entry.identifiers.intersection(
|
||||||
(DOMAIN, device_id) for device_id in myuplink_data.data.devices
|
(DOMAIN, device_id) for device_id in myuplink_data.data.devices
|
||||||
)
|
)
|
||||||
|
@ -7,13 +7,11 @@ from homeassistant.components.binary_sensor import (
|
|||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
BinarySensorEntityDescription,
|
BinarySensorEntityDescription,
|
||||||
)
|
)
|
||||||
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.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import MyUplinkDataCoordinator
|
from . import MyUplinkConfigEntry, MyUplinkDataCoordinator
|
||||||
from .const import DOMAIN
|
|
||||||
from .entity import MyUplinkEntity, MyUplinkSystemEntity
|
from .entity import MyUplinkEntity, MyUplinkSystemEntity
|
||||||
from .helpers import find_matching_platform
|
from .helpers import find_matching_platform
|
||||||
|
|
||||||
@ -51,12 +49,12 @@ def get_description(device_point: DevicePoint) -> BinarySensorEntityDescription
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: MyUplinkConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up myUplink binary_sensor."""
|
"""Set up myUplink binary_sensor."""
|
||||||
entities: list[BinarySensorEntity] = []
|
entities: list[BinarySensorEntity] = []
|
||||||
coordinator: MyUplinkDataCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator = config_entry.runtime_data
|
||||||
|
|
||||||
# Setup device point bound sensors
|
# Setup device point bound sensors
|
||||||
for device_id, point_data in coordinator.data.points.items():
|
for device_id, point_data in coordinator.data.points.items():
|
||||||
|
@ -4,25 +4,22 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from myuplink import MyUplinkAPI
|
|
||||||
|
|
||||||
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 MyUplinkConfigEntry
|
||||||
|
|
||||||
TO_REDACT = {"access_token", "refresh_token", "serialNumber"}
|
TO_REDACT = {"access_token", "refresh_token", "serialNumber"}
|
||||||
|
|
||||||
|
|
||||||
async def async_get_config_entry_diagnostics(
|
async def async_get_config_entry_diagnostics(
|
||||||
hass: HomeAssistant, config_entry: ConfigEntry
|
hass: HomeAssistant, config_entry: MyUplinkConfigEntry
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Return diagnostics for a config entry.
|
"""Return diagnostics for a config entry.
|
||||||
|
|
||||||
Pick up fresh data from API and dump it.
|
Pick up fresh data from API and dump it.
|
||||||
"""
|
"""
|
||||||
api: MyUplinkAPI = hass.data[DOMAIN][config_entry.entry_id].api
|
api = config_entry.runtime_data.api
|
||||||
myuplink_data = {}
|
myuplink_data = {}
|
||||||
myuplink_data["my_systems"] = await api.async_get_systems_json()
|
myuplink_data["my_systems"] = await api.async_get_systems_json()
|
||||||
myuplink_data["my_systems"]["devices"] = []
|
myuplink_data["my_systems"]["devices"] = []
|
||||||
|
@ -4,14 +4,12 @@ from aiohttp import ClientError
|
|||||||
from myuplink import DevicePoint
|
from myuplink import DevicePoint
|
||||||
|
|
||||||
from homeassistant.components.number import NumberEntity, NumberEntityDescription
|
from homeassistant.components.number import NumberEntity, NumberEntityDescription
|
||||||
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.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import MyUplinkDataCoordinator
|
from . import MyUplinkConfigEntry, MyUplinkDataCoordinator
|
||||||
from .const import DOMAIN
|
|
||||||
from .entity import MyUplinkEntity
|
from .entity import MyUplinkEntity
|
||||||
from .helpers import find_matching_platform, skip_entity
|
from .helpers import find_matching_platform, skip_entity
|
||||||
|
|
||||||
@ -55,12 +53,12 @@ def get_description(device_point: DevicePoint) -> NumberEntityDescription | None
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: MyUplinkConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up myUplink number."""
|
"""Set up myUplink number."""
|
||||||
entities: list[NumberEntity] = []
|
entities: list[NumberEntity] = []
|
||||||
coordinator: MyUplinkDataCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator = config_entry.runtime_data
|
||||||
|
|
||||||
# Setup device point number entities
|
# Setup device point number entities
|
||||||
for device_id, point_data in coordinator.data.points.items():
|
for device_id, point_data in coordinator.data.points.items():
|
||||||
|
@ -8,7 +8,6 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
REVOLUTIONS_PER_MINUTE,
|
REVOLUTIONS_PER_MINUTE,
|
||||||
Platform,
|
Platform,
|
||||||
@ -25,8 +24,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from . import MyUplinkDataCoordinator
|
from . import MyUplinkConfigEntry, MyUplinkDataCoordinator
|
||||||
from .const import DOMAIN
|
|
||||||
from .entity import MyUplinkEntity
|
from .entity import MyUplinkEntity
|
||||||
from .helpers import find_matching_platform, skip_entity
|
from .helpers import find_matching_platform, skip_entity
|
||||||
|
|
||||||
@ -187,13 +185,13 @@ def get_description(device_point: DevicePoint) -> SensorEntityDescription | None
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: MyUplinkConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up myUplink sensor."""
|
"""Set up myUplink sensor."""
|
||||||
|
|
||||||
entities: list[SensorEntity] = []
|
entities: list[SensorEntity] = []
|
||||||
coordinator: MyUplinkDataCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator = config_entry.runtime_data
|
||||||
|
|
||||||
# Setup device point sensors
|
# Setup device point sensors
|
||||||
for device_id, point_data in coordinator.data.points.items():
|
for device_id, point_data in coordinator.data.points.items():
|
||||||
|
@ -6,14 +6,12 @@ import aiohttp
|
|||||||
from myuplink import DevicePoint
|
from myuplink import DevicePoint
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
|
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
|
||||||
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.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import MyUplinkDataCoordinator
|
from . import MyUplinkConfigEntry, MyUplinkDataCoordinator
|
||||||
from .const import DOMAIN
|
|
||||||
from .entity import MyUplinkEntity
|
from .entity import MyUplinkEntity
|
||||||
from .helpers import find_matching_platform, skip_entity
|
from .helpers import find_matching_platform, skip_entity
|
||||||
|
|
||||||
@ -44,12 +42,12 @@ def get_description(device_point: DevicePoint) -> SwitchEntityDescription | None
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: MyUplinkConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up myUplink switch."""
|
"""Set up myUplink switch."""
|
||||||
entities: list[SwitchEntity] = []
|
entities: list[SwitchEntity] = []
|
||||||
coordinator: MyUplinkDataCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator = config_entry.runtime_data
|
||||||
|
|
||||||
# Setup device point switches
|
# Setup device point switches
|
||||||
for device_id, point_data in coordinator.data.points.items():
|
for device_id, point_data in coordinator.data.points.items():
|
||||||
|
@ -5,12 +5,10 @@ from homeassistant.components.update import (
|
|||||||
UpdateEntity,
|
UpdateEntity,
|
||||||
UpdateEntityDescription,
|
UpdateEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
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 . import MyUplinkDataCoordinator
|
from . import MyUplinkConfigEntry, MyUplinkDataCoordinator
|
||||||
from .const import DOMAIN
|
|
||||||
from .entity import MyUplinkEntity
|
from .entity import MyUplinkEntity
|
||||||
|
|
||||||
UPDATE_DESCRIPTION = UpdateEntityDescription(
|
UPDATE_DESCRIPTION = UpdateEntityDescription(
|
||||||
@ -21,11 +19,11 @@ UPDATE_DESCRIPTION = UpdateEntityDescription(
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: MyUplinkConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up update entity."""
|
"""Set up update entity."""
|
||||||
coordinator: MyUplinkDataCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator = config_entry.runtime_data
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
MyUplinkDeviceUpdate(
|
MyUplinkDeviceUpdate(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user