mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Explicitly pass in the config_entry in ping coordinator (#138041)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
4c331d3942
commit
ac3eead8ac
@ -6,7 +6,6 @@ import logging
|
|||||||
|
|
||||||
from icmplib import SocketPermissionError, async_ping
|
from icmplib import SocketPermissionError, async_ping
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import CONF_HOST, Platform
|
from homeassistant.const import CONF_HOST, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import config_validation as cv
|
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 homeassistant.util.hass_dict import HassKey
|
||||||
|
|
||||||
from .const import CONF_PING_COUNT, DOMAIN
|
from .const import CONF_PING_COUNT, DOMAIN
|
||||||
from .coordinator import PingUpdateCoordinator
|
from .coordinator import PingConfigEntry, PingUpdateCoordinator
|
||||||
from .helpers import PingDataICMPLib, PingDataSubProcess
|
from .helpers import PingDataICMPLib, PingDataSubProcess
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_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)
|
DATA_PRIVILEGED_KEY: HassKey[bool | None] = HassKey(DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
type PingConfigEntry = ConfigEntry[PingUpdateCoordinator]
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the ping integration."""
|
"""Set up the ping integration."""
|
||||||
hass.data[DATA_PRIVILEGED_KEY] = await _can_use_icmp_lib_with_privilege()
|
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
|
ping_cls = PingDataICMPLib
|
||||||
|
|
||||||
coordinator = PingUpdateCoordinator(
|
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()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
|
@ -6,13 +6,11 @@ from homeassistant.components.binary_sensor import (
|
|||||||
BinarySensorDeviceClass,
|
BinarySensorDeviceClass,
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
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 PingConfigEntry
|
|
||||||
from .const import CONF_IMPORTED_BY
|
from .const import CONF_IMPORTED_BY
|
||||||
from .coordinator import PingUpdateCoordinator
|
from .coordinator import PingConfigEntry, PingUpdateCoordinator
|
||||||
from .entity import PingEntity
|
from .entity import PingEntity
|
||||||
|
|
||||||
|
|
||||||
@ -31,7 +29,7 @@ class PingBinarySensor(PingEntity, BinarySensorEntity):
|
|||||||
_attr_name = None
|
_attr_name = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, config_entry: ConfigEntry, coordinator: PingUpdateCoordinator
|
self, config_entry: PingConfigEntry, coordinator: PingUpdateCoordinator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the Ping Binary sensor."""
|
"""Initialize the Ping Binary sensor."""
|
||||||
super().__init__(config_entry, coordinator, config_entry.entry_id)
|
super().__init__(config_entry, coordinator, config_entry.entry_id)
|
||||||
|
@ -7,6 +7,7 @@ from datetime import timedelta
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
|
|
||||||
@ -14,6 +15,8 @@ from .helpers import PingDataICMPLib, PingDataSubProcess
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
type PingConfigEntry = ConfigEntry[PingUpdateCoordinator]
|
||||||
|
|
||||||
|
|
||||||
@dataclass(slots=True, frozen=True)
|
@dataclass(slots=True, frozen=True)
|
||||||
class PingResult:
|
class PingResult:
|
||||||
@ -27,11 +30,13 @@ class PingResult:
|
|||||||
class PingUpdateCoordinator(DataUpdateCoordinator[PingResult]):
|
class PingUpdateCoordinator(DataUpdateCoordinator[PingResult]):
|
||||||
"""The Ping update coordinator."""
|
"""The Ping update coordinator."""
|
||||||
|
|
||||||
|
config_entry: PingConfigEntry
|
||||||
ping: PingDataSubProcess | PingDataICMPLib
|
ping: PingDataSubProcess | PingDataICMPLib
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
config_entry: PingConfigEntry,
|
||||||
ping: PingDataSubProcess | PingDataICMPLib,
|
ping: PingDataSubProcess | PingDataICMPLib,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the Ping coordinator."""
|
"""Initialize the Ping coordinator."""
|
||||||
@ -40,6 +45,7 @@ class PingUpdateCoordinator(DataUpdateCoordinator[PingResult]):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name=f"Ping {ping.ip_address}",
|
name=f"Ping {ping.ip_address}",
|
||||||
update_interval=timedelta(seconds=30),
|
update_interval=timedelta(seconds=30),
|
||||||
)
|
)
|
||||||
|
@ -9,15 +9,13 @@ from homeassistant.components.device_tracker import (
|
|||||||
DEFAULT_CONSIDER_HOME,
|
DEFAULT_CONSIDER_HOME,
|
||||||
ScannerEntity,
|
ScannerEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
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 homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from . import PingConfigEntry
|
|
||||||
from .const import CONF_IMPORTED_BY
|
from .const import CONF_IMPORTED_BY
|
||||||
from .coordinator import PingUpdateCoordinator
|
from .coordinator import PingConfigEntry, PingUpdateCoordinator
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
@ -33,7 +31,7 @@ class PingDeviceTracker(CoordinatorEntity[PingUpdateCoordinator], ScannerEntity)
|
|||||||
_last_seen: datetime | None = None
|
_last_seen: datetime | None = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, config_entry: ConfigEntry, coordinator: PingUpdateCoordinator
|
self, config_entry: PingConfigEntry, coordinator: PingUpdateCoordinator
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the Ping device tracker."""
|
"""Initialize the Ping device tracker."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
"""Base entity for the Ping component."""
|
"""Base entity for the Ping component."""
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN
|
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .coordinator import PingUpdateCoordinator
|
from .coordinator import PingConfigEntry, PingUpdateCoordinator
|
||||||
|
|
||||||
|
|
||||||
class PingEntity(CoordinatorEntity[PingUpdateCoordinator]):
|
class PingEntity(CoordinatorEntity[PingUpdateCoordinator]):
|
||||||
@ -15,7 +14,7 @@ class PingEntity(CoordinatorEntity[PingUpdateCoordinator]):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
config_entry: ConfigEntry,
|
config_entry: PingConfigEntry,
|
||||||
coordinator: PingUpdateCoordinator,
|
coordinator: PingUpdateCoordinator,
|
||||||
unique_id: str,
|
unique_id: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -14,8 +14,7 @@ from homeassistant.const import EntityCategory, UnitOfTime
|
|||||||
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 PingConfigEntry
|
from .coordinator import PingConfigEntry, PingResult, PingUpdateCoordinator
|
||||||
from .coordinator import PingResult, PingUpdateCoordinator
|
|
||||||
from .entity import PingEntity
|
from .entity import PingEntity
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user