Skip to content

Commit

Permalink
[fix] Fixed unrecognized access technology exception
Browse files Browse the repository at this point in the history
Co-authored-by: Federico Capoano <[email protected]>
  • Loading branch information
pandafy and nemesifier authored Jan 18, 2024
1 parent dd00861 commit 1212b4c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
36 changes: 36 additions & 0 deletions openwisp_monitoring/device/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,42 @@ def test_mobile_properties(self):
{'lte': {'rsrp': -75.00, 'rsrq': -8.00, 'rssi': -51.00, 'snr': 13.00}},
)

def test_empty_mobile_signal_data(self):
org = self._create_org()
device = self._create_device(organization=org)
data = {
'type': 'DeviceMonitoring',
'interfaces': [
{
'name': 'mobile0',
'mac': '00:00:00:00:00:00',
'mtu': 1900,
'multicast': True,
'txqueuelen': 1000,
'type': 'modem-manager',
'up': True,
'mobile': {
'connection_status': 'connected',
'imei': '300000001234567',
'manufacturer': 'Sierra Wireless, Incorporated',
'model': 'MC7430',
'operator_code': '50502',
'operator_name': 'YES OPTUS',
'power_status': 'on',
'signal': {'threshold': {'rssi': '0.0'}},
},
}
],
}
response = self._post_data(device.id, device.key, data)
self.assertEqual(response.status_code, 200)
mobile_data = DeviceData(pk=device.pk).data['interfaces'][0]['mobile']
with self.subTest('check mobile interface static properties'):
self.assertEqual(mobile_data['imei'], '300000001234567')
self.assertEqual(mobile_data['model'], 'MC7430')
self.assertIn('signal', mobile_data)
self.assertIn('threshold', mobile_data['signal'])

def test_garbage_mobile_properties(self):
o = self._create_org()
d = self._create_device(organization=o)
Expand Down
14 changes: 7 additions & 7 deletions openwisp_monitoring/device/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ def _get_extra_tags(self, device):
def _get_mobile_signal_type(self, signal):
if not signal:
return
# if only one access technology in use, return that
access_techs = list(ACCESS_TECHNOLOGIES.keys())
access_techs.reverse()
# if only one access technology is in use, return that
sections = list(signal.keys())
if len(sections) == 1:
return sections[0]
# if multiple access technologies are in use,
# return the most advanced one
access_technologies = list(ACCESS_TECHNOLOGIES.keys())
access_technologies.reverse()
for tech in access_technologies:
return sections[0] if sections[0] in access_techs else None
# if multiple mobile access technologies are in use,
# return the most evolved technology in use
for tech in access_techs:
if tech in signal:
return tech

Expand Down

0 comments on commit 1212b4c

Please sign in to comment.