From 906c24f7429975309b5a922e6a9140b60539eb08 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Wed, 23 Apr 2025 13:19:07 +0200 Subject: [PATCH 1/3] 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. --- supervisor/api/__init__.py | 3 +++ supervisor/api/root.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/supervisor/api/__init__.py b/supervisor/api/__init__.py index b04c2ac5602..0b228b4a372 100644 --- a/supervisor/api/__init__.py +++ b/supervisor/api/__init__.py @@ -345,6 +345,9 @@ def _register_root(self) -> None: 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)]) + + # Deprecated 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 6c74d7bdcba..00a9d0c1ac9 100644 --- a/supervisor/api/root.py +++ b/supervisor/api/root.py @@ -113,3 +113,8 @@ async def refresh_updates(self, request: web.Request) -> None: 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() From 92509b4e8cfece49c06ea860c2c0ae532461d5dd Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Wed, 23 Apr 2025 13:45:36 +0200 Subject: [PATCH 2/3] Add pytest --- tests/api/test_root.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/api/test_root.py b/tests/api/test_root.py index a497f97c505..9d233ace0a5 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 From ae714e9e073da2a7a8ce1d9eec5f53ff0c18cec4 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 24 Apr 2025 14:17:21 +0200 Subject: [PATCH 3/3] Update supervisor/api/__init__.py --- supervisor/api/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supervisor/api/__init__.py b/supervisor/api/__init__.py index 0b228b4a372..f4ced1bdffb 100644 --- a/supervisor/api/__init__.py +++ b/supervisor/api/__init__.py @@ -347,7 +347,7 @@ def _register_root(self) -> None: self.webapp.add_routes([web.get("/info", api_root.info)]) self.webapp.add_routes([web.post("/reload_updates", api_root.reload_updates)]) - # Deprecated + # 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)]