mirror of
https://github.com/home-assistant/core.git
synced 2025-08-07 12:38:21 +00:00
Pass config entry to AsusWRT coordinator (#149953)
This commit is contained in:
parent
8d8383e1c1
commit
c1ccfee7cc
@ -5,7 +5,7 @@ from __future__ import annotations
|
|||||||
from collections.abc import Callable, Mapping
|
from collections.abc import Callable, Mapping
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from pyasuswrt import AsusWrtError
|
from pyasuswrt import AsusWrtError
|
||||||
|
|
||||||
@ -40,6 +40,9 @@ from .const import (
|
|||||||
SENSORS_CONNECTED_DEVICE,
|
SENSORS_CONNECTED_DEVICE,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from . import AsusWrtConfigEntry
|
||||||
|
|
||||||
CONF_REQ_RELOAD = [CONF_DNSMASQ, CONF_INTERFACE, CONF_REQUIRE_IP]
|
CONF_REQ_RELOAD = [CONF_DNSMASQ, CONF_INTERFACE, CONF_REQUIRE_IP]
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=30)
|
SCAN_INTERVAL = timedelta(seconds=30)
|
||||||
@ -52,10 +55,13 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
class AsusWrtSensorDataHandler:
|
class AsusWrtSensorDataHandler:
|
||||||
"""Data handler for AsusWrt sensor."""
|
"""Data handler for AsusWrt sensor."""
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, api: AsusWrtBridge) -> None:
|
def __init__(
|
||||||
|
self, hass: HomeAssistant, api: AsusWrtBridge, entry: AsusWrtConfigEntry
|
||||||
|
) -> None:
|
||||||
"""Initialize a AsusWrt sensor data handler."""
|
"""Initialize a AsusWrt sensor data handler."""
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
self._api = api
|
self._api = api
|
||||||
|
self._entry = entry
|
||||||
self._connected_devices = 0
|
self._connected_devices = 0
|
||||||
|
|
||||||
async def _get_connected_devices(self) -> dict[str, int]:
|
async def _get_connected_devices(self) -> dict[str, int]:
|
||||||
@ -91,6 +97,7 @@ class AsusWrtSensorDataHandler:
|
|||||||
update_method=method,
|
update_method=method,
|
||||||
# Polling interval. Will only be polled if there are subscribers.
|
# Polling interval. Will only be polled if there are subscribers.
|
||||||
update_interval=SCAN_INTERVAL if should_poll else None,
|
update_interval=SCAN_INTERVAL if should_poll else None,
|
||||||
|
config_entry=self._entry,
|
||||||
)
|
)
|
||||||
await coordinator.async_refresh()
|
await coordinator.async_refresh()
|
||||||
|
|
||||||
@ -321,7 +328,9 @@ class AsusWrtRouter:
|
|||||||
if self._sensors_data_handler:
|
if self._sensors_data_handler:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._sensors_data_handler = AsusWrtSensorDataHandler(self.hass, self._api)
|
self._sensors_data_handler = AsusWrtSensorDataHandler(
|
||||||
|
self.hass, self._api, self._entry
|
||||||
|
)
|
||||||
self._sensors_data_handler.update_device_count(self._connected_devices)
|
self._sensors_data_handler.update_device_count(self._connected_devices)
|
||||||
|
|
||||||
sensors_types = await self._api.async_get_available_sensors()
|
sensors_types = await self._api.async_get_available_sensors()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user