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
This commit is contained in:
Stefan Agner 2025-04-24 15:46:18 +02:00 committed by GitHub
parent 88b41e80bb
commit de497cdc19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 1 deletions

View File

@ -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)]

View File

@ -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()

View File

@ -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