Skip to content

Commit

Permalink
Improve WiFi settings error handling
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
agners committed Sep 5, 2024
1 parent bb8f91e commit 641f457
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 6 additions & 4 deletions supervisor/dbus/network/setting/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
5 changes: 4 additions & 1 deletion supervisor/host/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 641f457

Please sign in to comment.