Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions supervisor/api/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
ATTR_BLK_WRITE,
ATTR_CHANNEL,
ATTR_CONTENT_TRUST,
ATTR_COUNTRY,
ATTR_CPU_PERCENT,
ATTR_DEBUG,
ATTR_DEBUG_BLOCK,
Expand Down Expand Up @@ -76,6 +77,7 @@
vol.Optional(ATTR_FORCE_SECURITY): vol.Boolean(),
vol.Optional(ATTR_AUTO_UPDATE): vol.Boolean(),
vol.Optional(ATTR_DETECT_BLOCKING_IO): vol.Coerce(DetectBlockingIO),
vol.Optional(ATTR_COUNTRY): str,
}
)

Expand Down Expand Up @@ -109,6 +111,7 @@ async def info(self, request: web.Request) -> dict[str, Any]:
ATTR_DIAGNOSTICS: self.sys_config.diagnostics,
ATTR_AUTO_UPDATE: self.sys_updater.auto_update,
ATTR_DETECT_BLOCKING_IO: blockbuster_enabled(),
ATTR_COUNTRY: self.sys_config.country,
# Depricated
ATTR_WAIT_BOOT: self.sys_config.wait_boot,
ATTR_ADDONS: [
Expand Down Expand Up @@ -147,6 +150,9 @@ async def options(self, request: web.Request) -> None:
if ATTR_CHANNEL in body:
self.sys_updater.channel = body[ATTR_CHANNEL]

if ATTR_COUNTRY in body:
self.sys_config.country = body[ATTR_COUNTRY]

if ATTR_DEBUG in body:
self.sys_config.debug = body[ATTR_DEBUG]

Expand Down
15 changes: 15 additions & 0 deletions supervisor/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from .const import (
ATTR_ADDONS_CUSTOM_LIST,
ATTR_COUNTRY,
ATTR_DEBUG,
ATTR_DEBUG_BLOCK,
ATTR_DETECT_BLOCKING_IO,
Expand Down Expand Up @@ -93,6 +94,20 @@ async def set_timezone(self, value: str) -> None:
None, get_time_zone, value
)

@property
def country(self) -> str | None:
"""Return supervisor country.

The format follows what Home Assistant Core provides, which today is
ISO 3166-1 alpha-2.
"""
return self._data.get(ATTR_COUNTRY)

@country.setter
def country(self, value: str | None) -> None:
"""Set supervisor country."""
self._data[ATTR_COUNTRY] = value

@property
def version(self) -> AwesomeVersion:
"""Return supervisor version."""
Expand Down
1 change: 1 addition & 0 deletions supervisor/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
ATTR_CONTAINERS = "containers"
ATTR_CONTENT = "content"
ATTR_CONTENT_TRUST = "content_trust"
ATTR_COUNTRY = "country"
ATTR_CPE = "cpe"
ATTR_CPU_PERCENT = "cpu_percent"
ATTR_CRYPTO = "crypto"
Expand Down
2 changes: 2 additions & 0 deletions supervisor/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ATTR_CHANNEL,
ATTR_CLI,
ATTR_CONTENT_TRUST,
ATTR_COUNTRY,
ATTR_DEBUG,
ATTR_DEBUG_BLOCK,
ATTR_DETECT_BLOCKING_IO,
Expand Down Expand Up @@ -164,6 +165,7 @@ def validate_repository(repository: str) -> str:
vol.Optional(ATTR_DEBUG_BLOCK, default=False): vol.Boolean(),
vol.Optional(ATTR_DIAGNOSTICS, default=None): vol.Maybe(vol.Boolean()),
vol.Optional(ATTR_DETECT_BLOCKING_IO, default=False): vol.Boolean(),
vol.Optional(ATTR_COUNTRY): str,
},
extra=vol.REMOVE_EXTRA,
)
Expand Down
15 changes: 15 additions & 0 deletions tests/api/test_supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,21 @@ async def test_api_supervisor_options_timezone(
assert coresys.timezone == "Europe/Zurich"


async def test_api_supervisor_options_country(api_client: TestClient, coresys: CoreSys):
"""Test setting supervisor country via API."""
assert coresys.config.country is None

resp = await api_client.post("/supervisor/options", json={"country": "CH"})
assert resp.status == 200

assert coresys.config.country == "CH"

resp = await api_client.get("/supervisor/info")
assert resp.status == 200
body = await resp.json()
assert body["data"]["country"] == "CH"


@pytest.mark.parametrize(
("blockbuster", "option_value", "config_value"),
[("no_blockbuster", "on", False), ("no_blockbuster", "on_at_startup", True)],
Expand Down