Store runtime data inside the config entry in Upnp (#117030)
store runtime data inside the config entry
This commit is contained in:
parent
35d44ec90a
commit
7f7d025b44
3 changed files with 12 additions and 21 deletions
|
@ -36,13 +36,13 @@ PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR]
|
|||
|
||||
CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False)
|
||||
|
||||
UpnpConfigEntry = ConfigEntry[UpnpDataUpdateCoordinator]
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: UpnpConfigEntry) -> bool:
|
||||
"""Set up UPnP/IGD device from a config entry."""
|
||||
LOGGER.debug("Setting up config entry: %s", entry.entry_id)
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
|
||||
udn = entry.data[CONFIG_ENTRY_UDN]
|
||||
st = entry.data[CONFIG_ENTRY_ST]
|
||||
usn = f"{udn}::{st}"
|
||||
|
@ -168,7 +168,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
# Save coordinator.
|
||||
hass.data[DOMAIN][entry.entry_id] = coordinator
|
||||
entry.runtime_data = coordinator
|
||||
|
||||
# Setup platforms, creating sensors/binary_sensors.
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
|
@ -179,10 +179,4 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a UPnP/IGD device from a config entry."""
|
||||
LOGGER.debug("Unloading config entry: %s", entry.entry_id)
|
||||
|
||||
# Unload platforms.
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
if unload_ok:
|
||||
del hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
return unload_ok
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
|
|
@ -9,13 +9,12 @@ from homeassistant.components.binary_sensor import (
|
|||
BinarySensorEntity,
|
||||
BinarySensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import UpnpDataUpdateCoordinator
|
||||
from .const import DOMAIN, LOGGER, WAN_STATUS
|
||||
from . import UpnpConfigEntry, UpnpDataUpdateCoordinator
|
||||
from .const import LOGGER, WAN_STATUS
|
||||
from .entity import UpnpEntity, UpnpEntityDescription
|
||||
|
||||
|
||||
|
@ -38,11 +37,11 @@ SENSOR_DESCRIPTIONS: tuple[UpnpBinarySensorEntityDescription, ...] = (
|
|||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: UpnpConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the UPnP/IGD sensors."""
|
||||
coordinator: UpnpDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
coordinator = config_entry.runtime_data
|
||||
|
||||
entities = [
|
||||
UpnpStatusBinarySensor(
|
||||
|
|
|
@ -11,7 +11,6 @@ from homeassistant.components.sensor import (
|
|||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
EntityCategory,
|
||||
UnitOfDataRate,
|
||||
|
@ -21,12 +20,12 @@ from homeassistant.const import (
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import UpnpConfigEntry
|
||||
from .const import (
|
||||
BYTES_RECEIVED,
|
||||
BYTES_SENT,
|
||||
DATA_PACKETS,
|
||||
DATA_RATE_PACKETS_PER_SECOND,
|
||||
DOMAIN,
|
||||
KIBIBYTES_PER_SEC_RECEIVED,
|
||||
KIBIBYTES_PER_SEC_SENT,
|
||||
LOGGER,
|
||||
|
@ -38,7 +37,6 @@ from .const import (
|
|||
ROUTER_UPTIME,
|
||||
WAN_STATUS,
|
||||
)
|
||||
from .coordinator import UpnpDataUpdateCoordinator
|
||||
from .entity import UpnpEntity, UpnpEntityDescription
|
||||
|
||||
|
||||
|
@ -146,11 +144,11 @@ SENSOR_DESCRIPTIONS: tuple[UpnpSensorEntityDescription, ...] = (
|
|||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: UpnpConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the UPnP/IGD sensors."""
|
||||
coordinator: UpnpDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
coordinator = config_entry.runtime_data
|
||||
|
||||
entities: list[UpnpSensor] = [
|
||||
UpnpSensor(
|
||||
|
|
Loading…
Add table
Reference in a new issue