namacha / python-magichue

Control Magic Hue(Magichome) in Python.
MIT License
60 stars 12 forks source link

Bug: Can not run constructor of Light() when device is is programming mode #33

Closed PrzemekMi closed 3 years ago

PrzemekMi commented 3 years ago

Can not run constructor of Light() when device is is programming mode. The issue is more relevant, because it was normal for me to run device in this mode, reason beeing it is new for this app. By programming mode I mean mode when you connect and reconnect power supply 3 times, and device flashes every color separatly.

To Reproduce

import magichue
bulbs = magichue.discover_bulbs() # returns list of bulb address
print(bulbs[0])
light = magichue.Light(bulbs[0])

Device

Additional context The reason for this problem is that 'programming mode' (you enter it by reconnecting power supply 3 times) has its own of mode_value = 0x63, wich is not in dictionary, so on call

self.mode = modes._VALUE_TO_MODE[mode_value] 

python rises KeyError: 99. The fix for me was to add this mode to const and dictionary to modes.py, i.e. :

_PROGRAMMING_MODE = 0x63
PROGRAMMING_MODE = Mode(_PROGRAMMING_MODE, 1, 'PROGRAMMING_MODE')
_PROGRAMMING_MODE: PROGRAMMING_MODE,

There are 3 palceses where you need to it, this is only suggestion for fix

namacha commented 3 years ago

Just merged fix for that bug. Thanks for reporting issue!