Fix iCloud device tracker stale location by requesting an active locate on each poll (#181731)

This commit is contained in:
Radek Piekarz
2026-09-19 09:19:23 +02:00
committed by GitHub
parent 8385ee1a7c
commit 6f3eb0bbe4
2 changed files with 14 additions and 0 deletions
@@ -175,6 +175,11 @@ class IcloudAccount:
api_devices = {}
try:
api_devices = self.api.devices
# Since pyicloud 2.3.0 device reads are cache-only and the library
# requests an active locate from Apple only at service creation, so
# explicitly refresh with locate=True to get a fresh GPS fix on
# every poll instead of Apple's cached location.
api_devices.refresh(locate=True)
except Exception as err: # noqa: BLE001
_LOGGER.error("Unknown iCloud error: %s", err)
self._fetch_interval = 2
+9
View File
@@ -99,6 +99,11 @@ class MockDevicesContainer:
"""Initialize with userinfo and list of device objects."""
self.user_info = userinfo
self._devices = devices
self.refresh_calls: list[bool] = []
def refresh(self, locate: bool = False) -> None:
"""Record refresh calls made by the account."""
self.refresh_calls.append(locate)
def __iter__(self):
"""Iterate returns device objects (each must have .status(...))."""
@@ -165,3 +170,7 @@ async def test_setup_success_with_devices(
assert account.owner_fullname == "user name"
assert "johntravolta" in account.family_members_fullname
assert account.family_members_fullname["johntravolta"] == "John TRAVOLTA"
# An active locate must be requested on every poll (pyicloud >= 2.3.0
# only locates at service creation, so the account has to ask for it)
assert mock_icloud_service.devices.refresh_calls == [True]
assert "device1" in account.devices