-
-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add update coordinator to ping (#104148)
* Add update coordinator to ping * Remove config_entry from coordinator * Remove PARALLEL_UPDATES and set to hass.data
- Loading branch information
Showing
5 changed files
with
105 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""DataUpdateCoordinator for the ping integration.""" | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from datetime import timedelta | ||
import logging | ||
from typing import Any | ||
|
||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator | ||
|
||
from .helpers import PingDataICMPLib, PingDataSubProcess | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
@dataclass(slots=True, frozen=True) | ||
class PingResult: | ||
"""Dataclass returned by the coordinator.""" | ||
|
||
ip_address: str | ||
is_alive: bool | ||
data: dict[str, Any] | None | ||
|
||
|
||
class PingUpdateCoordinator(DataUpdateCoordinator[PingResult]): | ||
"""The Ping update coordinator.""" | ||
|
||
ping: PingDataSubProcess | PingDataICMPLib | ||
|
||
def __init__( | ||
self, | ||
hass: HomeAssistant, | ||
ping: PingDataSubProcess | PingDataICMPLib, | ||
) -> None: | ||
"""Initialize the Ping coordinator.""" | ||
self.ping = ping | ||
|
||
super().__init__( | ||
hass, | ||
_LOGGER, | ||
name=f"Ping {ping.ip_address}", | ||
update_interval=timedelta(minutes=5), | ||
) | ||
|
||
async def _async_update_data(self) -> PingResult: | ||
"""Trigger ping check.""" | ||
await self.ping.async_update() | ||
return PingResult( | ||
ip_address=self.ping.ip_address, | ||
is_alive=self.ping.is_alive, | ||
data=self.ping.data, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters