Skip to content

Commit 5d07dd2

Browse files
authored
Add country to Supervisor info (#5826)
Similar to timezone also add country information to the Supervisor info. This is useful to set country specific configurations such as Wireless radio regulatory setting. This is also useful for add-ons which need country information but only have hassio API access.
1 parent adfb433 commit 5d07dd2

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

supervisor/api/supervisor.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
ATTR_BLK_WRITE,
1818
ATTR_CHANNEL,
1919
ATTR_CONTENT_TRUST,
20+
ATTR_COUNTRY,
2021
ATTR_CPU_PERCENT,
2122
ATTR_DEBUG,
2223
ATTR_DEBUG_BLOCK,
@@ -76,6 +77,7 @@
7677
vol.Optional(ATTR_FORCE_SECURITY): vol.Boolean(),
7778
vol.Optional(ATTR_AUTO_UPDATE): vol.Boolean(),
7879
vol.Optional(ATTR_DETECT_BLOCKING_IO): vol.Coerce(DetectBlockingIO),
80+
vol.Optional(ATTR_COUNTRY): str,
7981
}
8082
)
8183

@@ -109,6 +111,7 @@ async def info(self, request: web.Request) -> dict[str, Any]:
109111
ATTR_DIAGNOSTICS: self.sys_config.diagnostics,
110112
ATTR_AUTO_UPDATE: self.sys_updater.auto_update,
111113
ATTR_DETECT_BLOCKING_IO: blockbuster_enabled(),
114+
ATTR_COUNTRY: self.sys_config.country,
112115
# Depricated
113116
ATTR_WAIT_BOOT: self.sys_config.wait_boot,
114117
ATTR_ADDONS: [
@@ -147,6 +150,9 @@ async def options(self, request: web.Request) -> None:
147150
if ATTR_CHANNEL in body:
148151
self.sys_updater.channel = body[ATTR_CHANNEL]
149152

153+
if ATTR_COUNTRY in body:
154+
self.sys_config.country = body[ATTR_COUNTRY]
155+
150156
if ATTR_DEBUG in body:
151157
self.sys_config.debug = body[ATTR_DEBUG]
152158

supervisor/config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from .const import (
1212
ATTR_ADDONS_CUSTOM_LIST,
13+
ATTR_COUNTRY,
1314
ATTR_DEBUG,
1415
ATTR_DEBUG_BLOCK,
1516
ATTR_DETECT_BLOCKING_IO,
@@ -93,6 +94,20 @@ async def set_timezone(self, value: str) -> None:
9394
None, get_time_zone, value
9495
)
9596

97+
@property
98+
def country(self) -> str | None:
99+
"""Return supervisor country.
100+
101+
The format follows what Home Assistant Core provides, which today is
102+
ISO 3166-1 alpha-2.
103+
"""
104+
return self._data.get(ATTR_COUNTRY)
105+
106+
@country.setter
107+
def country(self, value: str | None) -> None:
108+
"""Set supervisor country."""
109+
self._data[ATTR_COUNTRY] = value
110+
96111
@property
97112
def version(self) -> AwesomeVersion:
98113
"""Return supervisor version."""

supervisor/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
ATTR_CONTAINERS = "containers"
141141
ATTR_CONTENT = "content"
142142
ATTR_CONTENT_TRUST = "content_trust"
143+
ATTR_COUNTRY = "country"
143144
ATTR_CPE = "cpe"
144145
ATTR_CPU_PERCENT = "cpu_percent"
145146
ATTR_CRYPTO = "crypto"

supervisor/validate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
ATTR_CHANNEL,
1414
ATTR_CLI,
1515
ATTR_CONTENT_TRUST,
16+
ATTR_COUNTRY,
1617
ATTR_DEBUG,
1718
ATTR_DEBUG_BLOCK,
1819
ATTR_DETECT_BLOCKING_IO,
@@ -164,6 +165,7 @@ def validate_repository(repository: str) -> str:
164165
vol.Optional(ATTR_DEBUG_BLOCK, default=False): vol.Boolean(),
165166
vol.Optional(ATTR_DIAGNOSTICS, default=None): vol.Maybe(vol.Boolean()),
166167
vol.Optional(ATTR_DETECT_BLOCKING_IO, default=False): vol.Boolean(),
168+
vol.Optional(ATTR_COUNTRY): str,
167169
},
168170
extra=vol.REMOVE_EXTRA,
169171
)

tests/api/test_supervisor.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,21 @@ async def test_api_supervisor_options_timezone(
252252
assert coresys.timezone == "Europe/Zurich"
253253

254254

255+
async def test_api_supervisor_options_country(api_client: TestClient, coresys: CoreSys):
256+
"""Test setting supervisor country via API."""
257+
assert coresys.config.country is None
258+
259+
resp = await api_client.post("/supervisor/options", json={"country": "CH"})
260+
assert resp.status == 200
261+
262+
assert coresys.config.country == "CH"
263+
264+
resp = await api_client.get("/supervisor/info")
265+
assert resp.status == 200
266+
body = await resp.json()
267+
assert body["data"]["country"] == "CH"
268+
269+
255270
@pytest.mark.parametrize(
256271
("blockbuster", "option_value", "config_value"),
257272
[("no_blockbuster", "on", False), ("no_blockbuster", "on_at_startup", True)],

0 commit comments

Comments
 (0)