From 96b98fae9f6b5263d3e801f4c12fc0f8adad635e Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sat, 17 Oct 2015 15:11:30 +0530 Subject: [PATCH] networks: Handle unavailability of device --- plinth/modules/networks/networks.py | 4 +- .../networks/templates/connection_show.html | 72 ++++++++++--------- plinth/network.py | 3 + 3 files changed, 42 insertions(+), 37 deletions(-) diff --git a/plinth/modules/networks/networks.py b/plinth/modules/networks/networks.py index 219477593..c93060c0a 100644 --- a/plinth/modules/networks/networks.py +++ b/plinth/modules/networks/networks.py @@ -79,15 +79,13 @@ def show(request, uuid): active_connection = None # Device status + device = None if active_connection and active_connection.get_devices(): device = active_connection.get_devices()[0] else: interface_name = connection_status['interface_name'] if interface_name: device = network.get_device_by_interface_name(interface_name) - else: - # TODO: What to do in this situation? - raise RuntimeError('Could not get device status') device_status = network.get_status_from_device(device) diff --git a/plinth/modules/networks/templates/connection_show.html b/plinth/modules/networks/templates/connection_show.html index dd4f17773..0842a6ecf 100644 --- a/plinth/modules/networks/templates/connection_show.html +++ b/plinth/modules/networks/templates/connection_show.html @@ -74,36 +74,38 @@ -

Device

+ {% if device %} +

Device

-
-
- State - {{ device.state }} -
- {% if device.state_reason != 'none' %} +
- State reason - {{ device.state_reason }} + State + {{ device.state }} +
+ {% if device.state_reason != 'none' %} +
+ State reason + {{ device.state_reason }} +
+ {% endif %} +
+ Type + {{ device.type }} +
+
+ MAC address + {{ device.hw_address }} +
+
+ Interface + {{ device.interface_name }} +
+
+ Description + {{ device.description }}
- {% endif %} -
- Type - {{ device.type }}
-
- MAC address - {{ device.hw_address }} -
-
- Interface - {{ device.interface_name }} -
-
- Description - {{ device.description }} -
-
+ {% endif %}

Physical Link

@@ -130,14 +132,16 @@ SSID {{ connection.wireless.ssid }}
-
- Speed - {{ device.wireless.bitrate }} Mbit/s -
-
- Mode - {{ device.wireless.mode }} -
+ {% if device %} +
+ Speed + {{ device.wireless.bitrate }} Mbit/s +
+
+ Mode + {{ device.wireless.mode }} +
+ {% endif %} {% if access_point.channel %}
Signal strength diff --git a/plinth/network.py b/plinth/network.py index 614e80c73..e40b1ec05 100644 --- a/plinth/network.py +++ b/plinth/network.py @@ -161,6 +161,9 @@ def get_status_from_wifi_access_point(device, ssid): """Return the current status of an access point.""" status = {} + if not ssid or not device: + return status + for access_point in device.get_access_points(): if access_point.get_ssid().get_data() == ssid: status['strength'] = access_point.get_strength()