Skip to content

Commit

Permalink
fix: remove data folder, not needed anymore
Browse files Browse the repository at this point in the history
fix: better error handling for networking page
  • Loading branch information
Stefano Bertelli committed Jun 7, 2024
1 parent ac84a9e commit 9794b17
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
9 changes: 5 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions rotary_controller_python/data/units.json

This file was deleted.

40 changes: 31 additions & 9 deletions rotary_controller_python/network/networkmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ def get_all_network_interface_names(
def get_profile_by_id(profile_id: str = "ospi") -> ConnectionProfile or None:
nms = NetworkManagerSettings()
connections = nms.list_connections()
profiles = [NetworkConnectionSettings(item).get_profile() for item in connections]
profiles = []
for item in connections:
try:
profile = NetworkConnectionSettings(item).get_profile()
profiles.append(profile)
except Exception as e:
log.error(e.__str__())

wlan_profiles = [item for item in profiles if item.connection.connection_id == profile_id]

if len(wlan_profiles) == 1:
Expand All @@ -69,26 +76,41 @@ def get_profile_by_id(profile_id: str = "ospi") -> ConnectionProfile or None:


def get_psk(profile: ConnectionProfile) -> str:
return profile.wireless_security.psk
if profile is None:
return ""
else:
return profile.wireless_security.psk


def get_ssid(profile: ConnectionProfile) -> str:
return profile.wireless.ssid.decode("UTF-8")
if profile is None:
return ""
else:
return profile.wireless.ssid.decode("UTF-8")


def get_connection_method(profile: ConnectionProfile) -> str:
return profile.ipv4.method
if profile is None:
return ""
else:
return profile.ipv4.method


def get_connection_by_profile(profile: ConnectionProfile):
nms = NetworkManagerSettings()
connections = nms.get_connections_by_id(profile.connection.connection_id)
if len(connections) != 1:
raise ValueError("Unable to find the connection associated with the given profile")
return connections[0]
if profile is None:
return None
else:
nms = NetworkManagerSettings()
connections = nms.get_connections_by_id(profile.connection.connection_id)
if len(connections) != 1:
raise ValueError("Unable to find the connection associated with the given profile")
return connections[0]


def get_ipv4(profile: ConnectionProfile) -> Tuple:
if profile is None:
return "", "", ""

network_manager = NetworkManager()
interface_name = profile.connection.interface_name
device_path = network_manager.get_device_by_ip_iface(interface_name)
Expand Down

0 comments on commit 9794b17

Please sign in to comment.