libsoundtouch icon indicating copy to clipboard operation
libsoundtouch copied to clipboard

device.presets() errors with unassigned buttons

Open TimoGo opened this issue 7 years ago • 1 comments

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.

TimoGo avatar Aug 06 '17 18:08 TimoGo

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.

CharlesBlonde avatar Aug 06 '17 21:08 CharlesBlonde