Skip to content

Commit

Permalink
[feature] Updated label for wireless interface clients
Browse files Browse the repository at this point in the history
"Access Point MAC address" for wireless interface in "station" mode,
"Associated client MAC address" otherwise.
Added UI element and updated schema for bitrate (MBit/s) and quality
  • Loading branch information
pandafy committed Oct 3, 2023
1 parent 2144bff commit dcfb7ea
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
5 changes: 5 additions & 0 deletions openwisp_monitoring/device/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ def _transform_data(self):
client['he'] = None
elif vht_enabled and client.get('he') is False:
client['he'] = None
# Convert bitrate from KBits/s to MBits/s
if wireless and 'bitrate' in wireless:
interface['wireless']['bitrate'] = round(
interface['wireless']['bitrate'] / 1000.0, 1
)
# add mac vendor to wireless clients if present
if (
not mac_detection
Expand Down
5 changes: 4 additions & 1 deletion openwisp_monitoring/device/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
],
"properties": {
"aid": {"type": "integer"},
"singal": {"type": "integer"},
"signal": {"type": "integer"},
"noise": {"type": "integer"},
"assoc": {"type": "boolean"},
"auth": {"type": "boolean"},
Expand All @@ -241,6 +241,9 @@
"wmm": {"type": "boolean"},
"wps": {"type": "boolean"},
"mac": {"type": "string"},
"bitrate": {"type": "integer"},
"quality": {"type": "integer"},
"quality_max": {"type": "integer"},
"vendor": {"type": "string"},
"mfp": {"type": "boolean"},
"preauth": {"type": "boolean"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,22 @@ <h2>{% trans 'Interface status' %}: {{ interface.name }}</h2>
</div>
</div>
{% endif %}
{% if interface.wireless.bitrate %}
<div class="form-row">
<label>{% trans 'Bitrate' %}:</label>
<div class="readonly">
{{ interface.wireless.bitrate }} MBits/s
</div>
</div>
{% endif %}
{% if interface.wireless.quality and interface.wireless.quality_max %}
<div class="form-row">
<label>{% trans 'Quality' %}:</label>
<div class="readonly">
{{ interface.wireless.quality }} / {{ interface.wireless.quality_max }}
</div>
</div>
{% endif %}
<div class="form-row">
<label>{% trans 'Noise' %}:</label>
<div class="readonly">
Expand Down Expand Up @@ -393,7 +409,11 @@ <h2>{% trans 'Interface status' %}: {{ interface.name }}</h2>
<thead>
<tr>
<th class="mac">
{% if interface.wireless.mode == 'station' %}
{% trans 'Access Point' %}
{% else %}
{% trans 'Associated client' %}
{% endif %}
{% trans 'MAC address' %}
</th>
{% if MAC_VENDOR_DETECTION %}
Expand Down
5 changes: 5 additions & 0 deletions openwisp_monitoring/device/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def _transform_wireless_interface_test_data(self, data):
client['he'] = None
elif vht_enabled and client.get('he') is False:
client['he'] = None
if wireless and 'bitrate' in wireless:
wireless['bitrate'] = round(wireless['bitrate'] / 1000.0, 1)
return data

def assertDataDict(self, dd_data, data):
Expand Down Expand Up @@ -276,6 +278,9 @@ def _data(self):
'tx_power': 6,
'channel': 6,
'ssid': 'testnet',
'bitrate': 1100,
'quality': 65,
'quality_max': 70,
'noise': -95,
'country': 'US',
'htmode': 'VHT80',
Expand Down
34 changes: 34 additions & 0 deletions openwisp_monitoring/device/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ def test_status_data(self):
],
}
)
data['interfaces'].append(deepcopy(data['interfaces'][0]))
data['interfaces'][2].update(
{
'name': 'wlan2',
'mac': '44:d1:fa:4b:38:45',
}
)
data['interfaces'][2]['wireless']['mode'] = 'station'
self._post_data(d.id, d.key, data)
url = reverse('admin:config_device_change', args=[d.pk])
r = self.client.get(url)
Expand All @@ -170,6 +178,32 @@ def test_status_data(self):
self.assertContains(r, '44:D1:FA:4B:00:02')
with self.subTest('Neighbor IP is shown'):
self.assertContains(r, 'fe80::9683:c4ff:fe02:c2bf')
with self.subTest('Wireless client table header is shown'):
self.assertContains(
r,
'<th class="mac">\n\nAssociated client\n\nMAC address\n\n' '</th>',
html=True,
count=2,
)
self.assertContains(
r,
'<th class="mac">\n\nAccess Point\n\nMAC address\n\n' '</th>',
html=True,
count=1,
)
with self.subTest('Wireless interface properties are shown'):
self.assertContains(
r,
'<div class="form-row">\n<label>Quality:</label>\n'
'<div class="readonly">\n65 / 70\n</div>\n</div>',
html=True,
)
self.assertContains(
r,
'<div class="form-row">\n<label>Bitrate:</label>\n'
'<div class="readonly">\n1.1 MBits/s\n</div>\n</div>',
html=True,
)

def test_status_data_contains_wifi_version(self):
data = self._data()
Expand Down

0 comments on commit dcfb7ea

Please sign in to comment.