mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Explicitly pass in the config_entry in upnp coordinator (#137885)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
999badf675
commit
f643f76f1f
@ -8,7 +8,6 @@ from datetime import timedelta
|
|||||||
from async_upnp_client.exceptions import UpnpConnectionError
|
from async_upnp_client.exceptions import UpnpConnectionError
|
||||||
|
|
||||||
from homeassistant.components import ssdp
|
from homeassistant.components import ssdp
|
||||||
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 ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
@ -28,7 +27,7 @@ from .const import (
|
|||||||
IDENTIFIER_SERIAL_NUMBER,
|
IDENTIFIER_SERIAL_NUMBER,
|
||||||
LOGGER,
|
LOGGER,
|
||||||
)
|
)
|
||||||
from .coordinator import UpnpDataUpdateCoordinator
|
from .coordinator import UpnpConfigEntry, UpnpDataUpdateCoordinator
|
||||||
from .device import async_create_device, get_preferred_location
|
from .device import async_create_device, get_preferred_location
|
||||||
|
|
||||||
NOTIFICATION_ID = "upnp_notification"
|
NOTIFICATION_ID = "upnp_notification"
|
||||||
@ -37,9 +36,6 @@ NOTIFICATION_TITLE = "UPnP/IGD Setup"
|
|||||||
PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR]
|
PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR]
|
||||||
|
|
||||||
|
|
||||||
type UpnpConfigEntry = ConfigEntry[UpnpDataUpdateCoordinator]
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: UpnpConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: UpnpConfigEntry) -> bool:
|
||||||
"""Set up UPnP/IGD device from a config entry."""
|
"""Set up UPnP/IGD device from a config entry."""
|
||||||
LOGGER.debug("Setting up config entry: %s", entry.entry_id)
|
LOGGER.debug("Setting up config entry: %s", entry.entry_id)
|
||||||
@ -176,6 +172,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: UpnpConfigEntry) -> bool
|
|||||||
update_interval = timedelta(seconds=DEFAULT_SCAN_INTERVAL)
|
update_interval = timedelta(seconds=DEFAULT_SCAN_INTERVAL)
|
||||||
coordinator = UpnpDataUpdateCoordinator(
|
coordinator = UpnpDataUpdateCoordinator(
|
||||||
hass,
|
hass,
|
||||||
|
config_entry=entry,
|
||||||
device=device,
|
device=device,
|
||||||
device_entry=device_entry,
|
device_entry=device_entry,
|
||||||
update_interval=update_interval,
|
update_interval=update_interval,
|
||||||
@ -193,7 +190,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: UpnpConfigEntry) -> bool
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: UpnpConfigEntry) -> bool:
|
||||||
"""Unload a UPnP/IGD device from a config entry."""
|
"""Unload a UPnP/IGD device from a config entry."""
|
||||||
LOGGER.debug("Unloading config entry: %s", entry.entry_id)
|
LOGGER.debug("Unloading config entry: %s", entry.entry_id)
|
||||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
@ -13,8 +13,8 @@ from homeassistant.const import EntityCategory
|
|||||||
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 UpnpConfigEntry, UpnpDataUpdateCoordinator
|
|
||||||
from .const import LOGGER, WAN_STATUS
|
from .const import LOGGER, WAN_STATUS
|
||||||
|
from .coordinator import UpnpConfigEntry, UpnpDataUpdateCoordinator
|
||||||
from .entity import UpnpEntity, UpnpEntityDescription
|
from .entity import UpnpEntity, UpnpEntityDescription
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ from datetime import datetime, timedelta
|
|||||||
|
|
||||||
from async_upnp_client.exceptions import UpnpCommunicationError
|
from async_upnp_client.exceptions import UpnpCommunicationError
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceEntry
|
from homeassistant.helpers.device_registry import DeviceEntry
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
@ -13,15 +14,20 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
|
|||||||
from .const import LOGGER
|
from .const import LOGGER
|
||||||
from .device import Device
|
from .device import Device
|
||||||
|
|
||||||
|
type UpnpConfigEntry = ConfigEntry[UpnpDataUpdateCoordinator]
|
||||||
|
|
||||||
|
|
||||||
class UpnpDataUpdateCoordinator(
|
class UpnpDataUpdateCoordinator(
|
||||||
DataUpdateCoordinator[dict[str, str | datetime | int | float | None]]
|
DataUpdateCoordinator[dict[str, str | datetime | int | float | None]]
|
||||||
):
|
):
|
||||||
"""Define an object to update data from UPNP device."""
|
"""Define an object to update data from UPNP device."""
|
||||||
|
|
||||||
|
config_entry: UpnpConfigEntry
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
config_entry: UpnpConfigEntry,
|
||||||
device: Device,
|
device: Device,
|
||||||
device_entry: DeviceEntry,
|
device_entry: DeviceEntry,
|
||||||
update_interval: timedelta,
|
update_interval: timedelta,
|
||||||
@ -34,6 +40,7 @@ class UpnpDataUpdateCoordinator(
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
LOGGER,
|
LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name=device.name,
|
name=device.name,
|
||||||
update_interval=update_interval,
|
update_interval=update_interval,
|
||||||
)
|
)
|
||||||
|
@ -20,7 +20,6 @@ from homeassistant.const import (
|
|||||||
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 UpnpConfigEntry
|
|
||||||
from .const import (
|
from .const import (
|
||||||
BYTES_RECEIVED,
|
BYTES_RECEIVED,
|
||||||
BYTES_SENT,
|
BYTES_SENT,
|
||||||
@ -38,6 +37,7 @@ from .const import (
|
|||||||
ROUTER_UPTIME,
|
ROUTER_UPTIME,
|
||||||
WAN_STATUS,
|
WAN_STATUS,
|
||||||
)
|
)
|
||||||
|
from .coordinator import UpnpConfigEntry
|
||||||
from .entity import UpnpEntity, UpnpEntityDescription
|
from .entity import UpnpEntity, UpnpEntityDescription
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user