namacha / python-magichue

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

Doesn't get the right RGB value #19

Closed philipsdirk closed 4 years ago

philipsdirk commented 4 years ago

Describe the bug When I try to get the current RGB value so I can reset it at the end of the program it get's it right te first time, but after that it keeps giving the same value even though I've manually changed the light with the app.

To Reproduce Code to reproduce the behavior:

import magichue
from bottle import route, run

pr = None
light = magichue.Light('192.168.1.36')
light.mode = magichue.NORMAL

def get_color():
    global pr
    pr = light.rgb

@route('/flashgreen')
def index():
    global pr
    get_color()
    time.sleep(1)
    light.rgb = (0, 0, 0)
    time.sleep(0.5)
    light.rgb = (0, 255, 0)
    time.sleep(0.4)
    light.rgb = (0, 0, 0)
    time.sleep(0.5)
    light.rgb = (0, 255, 0)
    time.sleep(0.4)
    light.rgb = pr

run(host='localhost', port=4783)

Device

Additional context I'm very new to Python so it could entirely be that I just made a mistake, if so please point it out. It could also be that the 'bottle' library is causing issues here because when I make a separate test program where I only print(light.rgb) it works fine.

namacha commented 4 years ago

You need to execute light.update_status() after you change the color of light with app.

philipsdirk commented 4 years ago

You need to execute light.update_status() after you change the color of light with app.

Yep that did it, thnx for the quick respons!