This PR refactors the backend logic of how we determine the connection status of the network interfaces. It extends the response structure so that we will be able to show IP address and MAC address in a separate network dialog. The current WiFi dialog also uses this endpoint, so there needs to be a small adjustment to accommodate the new structure there.
Notes:
I renamed the network.status() method to network.determine_network_status(), to reflect that it’s now actively running a command. In order to avoid code duplication, network.determine_network_status() is actually just a convenience wrapper around network.inspect_interface(), which also encapsulates the technical interface names eth0 and wlan0. I also renamed and restructured the NetworkStatus class to InterfaceStatus.
I found the JSON output structure of the ip command a bit hard to predict, as I saw numerous invariants of which fields were present during testing, which I wasn’t able to reproduce. I also couldn’t find reliable documentation for it. I therefore made the code inside the network.inspect_interface() method very defensive and failure-tolerant, to avoid producing erratic errors. I thought in the end it would be more user-friendly to show a network interface as down, even if that’s a false positive/negative, as opposed to potentially showing a lot of errors and risking to give the feature an overall brittle impression.
Related https://github.com/tiny-pilot/tinypilot/issues/1814.
This PR refactors the backend logic of how we determine the connection status of the network interfaces. It extends the response structure so that we will be able to show IP address and MAC address in a separate network dialog. The current WiFi dialog also uses this endpoint, so there needs to be a small adjustment to accommodate the new structure there.
Notes:
network.status()
method tonetwork.determine_network_status()
, to reflect that it’s now actively running a command. In order to avoid code duplication,network.determine_network_status()
is actually just a convenience wrapper aroundnetwork.inspect_interface()
, which also encapsulates the technical interface nameseth0
andwlan0
. I also renamed and restructured theNetworkStatus
class toInterfaceStatus
.ip
command a bit hard to predict, as I saw numerous invariants of which fields were present during testing, which I wasn’t able to reproduce. I also couldn’t find reliable documentation for it. I therefore made the code inside thenetwork.inspect_interface()
method very defensive and failure-tolerant, to avoid producing erratic errors. I thought in the end it would be more user-friendly to show a network interface as down, even if that’s a false positive/negative, as opposed to potentially showing a lot of errors and risking to give the feature an overall brittle impression.