Skip to content

Commit

Permalink
Avoid triggering ping device tracker home after restore (home-assis…
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbede authored Jan 3, 2024
1 parent 7114987 commit 938c32d
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions homeassistant/components/ping/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async def async_setup_entry(
class PingDeviceTracker(CoordinatorEntity[PingUpdateCoordinator], ScannerEntity):
"""Representation of a Ping device tracker."""

_first_offline: datetime | None = None
_last_seen: datetime | None = None

def __init__(
self, config_entry: ConfigEntry, coordinator: PingUpdateCoordinator
Expand Down Expand Up @@ -171,14 +171,12 @@ def source_type(self) -> SourceType:
def is_connected(self) -> bool:
"""Return true if ping returns is_alive or considered home."""
if self.coordinator.data.is_alive:
self._first_offline = None
return True
self._last_seen = dt_util.utcnow()

now = dt_util.utcnow()
if self._first_offline is None:
self._first_offline = now

return (self._first_offline + self._consider_home_interval) > now
return (
self._last_seen is not None
and (dt_util.utcnow() - self._last_seen) < self._consider_home_interval
)

@property
def entity_registry_enabled_default(self) -> bool:
Expand Down

0 comments on commit 938c32d

Please sign in to comment.