mirror of
https://github.com/home-assistant/core.git
synced 2025-04-29 03:37:51 +00:00
Use runtime data in Vodafone Station (#140464)
* Use runtime data in Vodafone Station * specialize config entry * revert unwanted change
This commit is contained in:
parent
bc6eb94c0d
commit
3bba781554
@ -1,16 +1,15 @@
|
|||||||
"""Vodafone Station integration."""
|
"""Vodafone Station integration."""
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import VodafoneStationRouter
|
from .coordinator import VodafoneConfigEntry, VodafoneStationRouter
|
||||||
|
|
||||||
PLATFORMS = [Platform.BUTTON, Platform.DEVICE_TRACKER, Platform.SENSOR]
|
PLATFORMS = [Platform.BUTTON, Platform.DEVICE_TRACKER, Platform.SENSOR]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: VodafoneConfigEntry) -> bool:
|
||||||
"""Set up Vodafone Station platform."""
|
"""Set up Vodafone Station platform."""
|
||||||
coordinator = VodafoneStationRouter(
|
coordinator = VodafoneStationRouter(
|
||||||
hass,
|
hass,
|
||||||
@ -22,7 +21,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
entry.runtime_data = coordinator
|
||||||
|
|
||||||
entry.async_on_unload(entry.add_update_listener(update_listener))
|
entry.async_on_unload(entry.add_update_listener(update_listener))
|
||||||
|
|
||||||
@ -31,10 +30,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: VodafoneConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
||||||
coordinator: VodafoneStationRouter = hass.data[DOMAIN][entry.entry_id]
|
coordinator = entry.runtime_data
|
||||||
await coordinator.api.logout()
|
await coordinator.api.logout()
|
||||||
await coordinator.api.close()
|
await coordinator.api.close()
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
@ -42,7 +41,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
async def update_listener(hass: HomeAssistant, entry: VodafoneConfigEntry) -> None:
|
||||||
"""Update when config_entry options update."""
|
"""Update when config_entry options update."""
|
||||||
if entry.options:
|
if entry.options:
|
||||||
await hass.config_entries.async_reload(entry.entry_id)
|
await hass.config_entries.async_reload(entry.entry_id)
|
||||||
|
@ -11,14 +11,13 @@ from homeassistant.components.button import (
|
|||||||
ButtonEntity,
|
ButtonEntity,
|
||||||
ButtonEntityDescription,
|
ButtonEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import EntityCategory
|
from homeassistant.const import EntityCategory
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import _LOGGER, DOMAIN
|
from .const import _LOGGER
|
||||||
from .coordinator import VodafoneStationRouter
|
from .coordinator import VodafoneConfigEntry, VodafoneStationRouter
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, kw_only=True)
|
@dataclass(frozen=True, kw_only=True)
|
||||||
@ -68,13 +67,13 @@ BUTTON_TYPES: Final = (
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: VodafoneConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up entry."""
|
"""Set up entry."""
|
||||||
_LOGGER.debug("Setting up Vodafone Station buttons")
|
_LOGGER.debug("Setting up Vodafone Station buttons")
|
||||||
|
|
||||||
coordinator: VodafoneStationRouter = hass.data[DOMAIN][entry.entry_id]
|
coordinator = entry.runtime_data
|
||||||
|
|
||||||
sensors_data = coordinator.data.sensors
|
sensors_data = coordinator.data.sensors
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@ from .helpers import cleanup_device_tracker
|
|||||||
|
|
||||||
CONSIDER_HOME_SECONDS = DEFAULT_CONSIDER_HOME.total_seconds()
|
CONSIDER_HOME_SECONDS = DEFAULT_CONSIDER_HOME.total_seconds()
|
||||||
|
|
||||||
|
type VodafoneConfigEntry = ConfigEntry[VodafoneStationRouter]
|
||||||
|
|
||||||
|
|
||||||
@dataclass(slots=True)
|
@dataclass(slots=True)
|
||||||
class VodafoneStationDeviceInfo:
|
class VodafoneStationDeviceInfo:
|
||||||
@ -42,7 +44,7 @@ class UpdateCoordinatorDataType:
|
|||||||
class VodafoneStationRouter(DataUpdateCoordinator[UpdateCoordinatorDataType]):
|
class VodafoneStationRouter(DataUpdateCoordinator[UpdateCoordinatorDataType]):
|
||||||
"""Queries router running Vodafone Station firmware."""
|
"""Queries router running Vodafone Station firmware."""
|
||||||
|
|
||||||
config_entry: ConfigEntry
|
config_entry: VodafoneConfigEntry
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -50,7 +52,7 @@ class VodafoneStationRouter(DataUpdateCoordinator[UpdateCoordinatorDataType]):
|
|||||||
host: str,
|
host: str,
|
||||||
username: str,
|
username: str,
|
||||||
password: str,
|
password: str,
|
||||||
config_entry: ConfigEntry,
|
config_entry: VodafoneConfigEntry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the scanner."""
|
"""Initialize the scanner."""
|
||||||
|
|
||||||
|
@ -3,25 +3,28 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.components.device_tracker import ScannerEntity
|
from homeassistant.components.device_tracker import ScannerEntity
|
||||||
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 AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import _LOGGER, DOMAIN
|
from .const import _LOGGER
|
||||||
from .coordinator import VodafoneStationDeviceInfo, VodafoneStationRouter
|
from .coordinator import (
|
||||||
|
VodafoneConfigEntry,
|
||||||
|
VodafoneStationDeviceInfo,
|
||||||
|
VodafoneStationRouter,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: VodafoneConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up device tracker for Vodafone Station component."""
|
"""Set up device tracker for Vodafone Station component."""
|
||||||
|
|
||||||
_LOGGER.debug("Start device trackers setup")
|
_LOGGER.debug("Start device trackers setup")
|
||||||
coordinator: VodafoneStationRouter = hass.data[DOMAIN][entry.entry_id]
|
coordinator = entry.runtime_data
|
||||||
|
|
||||||
tracked: set = set()
|
tracked: set = set()
|
||||||
|
|
||||||
|
@ -5,22 +5,20 @@ from __future__ import annotations
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.diagnostics import async_redact_data
|
from homeassistant.components.diagnostics import async_redact_data
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .coordinator import VodafoneConfigEntry
|
||||||
from .coordinator import VodafoneStationRouter
|
|
||||||
|
|
||||||
TO_REDACT = {CONF_USERNAME, CONF_PASSWORD}
|
TO_REDACT = {CONF_USERNAME, CONF_PASSWORD}
|
||||||
|
|
||||||
|
|
||||||
async def async_get_config_entry_diagnostics(
|
async def async_get_config_entry_diagnostics(
|
||||||
hass: HomeAssistant, entry: ConfigEntry
|
hass: HomeAssistant, entry: VodafoneConfigEntry
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Return diagnostics for a config entry."""
|
"""Return diagnostics for a config entry."""
|
||||||
|
|
||||||
coordinator: VodafoneStationRouter = hass.data[DOMAIN][entry.entry_id]
|
coordinator = entry.runtime_data
|
||||||
|
|
||||||
sensors_data = coordinator.data.sensors
|
sensors_data = coordinator.data.sensors
|
||||||
return {
|
return {
|
||||||
|
@ -12,14 +12,13 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import PERCENTAGE, EntityCategory, UnitOfDataRate
|
from homeassistant.const import PERCENTAGE, EntityCategory, UnitOfDataRate
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import _LOGGER, DOMAIN, LINE_TYPES
|
from .const import _LOGGER, LINE_TYPES
|
||||||
from .coordinator import VodafoneStationRouter
|
from .coordinator import VodafoneConfigEntry, VodafoneStationRouter
|
||||||
|
|
||||||
NOT_AVAILABLE: list = ["", "N/A", "0.0.0.0"]
|
NOT_AVAILABLE: list = ["", "N/A", "0.0.0.0"]
|
||||||
UPTIME_DEVIATION = 60
|
UPTIME_DEVIATION = 60
|
||||||
@ -166,13 +165,13 @@ SENSOR_TYPES: Final = (
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: VodafoneConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up entry."""
|
"""Set up entry."""
|
||||||
_LOGGER.debug("Setting up Vodafone Station sensors")
|
_LOGGER.debug("Setting up Vodafone Station sensors")
|
||||||
|
|
||||||
coordinator: VodafoneStationRouter = hass.data[DOMAIN][entry.entry_id]
|
coordinator = entry.runtime_data
|
||||||
|
|
||||||
sensors_data = coordinator.data.sensors
|
sensors_data = coordinator.data.sensors
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user