Skip to content

Commit 1c4c5d8

Browse files
committed
Separate rebuild options and test passing options
1 parent 60d685a commit 1c4c5d8

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

aiohasupervisor/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from aiohasupervisor.models.homeassistant import (
2727
HomeAssistantInfo,
2828
HomeAssistantOptions,
29+
HomeAssistantRebuildOptions,
2930
HomeAssistantRestartOptions,
3031
HomeAssistantStats,
3132
HomeAssistantStopOptions,
@@ -96,6 +97,7 @@
9697
"UnsupportedReason",
9798
"HomeAssistantInfo",
9899
"HomeAssistantOptions",
100+
"HomeAssistantRebuildOptions",
99101
"HomeAssistantRestartOptions",
100102
"HomeAssistantStats",
101103
"HomeAssistantStopOptions",

aiohasupervisor/models/homeassistant.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ class HomeAssistantRestartOptions(Options):
6464
force: bool | None = None
6565

6666

67+
@dataclass(frozen=True, slots=True)
68+
class HomeAssistantRebuildOptions(Options):
69+
"""HomeAssistantRebuildOptions model."""
70+
71+
safe_mode: bool | None = None
72+
force: bool | None = None
73+
74+
6775
@dataclass(frozen=True, slots=True)
6876
class HomeAssistantStopOptions(Request):
6977
"""HomeAssistantStopOptions model."""

tests/test_homeassistant.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,17 @@
33
from ipaddress import IPv4Address
44

55
from aioresponses import aioresponses
6+
import pytest
67
from yarl import URL
78

89
from aiohasupervisor import SupervisorClient
9-
from aiohasupervisor.models import HomeAssistantOptions
10+
from aiohasupervisor.models import (
11+
HomeAssistantOptions,
12+
HomeAssistantRebuildOptions,
13+
HomeAssistantRestartOptions,
14+
HomeAssistantStopOptions,
15+
HomeAssistantUpdateOptions,
16+
)
1017

1118
from . import load_fixture
1219
from .const import SUPERVISOR_URL
@@ -64,32 +71,41 @@ async def test_homeassistant_options(
6471
}
6572

6673

74+
@pytest.mark.parametrize("options", [None, HomeAssistantUpdateOptions(backup=False)])
6775
async def test_homeassistant_update(
68-
responses: aioresponses, supervisor_client: SupervisorClient
76+
responses: aioresponses,
77+
supervisor_client: SupervisorClient,
78+
options: HomeAssistantUpdateOptions | None,
6979
) -> None:
7080
"""Test Home Assistant update API."""
7181
responses.post(f"{SUPERVISOR_URL}/core/update", status=200)
72-
assert await supervisor_client.homeassistant.update() is None
82+
assert await supervisor_client.homeassistant.update(options) is None
7383
assert responses.requests.keys() == {("POST", URL(f"{SUPERVISOR_URL}/core/update"))}
7484

7585

86+
@pytest.mark.parametrize("options", [None, HomeAssistantRestartOptions(safe_mode=True)])
7687
async def test_homeassistant_restart(
77-
responses: aioresponses, supervisor_client: SupervisorClient
88+
responses: aioresponses,
89+
supervisor_client: SupervisorClient,
90+
options: HomeAssistantRestartOptions | None,
7891
) -> None:
7992
"""Test Home Assistant restart API."""
8093
responses.post(f"{SUPERVISOR_URL}/core/restart", status=200)
81-
assert await supervisor_client.homeassistant.restart() is None
94+
assert await supervisor_client.homeassistant.restart(options) is None
8295
assert responses.requests.keys() == {
8396
("POST", URL(f"{SUPERVISOR_URL}/core/restart"))
8497
}
8598

8699

100+
@pytest.mark.parametrize("options", [None, HomeAssistantStopOptions(force=True)])
87101
async def test_homeassistant_stop(
88-
responses: aioresponses, supervisor_client: SupervisorClient
102+
responses: aioresponses,
103+
supervisor_client: SupervisorClient,
104+
options: HomeAssistantStopOptions | None,
89105
) -> None:
90106
"""Test Home Assistant stop API."""
91107
responses.post(f"{SUPERVISOR_URL}/core/stop", status=200)
92-
assert await supervisor_client.homeassistant.stop() is None
108+
assert await supervisor_client.homeassistant.stop(options) is None
93109
assert responses.requests.keys() == {("POST", URL(f"{SUPERVISOR_URL}/core/stop"))}
94110

95111

@@ -111,12 +127,15 @@ async def test_homeassistant_check_config(
111127
assert responses.requests.keys() == {("POST", URL(f"{SUPERVISOR_URL}/core/check"))}
112128

113129

130+
@pytest.mark.parametrize("options", [None, HomeAssistantRebuildOptions(safe_mode=True)])
114131
async def test_homeassistant_rebuild(
115-
responses: aioresponses, supervisor_client: SupervisorClient
132+
responses: aioresponses,
133+
supervisor_client: SupervisorClient,
134+
options: HomeAssistantRebuildOptions | None,
116135
) -> None:
117136
"""Test Home Assistant rebuild API."""
118137
responses.post(f"{SUPERVISOR_URL}/core/rebuild", status=200)
119-
assert await supervisor_client.homeassistant.rebuild() is None
138+
assert await supervisor_client.homeassistant.rebuild(options) is None
120139
assert responses.requests.keys() == {
121140
("POST", URL(f"{SUPERVISOR_URL}/core/rebuild"))
122141
}

0 commit comments

Comments
 (0)