Explicitly pass in the config_entry in ping coordinator (#138041)
explicitly pass in the config_entry in coordinatorpull/130406/merge
parent
4c331d3942
commit
ac3eead8ac
|
@ -6,7 +6,6 @@ import logging
|
|||
|
||||
from icmplib import SocketPermissionError, async_ping
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
|
@ -14,7 +13,7 @@ from homeassistant.helpers.typing import ConfigType
|
|||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import CONF_PING_COUNT, DOMAIN
|
||||
from .coordinator import PingUpdateCoordinator
|
||||
from .coordinator import PingConfigEntry, PingUpdateCoordinator
|
||||
from .helpers import PingDataICMPLib, PingDataSubProcess
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -24,9 +23,6 @@ PLATFORMS = [Platform.BINARY_SENSOR, Platform.DEVICE_TRACKER, Platform.SENSOR]
|
|||
DATA_PRIVILEGED_KEY: HassKey[bool | None] = HassKey(DOMAIN)
|
||||
|
||||
|
||||
type PingConfigEntry = ConfigEntry[PingUpdateCoordinator]
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the ping integration."""
|
||||
hass.data[DATA_PRIVILEGED_KEY] = await _can_use_icmp_lib_with_privilege()
|
||||
|
@ -47,7 +43,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: PingConfigEntry) -> bool
|
|||
ping_cls = PingDataICMPLib
|
||||
|
||||
coordinator = PingUpdateCoordinator(
|
||||
hass=hass, ping=ping_cls(hass, host, count, privileged)
|
||||
hass=hass, config_entry=entry, ping=ping_cls(hass, host, count, privileged)
|
||||
)
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
|
|
|
@ -6,13 +6,11 @@ from homeassistant.components.binary_sensor import (
|
|||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import PingConfigEntry
|
||||
from .const import CONF_IMPORTED_BY
|
||||
from .coordinator import PingUpdateCoordinator
|
||||
from .coordinator import PingConfigEntry, PingUpdateCoordinator
|
||||
from .entity import PingEntity
|
||||
|
||||
|
||||
|
@ -31,7 +29,7 @@ class PingBinarySensor(PingEntity, BinarySensorEntity):
|
|||
_attr_name = None
|
||||
|
||||
def __init__(
|
||||
self, config_entry: ConfigEntry, coordinator: PingUpdateCoordinator
|
||||
self, config_entry: PingConfigEntry, coordinator: PingUpdateCoordinator
|
||||
) -> None:
|
||||
"""Initialize the Ping Binary sensor."""
|
||||
super().__init__(config_entry, coordinator, config_entry.entry_id)
|
||||
|
|
|
@ -7,6 +7,7 @@ from datetime import timedelta
|
|||
import logging
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
|
@ -14,6 +15,8 @@ from .helpers import PingDataICMPLib, PingDataSubProcess
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
type PingConfigEntry = ConfigEntry[PingUpdateCoordinator]
|
||||
|
||||
|
||||
@dataclass(slots=True, frozen=True)
|
||||
class PingResult:
|
||||
|
@ -27,11 +30,13 @@ class PingResult:
|
|||
class PingUpdateCoordinator(DataUpdateCoordinator[PingResult]):
|
||||
"""The Ping update coordinator."""
|
||||
|
||||
config_entry: PingConfigEntry
|
||||
ping: PingDataSubProcess | PingDataICMPLib
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: PingConfigEntry,
|
||||
ping: PingDataSubProcess | PingDataICMPLib,
|
||||
) -> None:
|
||||
"""Initialize the Ping coordinator."""
|
||||
|
@ -40,6 +45,7 @@ class PingUpdateCoordinator(DataUpdateCoordinator[PingResult]):
|
|||
super().__init__(
|
||||
hass,
|
||||
_LOGGER,
|
||||
config_entry=config_entry,
|
||||
name=f"Ping {ping.ip_address}",
|
||||
update_interval=timedelta(seconds=30),
|
||||
)
|
||||
|
|
|
@ -9,15 +9,13 @@ from homeassistant.components.device_tracker import (
|
|||
DEFAULT_CONSIDER_HOME,
|
||||
ScannerEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from . import PingConfigEntry
|
||||
from .const import CONF_IMPORTED_BY
|
||||
from .coordinator import PingUpdateCoordinator
|
||||
from .coordinator import PingConfigEntry, PingUpdateCoordinator
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
@ -33,7 +31,7 @@ class PingDeviceTracker(CoordinatorEntity[PingUpdateCoordinator], ScannerEntity)
|
|||
_last_seen: datetime | None = None
|
||||
|
||||
def __init__(
|
||||
self, config_entry: ConfigEntry, coordinator: PingUpdateCoordinator
|
||||
self, config_entry: PingConfigEntry, coordinator: PingUpdateCoordinator
|
||||
) -> None:
|
||||
"""Initialize the Ping device tracker."""
|
||||
super().__init__(coordinator)
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
"""Base entity for the Ping component."""
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .coordinator import PingUpdateCoordinator
|
||||
from .coordinator import PingConfigEntry, PingUpdateCoordinator
|
||||
|
||||
|
||||
class PingEntity(CoordinatorEntity[PingUpdateCoordinator]):
|
||||
|
@ -15,7 +14,7 @@ class PingEntity(CoordinatorEntity[PingUpdateCoordinator]):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: PingConfigEntry,
|
||||
coordinator: PingUpdateCoordinator,
|
||||
unique_id: str,
|
||||
) -> None:
|
||||
|
|
|
@ -14,8 +14,7 @@ from homeassistant.const import EntityCategory, UnitOfTime
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import PingConfigEntry
|
||||
from .coordinator import PingResult, PingUpdateCoordinator
|
||||
from .coordinator import PingConfigEntry, PingResult, PingUpdateCoordinator
|
||||
from .entity import PingEntity
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue