mirror of
https://github.com/home-assistant/core.git
synced 2025-05-01 20:57:51 +00:00
Avoid triggering ping device tracker home
after restore (#106913)
This commit is contained in:
parent
711498793a
commit
938c32d35e
@ -136,7 +136,7 @@ async def async_setup_entry(
|
|||||||
class PingDeviceTracker(CoordinatorEntity[PingUpdateCoordinator], ScannerEntity):
|
class PingDeviceTracker(CoordinatorEntity[PingUpdateCoordinator], ScannerEntity):
|
||||||
"""Representation of a Ping device tracker."""
|
"""Representation of a Ping device tracker."""
|
||||||
|
|
||||||
_first_offline: datetime | None = None
|
_last_seen: datetime | None = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, config_entry: ConfigEntry, coordinator: PingUpdateCoordinator
|
self, config_entry: ConfigEntry, coordinator: PingUpdateCoordinator
|
||||||
@ -171,14 +171,12 @@ class PingDeviceTracker(CoordinatorEntity[PingUpdateCoordinator], ScannerEntity)
|
|||||||
def is_connected(self) -> bool:
|
def is_connected(self) -> bool:
|
||||||
"""Return true if ping returns is_alive or considered home."""
|
"""Return true if ping returns is_alive or considered home."""
|
||||||
if self.coordinator.data.is_alive:
|
if self.coordinator.data.is_alive:
|
||||||
self._first_offline = None
|
self._last_seen = dt_util.utcnow()
|
||||||
return True
|
|
||||||
|
|
||||||
now = dt_util.utcnow()
|
return (
|
||||||
if self._first_offline is None:
|
self._last_seen is not None
|
||||||
self._first_offline = now
|
and (dt_util.utcnow() - self._last_seen) < self._consider_home_interval
|
||||||
|
)
|
||||||
return (self._first_offline + self._consider_home_interval) > now
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def entity_registry_enabled_default(self) -> bool:
|
def entity_registry_enabled_default(self) -> bool:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user