1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2025-12-24 12:29:08 +00:00

Make network API replace IP/WiFi settings (#5283)

* Allow to set user DNS through API with auto mode

Currently it is only possible to set DNS servers when in static mode.
However, there are use cases to set DNS servers when in auto mode as
well, e.g. if no local DNS server is provided by the DHCP, or the provided
DNS turns out to be non-working.

* Fix use separate data structure for IP configuration fallout

Make sure gateway is correctly converted to the internal IP
representation. Fix type info.

* Overwrite WiFi settings completely too

* Add test for DNS configuration

* Run ruff format

* ruff format

* Use schema validation as source for API defaults

Instead of using replace() simply set the API defaults in the API
schema.

* Revert "Use schema validation as source for API defaults"

This reverts commit 885506fd37.

* Use explicit dataclass initialization

This avoid the unnecessary replaces from before. It also makes it more
obvious that this part of the API doesn't patch existing settings.
This commit is contained in:
Stefan Agner
2024-09-05 09:19:13 +02:00
committed by GitHub
parent 05e0c7c3ab
commit f5b996b66c
7 changed files with 129 additions and 87 deletions

View File

@@ -184,7 +184,7 @@ async def test_api_network_interface_update_ethernet(
assert settings["ipv4"]["dns"] == Variant("au", [16843009])
assert settings["ipv4"]["gateway"] == Variant("s", "192.168.2.1")
# Partial static configuration, updates only provided settings (e.g. by CLI)
# Partial static configuration, clears other settings (e.g. by CLI)
resp = await api_client.post(
f"/network/interface/{TEST_INTERFACE_ETH_NAME}/update",
json={
@@ -205,8 +205,8 @@ async def test_api_network_interface_update_ethernet(
"aa{sv}",
[{"address": Variant("s", "192.168.2.149"), "prefix": Variant("u", 24)}],
)
assert settings["ipv4"]["dns"] == Variant("au", [16843009])
assert settings["ipv4"]["gateway"] == Variant("s", "192.168.2.1")
assert "dns" not in settings["ipv4"]
assert "gateway" not in settings["ipv4"]
# Auto configuration, clears all settings (represents frontend auto config)
resp = await api_client.post(
@@ -214,6 +214,7 @@ async def test_api_network_interface_update_ethernet(
json={
"ipv4": {
"method": "auto",
"nameservers": ["8.8.8.8"],
}
},
)
@@ -228,7 +229,7 @@ async def test_api_network_interface_update_ethernet(
assert "address-data" not in settings["ipv4"]
assert "addresses" not in settings["ipv4"]
assert "dns-data" not in settings["ipv4"]
assert "dns" not in settings["ipv4"]
assert settings["ipv4"]["dns"] == Variant("au", [134744072])
assert "gateway" not in settings["ipv4"]