From fc869bf5db705960402dc24b88680a0d3db0efcd Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 23 Oct 2023 22:11:32 +0200 Subject: [PATCH] [Fix] sounddevice arguments fix. Different versions of the `sounddevice` dependency may or may not return the `index` parameter when querying the available sound devices. Thus, the code should be ready for both cases. --- platypush/plugins/sound/_manager/_device.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/platypush/plugins/sound/_manager/_device.py b/platypush/plugins/sound/_manager/_device.py index fbd213894..082634672 100644 --- a/platypush/plugins/sound/_manager/_device.py +++ b/platypush/plugins/sound/_manager/_device.py @@ -96,9 +96,13 @@ class DeviceManager: if type: raise AssertionError(f'No default device for type={type}') - idx = next( - iter(i for i, d in enumerate(all_devices) if d['name'] == dev['name']), None - ) + if dev.get('idx') is None: + idx = next( + iter(i for i, d in enumerate(all_devices) if d['name'] == dev['name']), + None, + ) - assert idx is not None, 'Could not infer the sound device index' - return AudioDevice(index=idx, **dev) + assert idx is not None, 'Could not infer the sound device index' + dev['index'] = idx + + return AudioDevice(**dev)