mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +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."""
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import VodafoneStationRouter
|
||||
from .coordinator import VodafoneConfigEntry, VodafoneStationRouter
|
||||
|
||||
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."""
|
||||
coordinator = VodafoneStationRouter(
|
||||
hass,
|
||||
@ -22,7 +21,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
||||
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))
|
||||
|
||||
@ -31,10 +30,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
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."""
|
||||
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.close()
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
@ -42,7 +41,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
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."""
|
||||
if entry.options:
|
||||
await hass.config_entries.async_reload(entry.entry_id)
|
||||
|
@ -11,14 +11,13 @@ from homeassistant.components.button import (
|
||||
ButtonEntity,
|
||||
ButtonEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import _LOGGER, DOMAIN
|
||||
from .coordinator import VodafoneStationRouter
|
||||
from .const import _LOGGER
|
||||
from .coordinator import VodafoneConfigEntry, VodafoneStationRouter
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
@ -68,13 +67,13 @@ BUTTON_TYPES: Final = (
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: VodafoneConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up entry."""
|
||||
_LOGGER.debug("Setting up Vodafone Station buttons")
|
||||
|
||||
coordinator: VodafoneStationRouter = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
sensors_data = coordinator.data.sensors
|
||||
|
||||
|
@ -21,6 +21,8 @@ from .helpers import cleanup_device_tracker
|
||||
|
||||
CONSIDER_HOME_SECONDS = DEFAULT_CONSIDER_HOME.total_seconds()
|
||||
|
||||
type VodafoneConfigEntry = ConfigEntry[VodafoneStationRouter]
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class VodafoneStationDeviceInfo:
|
||||
@ -42,7 +44,7 @@ class UpdateCoordinatorDataType:
|
||||
class VodafoneStationRouter(DataUpdateCoordinator[UpdateCoordinatorDataType]):
|
||||
"""Queries router running Vodafone Station firmware."""
|
||||
|
||||
config_entry: ConfigEntry
|
||||
config_entry: VodafoneConfigEntry
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -50,7 +52,7 @@ class VodafoneStationRouter(DataUpdateCoordinator[UpdateCoordinatorDataType]):
|
||||
host: str,
|
||||
username: str,
|
||||
password: str,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: VodafoneConfigEntry,
|
||||
) -> None:
|
||||
"""Initialize the scanner."""
|
||||
|
||||
|
@ -3,25 +3,28 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.components.device_tracker import ScannerEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import _LOGGER, DOMAIN
|
||||
from .coordinator import VodafoneStationDeviceInfo, VodafoneStationRouter
|
||||
from .const import _LOGGER
|
||||
from .coordinator import (
|
||||
VodafoneConfigEntry,
|
||||
VodafoneStationDeviceInfo,
|
||||
VodafoneStationRouter,
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: VodafoneConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up device tracker for Vodafone Station component."""
|
||||
|
||||
_LOGGER.debug("Start device trackers setup")
|
||||
coordinator: VodafoneStationRouter = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
tracked: set = set()
|
||||
|
||||
|
@ -5,22 +5,20 @@ from __future__ import annotations
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import VodafoneStationRouter
|
||||
from .coordinator import VodafoneConfigEntry
|
||||
|
||||
TO_REDACT = {CONF_USERNAME, CONF_PASSWORD}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
hass: HomeAssistant, entry: VodafoneConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
|
||||
coordinator: VodafoneStationRouter = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
sensors_data = coordinator.data.sensors
|
||||
return {
|
||||
|
@ -12,14 +12,13 @@ from homeassistant.components.sensor import (
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import PERCENTAGE, EntityCategory, UnitOfDataRate
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import _LOGGER, DOMAIN, LINE_TYPES
|
||||
from .coordinator import VodafoneStationRouter
|
||||
from .const import _LOGGER, LINE_TYPES
|
||||
from .coordinator import VodafoneConfigEntry, VodafoneStationRouter
|
||||
|
||||
NOT_AVAILABLE: list = ["", "N/A", "0.0.0.0"]
|
||||
UPTIME_DEVIATION = 60
|
||||
@ -166,13 +165,13 @@ SENSOR_TYPES: Final = (
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: VodafoneConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up entry."""
|
||||
_LOGGER.debug("Setting up Vodafone Station sensors")
|
||||
|
||||
coordinator: VodafoneStationRouter = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
sensors_data = coordinator.data.sensors
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user