Skip to content

Commit 22c57d4

Browse files
committed
refresh_updates, stop and restart to aiohasupervisor
1 parent 414dc15 commit 22c57d4

File tree

12 files changed

+99
-179
lines changed

12 files changed

+99
-179
lines changed

homeassistant/components/hassio/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,9 @@ async def update_info_data(_: datetime | None = None) -> None:
468468
async def _async_stop(hass: HomeAssistant, restart: bool) -> None:
469469
"""Stop or restart home assistant."""
470470
if restart:
471-
await hassio.restart_homeassistant()
471+
await supervisor_client.homeassistant.restart()
472472
else:
473-
await hassio.stop_homeassistant()
473+
await supervisor_client.homeassistant.stop()
474474

475475
# Set a custom handler for the homeassistant.restart and homeassistant.stop services
476476
async_set_stop_handler(hass, _async_stop)

homeassistant/components/hassio/coordinator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,8 @@ async def _async_refresh(
563563
# updates if this is not a scheduled refresh and
564564
# we are not doing the first refresh.
565565
try:
566-
await self.hassio.refresh_updates()
567-
except HassioAPIError as err:
566+
await self.supervisor_client.refresh_updates()
567+
except SupervisorError as err:
568568
_LOGGER.warning("Error on Supervisor API: %s", err)
569569

570570
await super()._async_refresh(

homeassistant/components/hassio/handler.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -245,30 +245,6 @@ def get_ingress_panels(self) -> Coroutine:
245245
"""
246246
return self.send_command("/ingress/panels", method="get")
247247

248-
@_api_bool
249-
def restart_homeassistant(self) -> Coroutine:
250-
"""Restart Home-Assistant container.
251-
252-
This method returns a coroutine.
253-
"""
254-
return self.send_command("/homeassistant/restart")
255-
256-
@_api_bool
257-
def stop_homeassistant(self) -> Coroutine:
258-
"""Stop Home-Assistant container.
259-
260-
This method returns a coroutine.
261-
"""
262-
return self.send_command("/homeassistant/stop")
263-
264-
@_api_bool
265-
def refresh_updates(self) -> Coroutine:
266-
"""Refresh available updates.
267-
268-
This method returns a coroutine.
269-
"""
270-
return self.send_command("/refresh_updates", timeout=300)
271-
272248
@api_data
273249
def get_resolution_info(self) -> Coroutine:
274250
"""Return data for Supervisor resolution center.

tests/components/hassio/conftest.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ def hassio_stubs(
7474
patch(
7575
"homeassistant.components.hassio.issues.SupervisorIssues.setup",
7676
),
77-
patch(
78-
"homeassistant.components.hassio.HassIO.refresh_updates",
79-
),
8077
):
8178
hass.set_state(CoreState.starting)
8279
hass.loop.run_until_complete(async_setup_component(hass, "hassio", {}))
@@ -140,7 +137,6 @@ def all_setup_requests(
140137
)
141138

142139
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
143-
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})
144140
aioclient_mock.post("http://127.0.0.1/supervisor/options", json={"result": "ok"})
145141
aioclient_mock.get(
146142
"http://127.0.0.1/info",
@@ -221,7 +217,6 @@ def all_setup_requests(
221217
aioclient_mock.get(
222218
"http://127.0.0.1/ingress/panels", json={"result": "ok", "data": {"panels": {}}}
223219
)
224-
aioclient_mock.post("http://127.0.0.1/refresh_updates", json={"result": "ok"})
225220

226221
addon_installed.return_value.update_available = False
227222
addon_installed.return_value.version = "1.0.0"

tests/components/hassio/test_addon_panel.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Test add-on panel."""
22

33
from http import HTTPStatus
4-
from unittest.mock import patch
4+
from unittest.mock import AsyncMock, patch
55

66
import pytest
77

@@ -13,10 +13,11 @@
1313

1414

1515
@pytest.fixture(autouse=True)
16-
def mock_all(aioclient_mock: AiohttpClientMocker) -> None:
16+
def mock_all(
17+
aioclient_mock: AiohttpClientMocker, supervisor_is_connected: AsyncMock
18+
) -> None:
1719
"""Mock all setup requests."""
1820
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
19-
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})
2021
aioclient_mock.post("http://127.0.0.1/supervisor/options", json={"result": "ok"})
2122
aioclient_mock.get(
2223
"http://127.0.0.1/homeassistant/info",

tests/components/hassio/test_binary_sensor.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def mock_all(
2828
) -> None:
2929
"""Mock all setup requests."""
3030
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
31-
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})
3231
aioclient_mock.post("http://127.0.0.1/supervisor/options", json={"result": "ok"})
3332
aioclient_mock.get(
3433
"http://127.0.0.1/info",
@@ -141,7 +140,6 @@ def mock_all(
141140
aioclient_mock.get(
142141
"http://127.0.0.1/ingress/panels", json={"result": "ok", "data": {"panels": {}}}
143142
)
144-
aioclient_mock.post("http://127.0.0.1/refresh_updates", json={"result": "ok"})
145143
aioclient_mock.get(
146144
"http://127.0.0.1/resolution/info",
147145
json={

tests/components/hassio/test_diagnostics.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def mock_all(
2727
) -> None:
2828
"""Mock all setup requests."""
2929
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
30-
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})
3130
aioclient_mock.post("http://127.0.0.1/supervisor/options", json={"result": "ok"})
3231
aioclient_mock.get(
3332
"http://127.0.0.1/info",
@@ -144,7 +143,6 @@ def mock_all(
144143
aioclient_mock.get(
145144
"http://127.0.0.1/ingress/panels", json={"result": "ok", "data": {"panels": {}}}
146145
)
147-
aioclient_mock.post("http://127.0.0.1/refresh_updates", json={"result": "ok"})
148146
aioclient_mock.get(
149147
"http://127.0.0.1/resolution/info",
150148
json={

tests/components/hassio/test_handler.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,6 @@ async def test_api_core_info_error(
150150
assert aioclient_mock.call_count == 1
151151

152152

153-
async def test_api_homeassistant_stop(
154-
hassio_handler: HassIO, aioclient_mock: AiohttpClientMocker
155-
) -> None:
156-
"""Test setup with API Home Assistant stop."""
157-
aioclient_mock.post("http://127.0.0.1/homeassistant/stop", json={"result": "ok"})
158-
159-
assert await hassio_handler.stop_homeassistant()
160-
assert aioclient_mock.call_count == 1
161-
162-
163-
async def test_api_homeassistant_restart(
164-
hassio_handler: HassIO, aioclient_mock: AiohttpClientMocker
165-
) -> None:
166-
"""Test setup with API Home Assistant restart."""
167-
aioclient_mock.post("http://127.0.0.1/homeassistant/restart", json={"result": "ok"})
168-
169-
assert await hassio_handler.restart_homeassistant()
170-
assert aioclient_mock.call_count == 1
171-
172-
173153
async def test_api_core_stats(
174154
hassio_handler: HassIO, aioclient_mock: AiohttpClientMocker
175155
) -> None:
@@ -229,7 +209,6 @@ async def test_api_ingress_panels(
229209
("api_call", "method", "payload"),
230210
[
231211
("get_resolution_info", "GET", None),
232-
("refresh_updates", "POST", None),
233212
("update_diagnostics", "POST", True),
234213
],
235214
)

0 commit comments

Comments
 (0)