mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-18 22:56:31 +00:00
Fix network API default value & tests (#2234)
This commit is contained in:
parent
edc8d8960f
commit
9264d437b1
@ -181,11 +181,23 @@ class APINetwork(CoreSysAttributes):
|
|||||||
# Apply config
|
# Apply config
|
||||||
for key, config in body.items():
|
for key, config in body.items():
|
||||||
if key == ATTR_IPV4:
|
if key == ATTR_IPV4:
|
||||||
interface.ipv4 = attr.evolve(interface.ipv4, **config)
|
interface.ipv4 = attr.evolve(
|
||||||
|
interface.ipv4 or IpConfig(InterfaceMethod.STATIC, [], None, []),
|
||||||
|
**config,
|
||||||
|
)
|
||||||
elif key == ATTR_IPV6:
|
elif key == ATTR_IPV6:
|
||||||
interface.ipv6 = attr.evolve(interface.ipv6, **config)
|
interface.ipv6 = attr.evolve(
|
||||||
|
interface.ipv6 or IpConfig(InterfaceMethod.STATIC, [], None, []),
|
||||||
|
**config,
|
||||||
|
)
|
||||||
elif key == ATTR_WIFI:
|
elif key == ATTR_WIFI:
|
||||||
interface.wifi = attr.evolve(interface.wifi, **config)
|
interface.wifi = attr.evolve(
|
||||||
|
interface.wifi
|
||||||
|
or WifiConfig(
|
||||||
|
WifiMode.INFRASTRUCTURE, "", AuthMethod.OPEN, None, None
|
||||||
|
),
|
||||||
|
**config,
|
||||||
|
)
|
||||||
elif key == ATTR_ENABLED:
|
elif key == ATTR_ENABLED:
|
||||||
interface.enabled = config
|
interface.enabled = config
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ class NetworkManager(CoreSysAttributes):
|
|||||||
raise HostNetworkError() from err
|
raise HostNetworkError() from err
|
||||||
|
|
||||||
# Remove config from interface
|
# Remove config from interface
|
||||||
elif inet and not interface.enabled:
|
elif inet and inet.settings and not interface.enabled:
|
||||||
try:
|
try:
|
||||||
await inet.settings.delete()
|
await inet.settings.delete()
|
||||||
except DBusError as err:
|
except DBusError as err:
|
||||||
@ -126,6 +126,9 @@ class NetworkManager(CoreSysAttributes):
|
|||||||
except DBusError as err:
|
except DBusError as err:
|
||||||
_LOGGER.error("Can't create new interface")
|
_LOGGER.error("Can't create new interface")
|
||||||
raise HostNetworkError() from err
|
raise HostNetworkError() from err
|
||||||
|
else:
|
||||||
|
_LOGGER.warning("Requested Network interface update is not possible")
|
||||||
|
raise HostNetworkError()
|
||||||
|
|
||||||
await self.update()
|
await self.update()
|
||||||
|
|
||||||
|
@ -99,6 +99,37 @@ async def test_api_network_interface_update(api_client):
|
|||||||
assert result["result"] == "ok"
|
assert result["result"] == "ok"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_api_network_interface_update_wifi(api_client):
|
||||||
|
"""Test network manager api."""
|
||||||
|
resp = await api_client.post(
|
||||||
|
f"/network/interface/{TEST_INTERFACE_WLAN}/update",
|
||||||
|
json={
|
||||||
|
"enabled": True,
|
||||||
|
"ipv4": {
|
||||||
|
"method": "static",
|
||||||
|
"nameservers": ["1.1.1.1"],
|
||||||
|
"address": ["192.168.2.148/24"],
|
||||||
|
"gateway": "192.168.1.1",
|
||||||
|
},
|
||||||
|
"wifi": {"ssid": "MY_TEST", "auth": "wpa-psk", "psk": "myWifiPassword"},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
result = await resp.json()
|
||||||
|
assert result["result"] == "ok"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_api_network_interface_update_remove(api_client):
|
||||||
|
"""Test network manager api."""
|
||||||
|
resp = await api_client.post(
|
||||||
|
f"/network/interface/{TEST_INTERFACE}/update",
|
||||||
|
json={"enabled": False},
|
||||||
|
)
|
||||||
|
result = await resp.json()
|
||||||
|
assert result["result"] == "ok"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_api_network_interface_info_invalid(api_client):
|
async def test_api_network_interface_info_invalid(api_client):
|
||||||
"""Test network manager api."""
|
"""Test network manager api."""
|
||||||
|
1
tests/fixtures/org_freedesktop_NetworkManager-AddAndActivateConnection.fixture
vendored
Normal file
1
tests/fixtures/org_freedesktop_NetworkManager-AddAndActivateConnection.fixture
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
()
|
1
tests/fixtures/org_freedesktop_NetworkManager_Settings_1-Delete.fixture
vendored
Normal file
1
tests/fixtures/org_freedesktop_NetworkManager_Settings_1-Delete.fixture
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
()
|
Loading…
x
Reference in New Issue
Block a user