Skip to content

Commit de497cd

Browse files
authored
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
1 parent 88b41e8 commit de497cd

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

supervisor/api/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ def _register_root(self) -> None:
345345
api_root.coresys = self.coresys
346346

347347
self.webapp.add_routes([web.get("/info", api_root.info)])
348+
self.webapp.add_routes([web.post("/reload_updates", api_root.reload_updates)])
349+
350+
# Discouraged
348351
self.webapp.add_routes([web.post("/refresh_updates", api_root.refresh_updates)])
349352
self.webapp.add_routes(
350353
[web.get("/available_updates", api_root.available_updates)]

supervisor/api/root.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,8 @@ async def refresh_updates(self, request: web.Request) -> None:
113113
await asyncio.shield(
114114
asyncio.gather(self.sys_updater.reload(), self.sys_store.reload())
115115
)
116+
117+
@api_process
118+
async def reload_updates(self, request: web.Request) -> None:
119+
"""Refresh updater update information."""
120+
await self.sys_updater.reload()

tests/api/test_root.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""Test Supervisor API."""
22

33
# pylint: disable=protected-access
4-
from unittest.mock import AsyncMock
4+
from unittest.mock import AsyncMock, patch
5+
6+
from aiohttp.test_utils import TestClient
57

68
from supervisor.api.const import ATTR_AVAILABLE_UPDATES
79
from supervisor.coresys import CoreSys
@@ -78,3 +80,18 @@ async def test_api_refresh_updates(api_client, coresys: CoreSys):
7880

7981
assert coresys.updater.reload.called
8082
assert coresys.store.reload.called
83+
84+
85+
async def test_api_reload_updates(
86+
coresys: CoreSys,
87+
api_client: TestClient,
88+
):
89+
"""Test reload updates."""
90+
with (
91+
patch("supervisor.updater.Updater.fetch_data") as fetch_data,
92+
):
93+
resp = await api_client.post("/reload_updates")
94+
95+
fetch_data.assert_called_once_with()
96+
97+
assert resp.status == 200

0 commit comments

Comments
 (0)