Skip to content

Commit 91d2f24

Browse files
committed
Moving device type detection out of file operations.
The device type detection now uses USB VID/PID, which is known at the find_candidates() stage.
1 parent c557d79 commit 91d2f24

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

mbed_lstools/lstools_base.py

Lines changed: 6 additions & 4 deletions
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):

0 commit comments

Comments
 (0)