Skip to content

Commit f098335

Browse files
Merge pull request #378 from bridadan/device_type_now_with_no_files
Device type detection now with no files
2 parents c4db6bc + efbbcca commit f098335

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

mbed_lstools/lstools_base.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def list_mbeds(
137137
logger.debug("Candidates for display %r", candidates)
138138
result = []
139139
for device in candidates:
140+
device['device_type'] = self._detect_device_type(device)
140141
if ((not device['mount_point'] or
141142
not self.mount_point_ready(device['mount_point'])) and
142143
not self.list_unmounted):
@@ -146,7 +147,8 @@ def list_mbeds(
146147
"Use the '-u' flag to include it in the list.",
147148
device['target_id_usb_id'])
148149
else:
149-
platform_data = self.plat_db.get(device['target_id_usb_id'][0:4], verbose_data=True)
150+
platform_data = self.plat_db.get(device['target_id_usb_id'][0:4],
151+
device_type=device['device_type'] or 'daplink', verbose_data=True)
150152
device.update(platform_data or {"platform_name": None})
151153
maybe_device = {
152154
FSInteraction.BeforeFilter: self._fs_before_id_check,
@@ -167,6 +169,9 @@ def list_mbeds(
167169
self.retarget_data[device['target_id']])
168170
except KeyError:
169171
pass
172+
173+
# This is done for API compatibility, would prefer for this to just be None
174+
device['device_type'] = device['device_type'] if device['device_type'] else 'unknown'
170175
result.append(maybe_device)
171176

172177
return result
@@ -211,13 +216,11 @@ def _update_device_from_fs(self, device, read_details_txt):
211216
output dict attributes read from other files present on the 'mount_point'
212217
"""
213218
if not device.get('mount_point', None):
214-
device['device_type'] = 'unknown'
215219
return
216220

217221
try:
218222
directory_entries = os.listdir(device['mount_point'])
219223
device['directory_entries'] = directory_entries
220-
device['device_type'] = self._detect_device_type(device)
221224
device['target_id'] = device['target_id_usb_id']
222225

223226
{
@@ -230,7 +233,6 @@ def _update_device_from_fs(self, device, read_details_txt):
230233
'Marking device with mount point "%s" as unmounted due to the '
231234
'following error: %s', device['mount_point'], e)
232235
device['mount_point'] = None
233-
device['device_type'] = 'unknown'
234236

235237

236238
def _detect_device_type(self, device):

test/mbedls_toolsbase.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,8 @@ def test_update_device_from_fs_mid_unmount(self):
280280
with patch('os.listdir') as _listdir:
281281
_listdir.side_effect = OSError
282282
self.base._update_device_from_fs(device, False)
283-
self.assertEqual(device['device_type'], 'unknown')
284283
self.assertEqual(device['mount_point'], None)
285284

286-
def test_update_device_from_fs_unknown(self):
287-
device = {}
288-
self.base._update_device_from_fs(device, False)
289-
self.assertEqual(device['device_type'], 'unknown')
290-
291285
def test_detect_device_test(self):
292286
device_type = self.base._detect_device_type({
293287
'vendor_id': '0483'
@@ -304,6 +298,25 @@ def test_detect_device_test(self):
304298
})
305299
self.assertEqual(device_type, 'jlink')
306300

301+
def test_device_type_unmounted(self):
302+
self.base.list_unmounted = True
303+
self.base.return_value = [{'mount_point': None,
304+
'target_id_usb_id': u'0240DEADBEEF',
305+
'serial_port': "dummy_serial_port",
306+
'vendor_id': '0d28',
307+
'product_id': '0204'}]
308+
with patch("mbed_lstools.lstools_base.PlatformDatabase.get") as _get,\
309+
patch('os.listdir') as _listdir:
310+
_get.return_value = {
311+
'platform_name': 'foo_target'
312+
}
313+
to_check = self.base.list_mbeds()
314+
#_get.assert_any_call('0240', device_type='daplink', verbose_data=True)
315+
self.assertEqual(len(to_check), 1)
316+
self.assertEqual(to_check[0]['target_id'], "0240DEADBEEF")
317+
self.assertEqual(to_check[0]['platform_name'], 'foo_target')
318+
self.assertEqual(to_check[0]['device_type'], 'daplink')
319+
307320
def test_update_device_details_jlink(self):
308321
jlink_html_contents = ('<html><head><meta http-equiv="refresh" '
309322
'content="0; url=http://www.nxp.com/FRDM-KL27Z"/>'

0 commit comments

Comments
 (0)