mirror of
https://github.com/home-assistant/core.git
synced 2025-06-26 07:57:12 +00:00
Use runtime_data for acmeda (#116606)
This commit is contained in:
parent
8eb1970721
commit
64d9fac6db
@ -4,30 +4,35 @@ 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 .const import DOMAIN
|
|
||||||
from .hub import PulseHub
|
from .hub import PulseHub
|
||||||
|
|
||||||
CONF_HUBS = "hubs"
|
CONF_HUBS = "hubs"
|
||||||
|
|
||||||
PLATFORMS = [Platform.COVER, Platform.SENSOR]
|
PLATFORMS = [Platform.COVER, Platform.SENSOR]
|
||||||
|
|
||||||
|
AcmedaConfigEntry = ConfigEntry[PulseHub]
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant, config_entry: AcmedaConfigEntry
|
||||||
|
) -> bool:
|
||||||
"""Set up Rollease Acmeda Automate hub from a config entry."""
|
"""Set up Rollease Acmeda Automate hub from a config entry."""
|
||||||
hub = PulseHub(hass, config_entry)
|
hub = PulseHub(hass, config_entry)
|
||||||
|
|
||||||
if not await hub.async_setup():
|
if not await hub.async_setup():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})[config_entry.entry_id] = hub
|
config_entry.runtime_data = hub
|
||||||
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
async def async_unload_entry(
|
||||||
|
hass: HomeAssistant, config_entry: AcmedaConfigEntry
|
||||||
|
) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
hub = hass.data[DOMAIN][config_entry.entry_id]
|
hub = config_entry.runtime_data
|
||||||
|
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
config_entry, PLATFORMS
|
config_entry, PLATFORMS
|
||||||
@ -36,7 +41,4 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
|
|||||||
if not await hub.async_reset():
|
if not await hub.async_reset():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if unload_ok:
|
|
||||||
hass.data[DOMAIN].pop(config_entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
@ -9,24 +9,23 @@ from homeassistant.components.cover import (
|
|||||||
CoverEntity,
|
CoverEntity,
|
||||||
CoverEntityFeature,
|
CoverEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from . import AcmedaConfigEntry
|
||||||
from .base import AcmedaBase
|
from .base import AcmedaBase
|
||||||
from .const import ACMEDA_HUB_UPDATE, DOMAIN
|
from .const import ACMEDA_HUB_UPDATE
|
||||||
from .helpers import async_add_acmeda_entities
|
from .helpers import async_add_acmeda_entities
|
||||||
from .hub import PulseHub
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: AcmedaConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Acmeda Rollers from a config entry."""
|
"""Set up the Acmeda Rollers from a config entry."""
|
||||||
hub: PulseHub = hass.data[DOMAIN][config_entry.entry_id]
|
hub = config_entry.runtime_data
|
||||||
|
|
||||||
current: set[int] = set()
|
current: set[int] = set()
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from aiopulse import Roller
|
from aiopulse import Roller
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -11,17 +13,20 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
|
|
||||||
from .const import DOMAIN, LOGGER
|
from .const import DOMAIN, LOGGER
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from . import AcmedaConfigEntry
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_acmeda_entities(
|
def async_add_acmeda_entities(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entity_class: type,
|
entity_class: type,
|
||||||
config_entry: ConfigEntry,
|
config_entry: AcmedaConfigEntry,
|
||||||
current: set[int],
|
current: set[int],
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Add any new entities."""
|
"""Add any new entities."""
|
||||||
hub = hass.data[DOMAIN][config_entry.entry_id]
|
hub = config_entry.runtime_data
|
||||||
LOGGER.debug("Looking for new %s on: %s", entity_class.__name__, hub.host)
|
LOGGER.debug("Looking for new %s on: %s", entity_class.__name__, hub.host)
|
||||||
|
|
||||||
api = hub.api.rollers
|
api = hub.api.rollers
|
||||||
|
@ -3,25 +3,24 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import PERCENTAGE
|
from homeassistant.const import PERCENTAGE
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from . import AcmedaConfigEntry
|
||||||
from .base import AcmedaBase
|
from .base import AcmedaBase
|
||||||
from .const import ACMEDA_HUB_UPDATE, DOMAIN
|
from .const import ACMEDA_HUB_UPDATE
|
||||||
from .helpers import async_add_acmeda_entities
|
from .helpers import async_add_acmeda_entities
|
||||||
from .hub import PulseHub
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: AcmedaConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Acmeda Rollers from a config entry."""
|
"""Set up the Acmeda Rollers from a config entry."""
|
||||||
hub: PulseHub = hass.data[DOMAIN][config_entry.entry_id]
|
hub = config_entry.runtime_data
|
||||||
|
|
||||||
current: set[int] = set()
|
current: set[int] = set()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user