Skip to content

Commit

Permalink
Rename action methods without verb (#22)
Browse files Browse the repository at this point in the history
* Alias addon action methods without verb

* Rename action methods without verb
  • Loading branch information
mdegat01 authored Oct 26, 2024
1 parent 0089da8 commit a32315c
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 18 deletions.
8 changes: 5 additions & 3 deletions aiohasupervisor/addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def restart_addon(self, addon: str) -> None:
"""Restart an addon."""
await self._client.post(f"addons/{addon}/restart", timeout=None)

async def addon_options(self, addon: str, options: AddonsOptions) -> None:
async def set_addon_options(self, addon: str, options: AddonsOptions) -> None:
"""Set options for addon."""
await self._client.post(f"addons/{addon}/options", json=options.to_dict())

Expand All @@ -79,11 +79,13 @@ async def rebuild_addon(self, addon: str) -> None:
"""Rebuild an addon (only available for local addons built from source)."""
await self._client.post(f"addons/{addon}/rebuild")

async def addon_stdin(self, addon: str, stdin: bytes) -> None:
async def write_addon_stdin(self, addon: str, stdin: bytes) -> None:
"""Write to stdin of an addon (if supported by addon)."""
await self._client.post(f"addons/{addon}/stdin", data=stdin)

async def addon_security(self, addon: str, options: AddonsSecurityOptions) -> None:
async def set_addon_security(
self, addon: str, options: AddonsSecurityOptions
) -> None:
"""Set security options for addon."""
await self._client.post(f"addons/{addon}/security", json=options.to_dict())

Expand Down
2 changes: 1 addition & 1 deletion aiohasupervisor/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def info(self) -> BackupsInfo:
result = await self._client.get("backups/info")
return BackupsInfo.from_dict(result.data)

async def options(self, options: BackupsOptions) -> None:
async def set_options(self, options: BackupsOptions) -> None:
"""Set options for backups."""
await self._client.post("backups/options", json=options.to_dict())

Expand Down
2 changes: 1 addition & 1 deletion aiohasupervisor/homeassistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def stats(self) -> HomeAssistantStats:
result = await self._client.get("core/stats")
return HomeAssistantStats.from_dict(result.data)

async def options(self, options: HomeAssistantOptions) -> None:
async def set_options(self, options: HomeAssistantOptions) -> None:
"""Set Home Assistant options."""
await self._client.post("core/options", json=options.to_dict())

Expand Down
2 changes: 1 addition & 1 deletion aiohasupervisor/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def reload(self) -> None:
"""Reload host info cache."""
await self._client.post("host/reload")

async def options(self, options: HostOptions) -> None:
async def set_options(self, options: HostOptions) -> None:
"""Set host options."""
await self._client.post("host/options", json=options.to_dict())

Expand Down
4 changes: 2 additions & 2 deletions aiohasupervisor/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def green_info(self) -> GreenInfo:
result = await self._client.get("os/boards/green")
return GreenInfo.from_dict(result.data)

async def green_options(self, options: GreenOptions) -> None:
async def set_green_options(self, options: GreenOptions) -> None:
"""Set options for green board (if in use)."""
await self._client.post("os/boards/green", json=options.to_dict())

Expand All @@ -64,6 +64,6 @@ async def yellow_info(self) -> YellowInfo:
result = await self._client.get("os/boards/yellow")
return YellowInfo.from_dict(result.data)

async def yellow_options(self, options: YellowOptions) -> None:
async def set_yellow_options(self, options: YellowOptions) -> None:
"""Set options for yellow board (if in use)."""
await self._client.post("os/boards/yellow", json=options.to_dict())
2 changes: 1 addition & 1 deletion aiohasupervisor/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def restart(self) -> None:
"""Restart supervisor."""
await self._client.post("supervisor/restart")

async def options(self, options: SupervisorOptions) -> None:
async def set_options(self, options: SupervisorOptions) -> None:
"""Set supervisor options."""
await self._client.post("supervisor/options", json=options.to_dict())

Expand Down
7 changes: 4 additions & 3 deletions tests/test_addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async def test_addons_options(
"""Test addon options API."""
responses.post(f"{SUPERVISOR_URL}/addons/core_ssh/options", status=200)
assert (
await supervisor_client.addons.addon_options(
await supervisor_client.addons.set_addon_options(
"core_ssh",
AddonsOptions(
config=None,
Expand Down Expand Up @@ -195,7 +195,8 @@ async def test_addons_stdin(
"""Test addon stdin API."""
responses.post(f"{SUPERVISOR_URL}/addons/core_ssh/stdin", status=200)
assert (
await supervisor_client.addons.addon_stdin("core_ssh", b"hello world") is None
await supervisor_client.addons.write_addon_stdin("core_ssh", b"hello world")
is None
)
assert len(responses.requests) == 1
assert (
Expand All @@ -212,7 +213,7 @@ async def test_addons_security(
"""Test addon security API."""
responses.post(f"{SUPERVISOR_URL}/addons/core_ssh/security", status=200)
assert (
await supervisor_client.addons.addon_security(
await supervisor_client.addons.set_addon_security(
"core_ssh", AddonsSecurityOptions(protected=True)
)
is None
Expand Down
2 changes: 1 addition & 1 deletion tests/test_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async def test_backups_options(
"""Test backups options API."""
responses.post(f"{SUPERVISOR_URL}/backups/options", status=200)
assert (
await supervisor_client.backups.options(BackupsOptions(days_until_stale=10))
await supervisor_client.backups.set_options(BackupsOptions(days_until_stale=10))
is None
)
assert responses.requests.keys() == {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_homeassistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async def test_homeassistant_options(
"""Test Home Assistant options API."""
responses.post(f"{SUPERVISOR_URL}/core/options", status=200)
assert (
await supervisor_client.homeassistant.options(
await supervisor_client.homeassistant.set_options(
HomeAssistantOptions(watchdog=False, backups_exclude_database=True)
)
is None
Expand Down
4 changes: 3 additions & 1 deletion tests/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ async def test_host_options(
) -> None:
"""Test host options API."""
responses.post(f"{SUPERVISOR_URL}/host/options", status=200)
assert await supervisor_client.host.options(HostOptions(hostname="test")) is None
assert (
await supervisor_client.host.set_options(HostOptions(hostname="test")) is None
)
assert responses.requests.keys() == {
("POST", URL(f"{SUPERVISOR_URL}/host/options"))
}
Expand Down
6 changes: 4 additions & 2 deletions tests/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async def test_os_green_options(
"""Test OS green board options API."""
responses.post(f"{SUPERVISOR_URL}/os/boards/green", status=200)
assert (
await supervisor_client.os.green_options(GreenOptions(activity_led=False))
await supervisor_client.os.set_green_options(GreenOptions(activity_led=False))
is None
)
assert responses.requests.keys() == {
Expand Down Expand Up @@ -170,7 +170,9 @@ async def test_os_yellow_options(
"""Test OS yellow board options API."""
responses.post(f"{SUPERVISOR_URL}/os/boards/yellow", status=200)
assert (
await supervisor_client.os.yellow_options(YellowOptions(heartbeat_led=False))
await supervisor_client.os.set_yellow_options(
YellowOptions(heartbeat_led=False)
)
is None
)
assert responses.requests.keys() == {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def test_supervisor_options(
"""Test supervisor options API."""
responses.post(f"{SUPERVISOR_URL}/supervisor/options", status=200)
assert (
await supervisor_client.supervisor.options(
await supervisor_client.supervisor.set_options(
SupervisorOptions(debug=True, debug_block=True)
)
is None
Expand Down

0 comments on commit a32315c

Please sign in to comment.