From de497cdc19267b6a0332e016eddd6adf0eb5dbf0 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 24 Apr 2025 15:46:18 +0200 Subject: [PATCH] Add dedicated version update refresh for main components (#5833) * Add dedicated update information reload Currently we have the /refresh_updates endpoint which updates the main component versions (Core, OS, Supervisor, Plug-ins) and the add-on store at the same time. This combined update causes more update information reloads than necessary. To allow fine grained update refresh control introduce a new endpoint /reload_updates which asks Supervisor to only update main component versions (learned through the version json files). The /store/reload endpoint already allows to update the add-on store separately. * Add pytest * Update supervisor/api/__init__.py --- supervisor/api/__init__.py | 3 +++ supervisor/api/root.py | 5 +++++ tests/api/test_root.py | 19 ++++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/supervisor/api/__init__.py b/supervisor/api/__init__.py index b04c2ac56..f4ced1bdf 100644 --- a/supervisor/api/__init__.py +++ b/supervisor/api/__init__.py @@ -345,6 +345,9 @@ class RestAPI(CoreSysAttributes): api_root.coresys = self.coresys self.webapp.add_routes([web.get("/info", api_root.info)]) + self.webapp.add_routes([web.post("/reload_updates", api_root.reload_updates)]) + + # Discouraged self.webapp.add_routes([web.post("/refresh_updates", api_root.refresh_updates)]) self.webapp.add_routes( [web.get("/available_updates", api_root.available_updates)] diff --git a/supervisor/api/root.py b/supervisor/api/root.py index 6c74d7bdc..00a9d0c1a 100644 --- a/supervisor/api/root.py +++ b/supervisor/api/root.py @@ -113,3 +113,8 @@ class APIRoot(CoreSysAttributes): await asyncio.shield( asyncio.gather(self.sys_updater.reload(), self.sys_store.reload()) ) + + @api_process + async def reload_updates(self, request: web.Request) -> None: + """Refresh updater update information.""" + await self.sys_updater.reload() diff --git a/tests/api/test_root.py b/tests/api/test_root.py index a497f97c5..9d233ace0 100644 --- a/tests/api/test_root.py +++ b/tests/api/test_root.py @@ -1,7 +1,9 @@ """Test Supervisor API.""" # pylint: disable=protected-access -from unittest.mock import AsyncMock +from unittest.mock import AsyncMock, patch + +from aiohttp.test_utils import TestClient from supervisor.api.const import ATTR_AVAILABLE_UPDATES from supervisor.coresys import CoreSys @@ -78,3 +80,18 @@ async def test_api_refresh_updates(api_client, coresys: CoreSys): assert coresys.updater.reload.called assert coresys.store.reload.called + + +async def test_api_reload_updates( + coresys: CoreSys, + api_client: TestClient, +): + """Test reload updates.""" + with ( + patch("supervisor.updater.Updater.fetch_data") as fetch_data, + ): + resp = await api_client.post("/reload_updates") + + fetch_data.assert_called_once_with() + + assert resp.status == 200