From f036e7731f45c857f64b9544a7d0908e887a17c8 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 24 Apr 2025 15:05:36 +0200 Subject: [PATCH 1/4] Add reload updates for main components Add /reload_updates endpoint which refreshes updates of the main components only (OS, Supervisor, Core and Plug-ins). --- aiohasupervisor/root.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/aiohasupervisor/root.py b/aiohasupervisor/root.py index 6f01456..4145ea4 100644 --- a/aiohasupervisor/root.py +++ b/aiohasupervisor/root.py @@ -109,12 +109,19 @@ async def info(self) -> RootInfo: result = await self._client.get("info") return RootInfo.from_dict(result.data) + async def reload_updates(self) -> None: + """Reload updates. + + Reload main components update information (OS, Supervisor, Core and plug-ins). + """ + await self._client.post("reload_updates", timeout=ClientTimeout(total=300)) + async def refresh_updates(self) -> None: - """Refresh updates.""" + """Refresh updates (discouraged).""" await self._client.post("refresh_updates", timeout=ClientTimeout(total=300)) async def available_updates(self) -> list[AvailableUpdate]: - """Get available updates.""" + """Get available updates (discouraged).""" result = await self._client.get("available_updates") return AvailableUpdates.from_dict(result.data).available_updates From 099ee69489b5adc22365511e9b870e9ff721623f Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 24 Apr 2025 15:38:07 +0200 Subject: [PATCH 2/4] Discourage /refresh_updates only --- aiohasupervisor/root.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/aiohasupervisor/root.py b/aiohasupervisor/root.py index 4145ea4..1b73b2d 100644 --- a/aiohasupervisor/root.py +++ b/aiohasupervisor/root.py @@ -117,11 +117,14 @@ async def reload_updates(self) -> None: await self._client.post("reload_updates", timeout=ClientTimeout(total=300)) async def refresh_updates(self) -> None: - """Refresh updates (discouraged).""" + """Refresh updates. + + Discouraged. Use the `reload_updates()` and `store.reload()` instead. + """ await self._client.post("refresh_updates", timeout=ClientTimeout(total=300)) async def available_updates(self) -> list[AvailableUpdate]: - """Get available updates (discouraged).""" + """Get available updates.""" result = await self._client.get("available_updates") return AvailableUpdates.from_dict(result.data).available_updates From a3a063206acc6ce36f34d9968d01040e41776fda Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 24 Apr 2025 15:38:59 +0200 Subject: [PATCH 3/4] Add pytest --- tests/test_root.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_root.py b/tests/test_root.py index eb2cd69..1b31d66 100644 --- a/tests/test_root.py +++ b/tests/test_root.py @@ -88,6 +88,17 @@ async def test_available_updates( assert updates[1].update_type == UpdateType.OS +async def test_reload_updates( + responses: aioresponses, supervisor_client: SupervisorClient +) -> None: + """Test reload updates API.""" + responses.post(f"{SUPERVISOR_URL}/reload_updates", status=200) + assert await supervisor_client.reload_updates() is None + assert responses.requests.keys() == { + ("POST", URL(f"{SUPERVISOR_URL}/reload_updates")) + } + + async def test_refresh_updates( responses: aioresponses, supervisor_client: SupervisorClient ) -> None: From 4e23dc665f4d81066f7c2661fda4a388793fc67c Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 24 Apr 2025 16:07:14 +0200 Subject: [PATCH 4/4] Add discouraged explanation --- aiohasupervisor/root.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aiohasupervisor/root.py b/aiohasupervisor/root.py index 1b73b2d..af316a4 100644 --- a/aiohasupervisor/root.py +++ b/aiohasupervisor/root.py @@ -119,7 +119,8 @@ async def reload_updates(self) -> None: async def refresh_updates(self) -> None: """Refresh updates. - Discouraged. Use the `reload_updates()` and `store.reload()` instead. + Discouraged as this endpoint does two things at once. Use the `reload_updates()` + and `store.reload()` instead. """ await self._client.post("refresh_updates", timeout=ClientTimeout(total=300))