diff --git a/mbed_lstools/lstools_base.py b/mbed_lstools/lstools_base.py index aaa9d0e..2047d54 100644 --- a/mbed_lstools/lstools_base.py +++ b/mbed_lstools/lstools_base.py @@ -137,6 +137,7 @@ def list_mbeds( logger.debug("Candidates for display %r", candidates) result = [] for device in candidates: + device['device_type'] = self._detect_device_type(device) if ((not device['mount_point'] or not self.mount_point_ready(device['mount_point'])) and not self.list_unmounted): @@ -146,7 +147,8 @@ def list_mbeds( "Use the '-u' flag to include it in the list.", device['target_id_usb_id']) else: - platform_data = self.plat_db.get(device['target_id_usb_id'][0:4], verbose_data=True) + platform_data = self.plat_db.get(device['target_id_usb_id'][0:4], + device_type=device['device_type'] or 'daplink', verbose_data=True) device.update(platform_data or {"platform_name": None}) maybe_device = { FSInteraction.BeforeFilter: self._fs_before_id_check, @@ -167,6 +169,9 @@ def list_mbeds( self.retarget_data[device['target_id']]) except KeyError: pass + + # This is done for API compatibility, would prefer for this to just be None + device['device_type'] = device['device_type'] if device['device_type'] else 'unknown' result.append(maybe_device) return result @@ -211,13 +216,11 @@ def _update_device_from_fs(self, device, read_details_txt): output dict attributes read from other files present on the 'mount_point' """ if not device.get('mount_point', None): - device['device_type'] = 'unknown' return try: directory_entries = os.listdir(device['mount_point']) device['directory_entries'] = directory_entries - device['device_type'] = self._detect_device_type(device) device['target_id'] = device['target_id_usb_id'] { @@ -230,7 +233,6 @@ def _update_device_from_fs(self, device, read_details_txt): 'Marking device with mount point "%s" as unmounted due to the ' 'following error: %s', device['mount_point'], e) device['mount_point'] = None - device['device_type'] = 'unknown' def _detect_device_type(self, device): diff --git a/test/mbedls_toolsbase.py b/test/mbedls_toolsbase.py index 2d77a77..e4eeb76 100644 --- a/test/mbedls_toolsbase.py +++ b/test/mbedls_toolsbase.py @@ -280,14 +280,8 @@ def test_update_device_from_fs_mid_unmount(self): with patch('os.listdir') as _listdir: _listdir.side_effect = OSError self.base._update_device_from_fs(device, False) - self.assertEqual(device['device_type'], 'unknown') self.assertEqual(device['mount_point'], None) - def test_update_device_from_fs_unknown(self): - device = {} - self.base._update_device_from_fs(device, False) - self.assertEqual(device['device_type'], 'unknown') - def test_detect_device_test(self): device_type = self.base._detect_device_type({ 'vendor_id': '0483' @@ -304,6 +298,25 @@ def test_detect_device_test(self): }) self.assertEqual(device_type, 'jlink') + def test_device_type_unmounted(self): + self.base.list_unmounted = True + self.base.return_value = [{'mount_point': None, + 'target_id_usb_id': u'0240DEADBEEF', + 'serial_port': "dummy_serial_port", + 'vendor_id': '0d28', + 'product_id': '0204'}] + with patch("mbed_lstools.lstools_base.PlatformDatabase.get") as _get,\ + patch('os.listdir') as _listdir: + _get.return_value = { + 'platform_name': 'foo_target' + } + to_check = self.base.list_mbeds() + #_get.assert_any_call('0240', device_type='daplink', verbose_data=True) + self.assertEqual(len(to_check), 1) + self.assertEqual(to_check[0]['target_id'], "0240DEADBEEF") + self.assertEqual(to_check[0]['platform_name'], 'foo_target') + self.assertEqual(to_check[0]['device_type'], 'daplink') + def test_update_device_details_jlink(self): jlink_html_contents = ('
'