libsoundtouch
libsoundtouch copied to clipboard
device.presets() errors with unassigned buttons
Hi,
when I try to read the presets of a not yet assigned button with:
presets = device.presets()
print(presets[4].name)
I get this error:
root@e422731c2b9f:~# ./get_buttons.py
Traceback (most recent call last):
File "./get_buttons.py", line 18, in <module>
print(presets[4].name)
IndexError: list index out of range
root@e422731c2b9f:~#
Iam a python beginner, so please ignore this if there is a simple solution for that in python.
It's the normal behavior because you don't have 5 presets configured on your device (indices start at 0).
you can iterate over preset and get the preset_id
(1-6):
for preset in presets:
print(preset.preset_id)
print(preset.name)
But I have to implement string representation methods (str) in order to help users to understand what are in the objects.