From 641f4571f64580cc3733679dea97857960886808 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 5 Sep 2024 18:06:30 +0200 Subject: [PATCH] Improve WiFi settings error handling Currently, the frontend potentially provides no WiFi settings dictionary but still tries to update other (IP address) settings on the interface. This leads to a stack trace since network manager is not able to fetch the WiFi settings from the settings dictionary. Simply fill out what we can and let NetworkManager provide an error. Also allow to disable a network interface which has no configuration. This avoids an error when switching to auto and back to disabled then press save on a new wireless network interface. --- supervisor/dbus/network/setting/generate.py | 10 ++++++---- supervisor/host/network.py | 5 ++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/supervisor/dbus/network/setting/generate.py b/supervisor/dbus/network/setting/generate.py index 0f59fc53fc4..554c5b230e7 100644 --- a/supervisor/dbus/network/setting/generate.py +++ b/supervisor/dbus/network/setting/generate.py @@ -199,15 +199,17 @@ def get_connection_from_interface( elif interface.type == InterfaceType.WIRELESS: wireless = { CONF_ATTR_802_WIRELESS_ASSIGNED_MAC: Variant("s", "preserve"), - CONF_ATTR_802_WIRELESS_SSID: Variant( - "ay", interface.wifi.ssid.encode("UTF-8") - ), CONF_ATTR_802_WIRELESS_MODE: Variant("s", "infrastructure"), CONF_ATTR_802_WIRELESS_POWERSAVE: Variant("i", 1), } + if interface.wifi and interface.wifi.ssid: + wireless[CONF_ATTR_802_WIRELESS_SSID] = Variant( + "ay", interface.wifi.ssid.encode("UTF-8") + ) + conn[CONF_ATTR_802_WIRELESS] = wireless - if interface.wifi.auth != "open": + if interface.wifi and interface.wifi.auth != "open": wireless["security"] = Variant("s", CONF_ATTR_802_WIRELESS_SECURITY) wireless_security = {} if interface.wifi.auth == "wep": diff --git a/supervisor/host/network.py b/supervisor/host/network.py index 57e288b12b6..eb71a622ee7 100644 --- a/supervisor/host/network.py +++ b/supervisor/host/network.py @@ -236,7 +236,10 @@ async def apply_changes( ) from err # Remove config from interface - elif inet and inet.settings and not interface.enabled: + elif inet and not interface.enabled: + if not inet.settings: + # It was and is disabled, that is fine + return try: await inet.settings.delete() except DBusError as err: