class ColorBulb(WhiteBulb): def __init__(self, ip): super() self.bulb = Bulb(ip) def color_red(self): self.bulb.set_rgb(255, 0, 0) print("Setting the light to red...") def color_green(self): self.bulb.set_rgb(0, 255, 0) print("Setting the light to green...") def color_blue(self): self.bulb.set_rgb(0, 0, 255) print("Setting the light to blue...") def color_white(self): self.bulb.set_color_temp(4000) print("Setting the light to white...") def color_hex(self, hex): hex = hex.lstrip('#') red, green, blue = tuple(int(hex[i:i + 2], 16) for i in (0, 2, 4)) self.bulb.set_rgb(red, green, blue) print("Setting the light to RGB(", str(red), str(green), str(blue), ")...")
class WhiteBulb: def __init__(self, ip): self.bulb = Bulb(ip) def power_on(self): self.bulb.turn_on() print("Turning the light on...") def power_off(self): self.bulb.turn_off() print("Turning the light off...") def power_toggle(self): self.bulb.toggle() print("Toggling the light...") def set_brightness(self, bright): self.bulb.set_brightness(bright) print("Setting the brightness to ", bright, "%...") def set_temperature(self, temp): self.bulb.set_color_temp(temp) print("Setting the temperature to ", temp, "K...") def get_status(self): status = self.bulb.get_properties() power = status['power'] bright = status['bright'] temp = status['ct'] rgb = status['rgb'] r, g, b = [rgb[i:i + 3] for i in range(0, len(rgb), 3)] rgb = "(" + r + ", " + g + ", " + b + ")" print("Power: {}\nBrighness: {}%\nTemperature: {}K\nRGB: {}".format( power, bright, temp, rgb))
class YeetBulb: def __init__(self, name, ip): self.name = name self.ip = ip self.bulb = Bulb(self.ip, effect="smooth", duration=750, auto_on=True) self.properties = self.bulb.get_properties() def __getitem__(self, key): return getattr(self, key) def turnoff(self): self.bulb.turn_off() def turnon(self): self.bulb.turn_on() def toggle(self): self.bulb.toggle() def loadPreset(self, preset): if os.path.isfile(preset): with open(preset, 'r') as f: config = json.load(f) if 'preset' in config: preset = config['preset'] if ('rgb' in preset): try: self.bulb.set_rgb(preset['rgb'][0], preset['rgb'][1], preset['rgb'][2]) except: print('not supported by bulb') if ('hsv' in preset): try: self.bulb.set_hsv(preset['hsv'][0], preset['hsv'][1], preset['hsv'][2]) except: print('not supported by bulb') if ('color_temp' in preset): try: self.bulb.set_color_temp(preset['color_temp']) except: print('not supported by bulb') if ('brightness' in preset): try: self.bulb.set_brightness(preset['brightness']) except: print('not supported by bulb') if ('color_temp' in preset): try: self.bulb.set_color_temp(preset['color_temp']) except: print('not supported by bulb') else: print('File not found: ' + preset) def updateProperties(self): self.properties = self.bulb.get_properties()
class YeelightBulb(object): def __init__(self, name, ip, support, model, power): self.name = name self.ip = ip self.support = support self.model = model self.power = power self.bulb = Bulb(self.ip, auto_on=True) def set_power(self, mode): answer = ('%s is now %s' % (self.name, mode)) if mode == "on" and self.power != "on": self.bulb.turn_on() self.power = mode elif mode == "off" and self.power != "off": self.bulb.turn_off() self.power = mode elif mode == "toggle": self.bulb.toggle() if self.power == "on": self.power = "off" else: self.power = "on" else: answer = ('%s is already %s' % (self.name, self.power)) return answer def set_brightness(self, value): self.bulb.set_brightness(value) answer = ('%s brightness value set' % self.name) return answer def set_rgb(self, color, color_name): if "set_rgb" in self.support: self.bulb.set_rgb(color[0],color[1],color[2]) answer = ('%s color set to %s' % (self.name, color_name)) else: answer = ('%s doesn\'t support RGB color mode' % self.name) return answer def set_color_temp(self, temp): if "set_ct_abx" in self.support: if 1700 <= temp <= 6500: self.bulb.set_color_temp(temp) answer = ('%s color temperature set' % self.name) else: answer = 'Color temperature must be between 1700 and 6500 degrees' else: answer = ('%s doesn\'t support color temperature adjustment' % self.name) return answer
def start_dawn(duration: timedelta, bulb: Bulb): steps = duration // STEP logger.info('Starting dawn in %s steps...', steps) bulb.turn_on() for step in range(steps): temperature = get_value(MIN_TEMPERATURE, MAX_TEMPERATURE, steps, step) brightness = get_value(MIN_BRIGHTNESS, MAX_BRIGHTNESS, steps, step) logger.debug( 'Setting up temperature to %s and brightness to %s on %s step', temperature, brightness, step) bulb.set_color_temp(temperature) bulb.set_brightness(brightness) sleep(STEP.seconds) logger.info('Rise and shine!')
class BulbContainer: def __init__(self, ip): self.bulb = Bulb(ip, duration=1000) def blink(self, duration, retry=10): try: self.bulb.turn_on(duration=1000) self.bulb.set_color_temp(6500) self.bulb.set_brightness(100) sleep(duration) self.bulb.turn_off(duration=10000) except Exception as ex: log(f"Blink error: {ex}") if retry > 0: log(f'Retrying... ({retry} more time)') self.blink(duration, retry=retry - 1)
def user_homepage(request): bulb = Bulb("10.3.3.144") if request.GET.get('connect'): print(request.GET.get('connect')) print("Discovering") print(discover_bulbs()) elif request.GET.get('turnon'): print(request.GET.get('turnon')) print("Turning On") bulb.turn_on() elif request.GET.get('turnoff'): print(request.GET.get('turnoff')) print("Turning Off") bulb.turn_off() elif request.GET.get('dimming'): print(request.GET.get('dimming')) print("Dimming") bulb.set_brightness(100) elif request.GET.get('color'): print(request.GET.get('color')) print("Setting Color") bulb.set_color_temp(2000) elif request.GET.get('lecrepecafe'): print(request.GET.get('lecrepecafe')) print("Clicked Le Crepe Cafe") bulb.turn_on() bulb.set_color_temp(6500) elif request.GET.get('starbucks'): print(request.GET.get('starbucks')) print("Clicked Starbucks") bulb.turn_on() bulb.set_color_temp(1500) elif request.GET.get('jamba'): print(request.GET.get('jamba')) print("Clicked Jamba") bulb.turn_on() bulb.set_color_temp(1500) elif request.GET.get('panda'): print(request.GET.get('panda')) print("Clicked Panda") bulb.turn_on() bulb.set_color_temp(6500) return render(request, 'users/userhome.html')
def index(request): bulb = Bulb("10.3.3.144") if request.GET.get('connect'): print(request.GET.get('connect')) print("Discovering") print(discover_bulbs()) elif request.GET.get('turnon'): print(request.GET.get('turnon')) print("Turning On") bulb.turn_on() elif request.GET.get('turnoff'): print(request.GET.get('turnoff')) print("Turning Off") bulb.turn_off() elif request.GET.get('dimming'): print(request.GET.get('dimming')) print("Dimming") bulb.set_brightness(1) elif request.GET.get('color'): print(request.GET.get('color')) print("Setting Color") bulb.set_color_temp(2000) return render(request, 'index.html')
def room_handler(): post_dict = request.query.decode() if 'ct' in post_dict and 'bri' in post_dict: ct = int(post_dict['ct']) bri = int(float(post_dict['bri']) * 100) for (currentbulb, maxtemp, mintemp) in zip(bulbs, maxtemps, mintemps): if currentbulb != '': print('Sending command to Yeelight at', currentbulb) bulb = Bulb(currentbulb) if static_brightness is False: bulb.set_brightness(bri) print('Brightness set to', bri, 'percent') if int(mintemp) < ct < int(maxtemp): bulb.set_color_temp(ct) print('Color temperature set to', ct, 'Kelvin') else: if ct > int(maxtemp): bulb.set_color_temp(int(maxtemp)) print('Reached highest color temperature of', maxtemp, 'Kelvin') if ct < int(mintemp): bulb.set_color_temp(int(mintemp)) print('Reached lowest color temperature of', mintemp, 'Kelvin')
ar = np.asarray(im) shape = ar.shape ar = ar.reshape(np.product(shape[:2]), shape[2]).astype(float) # print('finding clusters') codes, dist = scipy.cluster.vq.kmeans(ar, NUM_CLUSTERS) # print('cluster centres:\n', codes) vecs, dist = scipy.cluster.vq.vq(ar, codes) # assign codes counts, bins = np.histogram(vecs, len(codes)) # count occurrences index_max = np.argmax(counts) # find most frequent peak = codes[index_max] # print('most frequent is %s (#%s)' % (peak, colour)) print(peak) luma = 0.2126*int(peak[0]) + 0.7152*int(peak[1]) + 0.0722*int(peak[2]) if luma < 30: print('troppo scuro') bulb1.set_rgb(158, 0, 255) bulb2.set_rgb(158, 0, 255) elif luma > 130: print(bulb1.set_color_temp(6000)) print(bulb2.set_color_temp(6000)) else: print(bulb1.set_rgb(int(peak[0]), int(peak[1]), int(peak[2]))) print(bulb2.set_rgb(int(peak[0]), int(peak[1]), int(peak[2]))) time.sleep(1)
class Tests(unittest.TestCase): def setUp(self): self.socket = SocketMock() self.bulb = Bulb(ip="", auto_on=True) self.bulb._Bulb__socket = self.socket def test_rgb1(self): self.bulb.set_rgb(255, 255, 0) self.assertEqual(self.socket.sent["method"], "set_rgb") self.assertEqual(self.socket.sent["params"], [16776960, 'smooth', 300]) def test_rgb2(self): self.bulb.effect = "sudden" self.bulb.set_rgb(255, 255, 0) self.assertEqual(self.socket.sent["method"], "set_rgb") self.assertEqual(self.socket.sent["params"], [16776960, 'sudden', 300]) def test_rgb3(self): self.bulb.set_rgb(255, 255, 0, effect="sudden") self.assertEqual(self.socket.sent["method"], "set_rgb") self.assertEqual(self.socket.sent["params"], [16776960, 'sudden', 300]) def test_hsv1(self): self.bulb.set_hsv(200, 100, effect="sudden") self.assertEqual(self.socket.sent["method"], "set_hsv") self.assertEqual(self.socket.sent["params"], [200, 100, 'sudden', 300]) def test_hsv2(self): self.bulb.set_hsv(200, 100, 10, effect="sudden", duration=500) self.assertEqual(self.socket.sent["method"], "start_cf") self.assertEqual(self.socket.sent["params"], [1, 1, "50, 1, 43263, 10"]) def test_hsv3(self): self.bulb.set_hsv(200, 100, 10, effect="smooth", duration=1000) self.assertEqual(self.socket.sent["method"], "start_cf") self.assertEqual(self.socket.sent["params"], [1, 1, "1000, 1, 43263, 10"]) def test_hsv4(self): self.bulb.effect = "sudden" self.bulb.set_hsv(200, 100, 10, effect="smooth", duration=1000) self.assertEqual(self.socket.sent["method"], "start_cf") self.assertEqual(self.socket.sent["params"], [1, 1, "1000, 1, 43263, 10"]) def test_toggle1(self): self.bulb.toggle() self.assertEqual(self.socket.sent["method"], "toggle") self.assertEqual(self.socket.sent["params"], ["smooth", 300]) def test_turn_off1(self): self.bulb.turn_off() self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["off", "smooth", 300]) def test_turn_on1(self): self.bulb.turn_on() self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["on", "smooth", 300]) def test_turn_on2(self): self.bulb.effect = "sudden" self.bulb.turn_on() self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["on", "sudden", 300]) def test_turn_on3(self): self.bulb.turn_on(effect="sudden", duration=50) self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["on", "sudden", 50]) def test_color_temp1(self): self.bulb.set_color_temp(1400) self.assertEqual(self.socket.sent["method"], "set_ct_abx") self.assertEqual(self.socket.sent["params"], [1700, "smooth", 300]) def test_color_temp2(self): self.bulb.set_color_temp(8400, effect="sudden") self.assertEqual(self.socket.sent["method"], "set_ct_abx") self.assertEqual(self.socket.sent["params"], [6500, "sudden", 300])
class Tests(unittest.TestCase): def setUp(self): self.socket = SocketMock() self.bulb = Bulb(ip="", auto_on=True) self.bulb._Bulb__socket = self.socket def test_rgb1(self): self.bulb.set_rgb(255, 255, 0) self.assertEqual(self.socket.sent["method"], "set_rgb") self.assertEqual(self.socket.sent["params"], [16776960, "smooth", 300]) def test_rgb2(self): self.bulb.effect = "sudden" self.bulb.set_rgb(255, 255, 0) self.assertEqual(self.socket.sent["method"], "set_rgb") self.assertEqual(self.socket.sent["params"], [16776960, "sudden", 300]) def test_rgb3(self): self.bulb.set_rgb(255, 255, 0, effect="sudden") self.assertEqual(self.socket.sent["method"], "set_rgb") self.assertEqual(self.socket.sent["params"], [16776960, "sudden", 300]) def test_hsv1(self): self.bulb.set_hsv(200, 100, effect="sudden") self.assertEqual(self.socket.sent["method"], "set_hsv") self.assertEqual(self.socket.sent["params"], [200, 100, "sudden", 300]) def test_hsv2(self): self.bulb.set_hsv(200, 100, 10, effect="sudden", duration=500) self.assertEqual(self.socket.sent["method"], "start_cf") self.assertEqual(self.socket.sent["params"], [1, 1, "50, 1, 43263, 10"]) def test_hsv3(self): self.bulb.set_hsv(200, 100, 10, effect="smooth", duration=1000) self.assertEqual(self.socket.sent["method"], "start_cf") self.assertEqual(self.socket.sent["params"], [1, 1, "1000, 1, 43263, 10"]) def test_hsv4(self): self.bulb.effect = "sudden" self.bulb.set_hsv(200, 100, 10, effect="smooth", duration=1000) self.assertEqual(self.socket.sent["method"], "start_cf") self.assertEqual(self.socket.sent["params"], [1, 1, "1000, 1, 43263, 10"]) def test_toggle1(self): self.bulb.toggle() self.assertEqual(self.socket.sent["method"], "toggle") self.assertEqual(self.socket.sent["params"], ["smooth", 300]) self.bulb.toggle(duration=3000) self.assertEqual(self.socket.sent["params"], ["smooth", 3000]) def test_turn_off1(self): self.bulb.turn_off() self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["off", "smooth", 300]) self.bulb.turn_off(duration=3000) self.assertEqual(self.socket.sent["params"], ["off", "smooth", 3000]) def test_turn_on1(self): self.bulb.turn_on() self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["on", "smooth", 300]) self.bulb.turn_on(duration=3000) self.assertEqual(self.socket.sent["params"], ["on", "smooth", 3000]) def test_turn_on2(self): self.bulb.effect = "sudden" self.bulb.turn_on() self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["on", "sudden", 300]) def test_turn_on3(self): self.bulb.turn_on(effect="sudden", duration=50) self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["on", "sudden", 50]) def test_turn_on4(self): self.bulb.power_mode = enums.PowerMode.MOONLIGHT self.bulb.turn_on() self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual( self.socket.sent["params"], ["on", "smooth", 300, enums.PowerMode.MOONLIGHT.value]) def test_turn_on5(self): self.bulb.turn_on(power_mode=enums.PowerMode.MOONLIGHT) self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual( self.socket.sent["params"], ["on", "smooth", 300, enums.PowerMode.MOONLIGHT.value]) def test_set_power_mode1(self): self.bulb.set_power_mode(enums.PowerMode.MOONLIGHT) self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual( self.socket.sent["params"], ["on", "smooth", 300, enums.PowerMode.MOONLIGHT.value]) def test_set_power_mode2(self): self.bulb.set_power_mode(enums.PowerMode.NORMAL) self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["on", "smooth", 300, enums.PowerMode.NORMAL.value]) def test_set_power_mode3(self): self.bulb.set_power_mode(enums.PowerMode.LAST) self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["on", "smooth", 300]) def test_color_temp1(self): self.bulb.set_color_temp(1400) self.assertEqual(self.socket.sent["method"], "set_ct_abx") self.assertEqual(self.socket.sent["params"], [1700, "smooth", 300]) self.bulb.set_color_temp(1400, duration=3000) self.assertEqual(self.socket.sent["params"], [1700, "smooth", 3000]) def test_color_temp2(self): self.bulb.set_color_temp(8400, effect="sudden") self.assertEqual(self.socket.sent["method"], "set_ct_abx") self.assertEqual(self.socket.sent["params"], [6500, "sudden", 300]) def test_color_temp_with_model_declared(self): self.bulb._model = "ceiling2" self.bulb.set_color_temp(1800) self.assertEqual(self.socket.sent["method"], "set_ct_abx") self.assertEqual(self.socket.sent["params"], [2700, "smooth", 300]) def test_start_flow(self): transitions = [ TemperatureTransition(1700, duration=40000), TemperatureTransition(6500, duration=40000) ] flow = Flow(count=1, action=Action.stay, transitions=transitions) self.bulb.start_flow(flow) self.assertEqual(self.socket.sent["method"], "start_cf") self.assertEqual(self.socket.sent["params"], [2, 1, "40000, 2, 1700, 100, 40000, 2, 6500, 100"]) def test_set_scene_color(self): self.bulb.set_scene(SceneClass.COLOR, 255, 255, 0, 10) self.assertEqual(self.socket.sent["method"], "set_scene") self.assertEqual(self.socket.sent["params"], ["color", 16776960, 10]) def test_set_scene_color_ambilight(self): self.bulb.set_scene(SceneClass.COLOR, 255, 255, 0, 10, light_type=LightType.Ambient) self.assertEqual(self.socket.sent["method"], "bg_set_scene") self.assertEqual(self.socket.sent["params"], ["color", 16776960, 10]) def test_set_scene_color_temperature(self): self.bulb.set_scene(SceneClass.CT, 2000, 15) self.assertEqual(self.socket.sent["method"], "set_scene") self.assertEqual(self.socket.sent["params"], ["ct", 2000, 15]) def test_set_scene_hsv(self): self.bulb.set_scene(SceneClass.HSV, 200, 100, 10) self.assertEqual(self.socket.sent["method"], "set_scene") self.assertEqual(self.socket.sent["params"], ["hsv", 200, 100, 10]) def test_set_scene_color_flow(self): transitions = [ TemperatureTransition(1700, duration=40000), TemperatureTransition(6500, duration=40000) ] flow = Flow(count=1, action=Action.stay, transitions=transitions) self.bulb.set_scene(SceneClass.CF, flow) self.assertEqual(self.socket.sent["method"], "set_scene") self.assertEqual( self.socket.sent["params"], ["cf", 2, 1, "40000, 2, 1700, 100, 40000, 2, 6500, 100"]) def test_set_scene_auto_delay_off(self): self.bulb.set_scene(SceneClass.AUTO_DELAY_OFF, 20, 1) self.assertEqual(self.socket.sent["method"], "set_scene") self.assertEqual(self.socket.sent["params"], ["auto_delay_off", 20, 1]) def test_sunrise(self): flow = flows.sunrise() self.bulb.set_scene(SceneClass.CF, flow) self.assertEqual(self.socket.sent["method"], "set_scene") self.assertEqual(self.socket.sent["params"], [ "cf", 3, 1, "50, 1, 16731392, 1, 360000, 2, 1700, 10, 540000, 2, 2700, 100" ]) def test_sunset(self): flow = flows.sunset() self.bulb.set_scene(SceneClass.CF, flow) self.assertEqual(self.socket.sent["method"], "set_scene") self.assertEqual(self.socket.sent["params"], [ "cf", 3, 2, "50, 2, 2700, 10, 180000, 2, 1700, 5, 420000, 1, 16731136, 1" ]) def test_romance(self): flow = flows.romance() self.bulb.set_scene(SceneClass.CF, flow) self.assertEqual(self.socket.sent["method"], "set_scene") self.assertEqual( self.socket.sent["params"], ["cf", 0, 1, "4000, 1, 5838189, 1, 4000, 1, 6689834, 1"]) def test_happy_birthday(self): flow = flows.happy_birthday() self.bulb.set_scene(SceneClass.CF, flow) self.assertEqual(self.socket.sent["method"], "set_scene") self.assertEqual( self.socket.sent["params"], [ "cf", 0, 1, "1996, 1, 14438425, 80, 1996, 1, 14448670, 80, 1996, 1, 11153940, 80" ], ) def test_candle_flicker(self): flow = flows.candle_flicker() self.bulb.set_scene(SceneClass.CF, flow) self.assertEqual(self.socket.sent["method"], "set_scene") self.assertEqual( self.socket.sent["params"], [ "cf", 0, 0, "800, 2, 2700, 50, 800, 2, 2700, 30, 1200, 2, 2700, 80, 800, 2, 2700, 60, 1200, 2, 2700, 90, 2400, 2, 2700, 50, 1200, 2, 2700, 80, 800, 2, 2700, 60, 400, 2, 2700, 70", ], ) def test_home(self): flow = flows.home() self.bulb.set_scene(SceneClass.CF, flow) self.assertEqual(self.socket.sent["method"], "set_scene") self.assertEqual(self.socket.sent["params"], ["cf", 0, 0, "500, 2, 3200, 80"]) def test_night_mode(self): flow = flows.night_mode() self.bulb.set_scene(SceneClass.CF, flow) self.assertEqual(self.socket.sent["method"], "set_scene") self.assertEqual(self.socket.sent["params"], ["cf", 0, 0, "500, 1, 16750848, 1"]) def test_date_night(self): flow = flows.date_night() self.bulb.set_scene(SceneClass.CF, flow) self.assertEqual(self.socket.sent["method"], "set_scene") self.assertEqual(self.socket.sent["params"], ["cf", 0, 0, "500, 1, 16737792, 50"]) def test_movie(self): flow = flows.movie() self.bulb.set_scene(SceneClass.CF, flow) self.assertEqual(self.socket.sent["method"], "set_scene") self.assertEqual(self.socket.sent["params"], ["cf", 0, 0, "500, 1, 1315890, 50"]) def test_notification(self): notification_event = threading.Event() listening_stopped_event = threading.Event() shutdown = False def _callback(new_properties): notification_event.set() def _listen(): self.bulb.listen(_callback) listening_stopped_event.set() def _blocking_recv(size): time.sleep(0.1) if shutdown: raise IOError return b'{"method": "props", "params": {"power": "on"}}' def _shutdown(type): shutdown = True # noqa: F841 socket = mock.MagicMock() type(socket).recv = mock.MagicMock(side_effect=_blocking_recv) type(socket).shutdown = mock.MagicMock(side_effect=_shutdown) with mock.patch("yeelight.main.socket.socket", return_value=socket): assert self.bulb.last_properties == {} thread = threading.Thread(target=_listen) thread.start() assert notification_event.wait(0.5) is True assert self.bulb.last_properties == {"power": "on"} self.bulb.stop_listening() assert listening_stopped_event.wait(0.5) is True
class Tests(unittest.TestCase): def setUp(self): self.socket = SocketMock() self.bulb = Bulb(ip="", auto_on=True) self.bulb._Bulb__socket = self.socket def test_rgb1(self): self.bulb.set_rgb(255, 255, 0) self.assertEqual(self.socket.sent["method"], "set_rgb") self.assertEqual(self.socket.sent["params"], [16776960, "smooth", 300]) def test_rgb2(self): self.bulb.effect = "sudden" self.bulb.set_rgb(255, 255, 0) self.assertEqual(self.socket.sent["method"], "set_rgb") self.assertEqual(self.socket.sent["params"], [16776960, "sudden", 300]) def test_rgb3(self): self.bulb.set_rgb(255, 255, 0, effect="sudden") self.assertEqual(self.socket.sent["method"], "set_rgb") self.assertEqual(self.socket.sent["params"], [16776960, "sudden", 300]) def test_hsv1(self): self.bulb.set_hsv(200, 100, effect="sudden") self.assertEqual(self.socket.sent["method"], "set_hsv") self.assertEqual(self.socket.sent["params"], [200, 100, "sudden", 300]) def test_hsv2(self): self.bulb.set_hsv(200, 100, 10, effect="sudden", duration=500) self.assertEqual(self.socket.sent["method"], "start_cf") self.assertEqual(self.socket.sent["params"], [1, 1, "50, 1, 43263, 10"]) def test_hsv3(self): self.bulb.set_hsv(200, 100, 10, effect="smooth", duration=1000) self.assertEqual(self.socket.sent["method"], "start_cf") self.assertEqual(self.socket.sent["params"], [1, 1, "1000, 1, 43263, 10"]) def test_hsv4(self): self.bulb.effect = "sudden" self.bulb.set_hsv(200, 100, 10, effect="smooth", duration=1000) self.assertEqual(self.socket.sent["method"], "start_cf") self.assertEqual(self.socket.sent["params"], [1, 1, "1000, 1, 43263, 10"]) def test_toggle1(self): self.bulb.toggle() self.assertEqual(self.socket.sent["method"], "toggle") self.assertEqual(self.socket.sent["params"], ["smooth", 300]) self.bulb.toggle(duration=3000) self.assertEqual(self.socket.sent["params"], ["smooth", 3000]) def test_turn_off1(self): self.bulb.turn_off() self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["off", "smooth", 300]) self.bulb.turn_off(duration=3000) self.assertEqual(self.socket.sent["params"], ["off", "smooth", 3000]) def test_turn_on1(self): self.bulb.turn_on() self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["on", "smooth", 300, enums.PowerMode.LAST.value]) self.bulb.turn_on(duration=3000) self.assertEqual(self.socket.sent["params"], ["on", "smooth", 3000, enums.PowerMode.LAST.value]) def test_turn_on2(self): self.bulb.effect = "sudden" self.bulb.turn_on() self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["on", "sudden", 300, enums.PowerMode.LAST.value]) def test_turn_on3(self): self.bulb.turn_on(effect="sudden", duration=50) self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["on", "sudden", 50, enums.PowerMode.LAST.value]) def test_turn_on4(self): self.bulb.power_mode = enums.PowerMode.MOONLIGHT self.bulb.turn_on() self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual( self.socket.sent["params"], ["on", "smooth", 300, enums.PowerMode.MOONLIGHT.value]) def test_turn_on5(self): self.bulb.turn_on(power_mode=enums.PowerMode.MOONLIGHT) self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual( self.socket.sent["params"], ["on", "smooth", 300, enums.PowerMode.MOONLIGHT.value]) def test_set_power_mode1(self): self.bulb.set_power_mode(enums.PowerMode.MOONLIGHT) self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual( self.socket.sent["params"], ["on", "smooth", 300, enums.PowerMode.MOONLIGHT.value]) def test_set_power_mode2(self): self.bulb.set_power_mode(enums.PowerMode.NORMAL) self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["on", "smooth", 300, enums.PowerMode.NORMAL.value]) def test_set_power_mode3(self): self.bulb.set_power_mode(enums.PowerMode.LAST) self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["on", "smooth", 300, enums.PowerMode.LAST.value]) def test_color_temp1(self): self.bulb.set_color_temp(1400) self.assertEqual(self.socket.sent["method"], "set_ct_abx") self.assertEqual(self.socket.sent["params"], [1700, "smooth", 300]) self.bulb.set_color_temp(1400, duration=3000) self.assertEqual(self.socket.sent["params"], [1700, "smooth", 3000]) def test_color_temp2(self): self.bulb.set_color_temp(8400, effect="sudden") self.assertEqual(self.socket.sent["method"], "set_ct_abx") self.assertEqual(self.socket.sent["params"], [6500, "sudden", 300])
class Device(BaseDevice): typesDevice = ["light"] name = DEVICE_NAME addConfig = AddDevice( fields=False, description= "1. Through the original application, you must enable device management over the local network.\n2. Enter the ip-address of the device (it can be viewed in the same application)." ) editConfig = EditDevice(address=True, fields=EditField(icon=True)) def __init__(self, *args, **kwargs): super().__init__(**kwargs) self.device = Bulb(self.coreAddress) try: values = self.device.get_properties() self.minmaxValue = self.device.get_model_specs() if (not look_for_param(self.values, "state") and "power" in values): val = "0" if (values["power"] == "on"): val = "1" self.values.append( DeviceElement(name="state", systemName=self.systemName, control=True, high=1, low=0, type="binary", icon="fas fa-power-off", value=val)) if (not look_for_param(self.values, "brightness") and "current_brightness" in values): self.values.append( DeviceElement(name="brightness", systemName=self.systemName, control=True, high=100, low=0, type="number", icon="far fa-sun", value=values["current_brightness"])) if (not look_for_param(self.values, "night_light") and self.minmaxValue["night_light"] != False): self.values.append( DeviceElement(name="night_light", systemName=self.systemName, control=True, high="1", low=0, type="binary", icon="fab fa-moon", value=values["active_mode"])) if (not look_for_param(self.values, "color") and values["hue"] != None): self.values.append( DeviceElement(name="color", systemName=self.systemName, control=True, high=360, low=0, type="number", icon="fab fa-medium-m", value=values["hue"])) if (not look_for_param(self.values, "saturation") and values["sat"] != None): self.values.append( DeviceElement(name="saturation", systemName=self.systemName, control=True, high=100, low=0, type="number", icon="fab fa-medium-m", value=values["sat"])) if (not look_for_param(self.values, "temp") and "ct" in values): self.values.append( DeviceElement(name="temp", systemName=self.systemName, control=True, high=self.minmaxValue["color_temp"]["max"], low=self.minmaxValue["color_temp"]["min"], type="number", icon="fas fa-adjust", value=values["ct"])) super().save() except Exception as e: logger.warning(f"yeelight initialize error. {e}") self.device = None def update_value(self, *args, **kwargs): values = self.device.get_properties() state = look_for_param(self.values, "state") if (state and "power" in values): val = "0" if (values["power"] == "on"): val = "1" saveNewDate(state, val) brightness = look_for_param(self.values, "brightness") if (brightness and "current_brightness" in values): saveNewDate(brightness, values["current_brightness"]) mode = look_for_param(self.values, "night_light") if (mode and "active_mode" in values): saveNewDate(mode, values["active_mode"]) temp = look_for_param(self.values, "temp") if (temp and "ct" in values): saveNewDate(temp, values["ct"]) color = look_for_param(self.values, "color") if (color and "hue" in values): saveNewDate(color, values["hue"]) saturation = look_for_param(self.values, "saturation") if (saturation and "sat" in values): saveNewDate(saturation, values["sat"]) def get_value(self, name): self.update_value() return super().get_value(name) def get_values(self): self.update_value() return super().get_values() def set_value(self, name, status): status = super().set_value(name, status) if (name == "state"): if (int(status) == 1): self.device.turn_on() else: self.device.turn_off() if (name == "brightness"): self.device.set_brightness(int(status)) if (name == "temp"): self.device.set_power_mode(PowerMode.NORMAL) self.device.set_color_temp(int(status)) if (name == "night_light"): if (int(status) == 1): self.device.set_power_mode(PowerMode.MOONLIGHT) if (int(status) == 0): self.device.set_power_mode(PowerMode.NORMAL) if (name == "color"): self.device.set_power_mode(PowerMode.HSV) saturation = look_for_param(self.values, "saturation") self.device.set_hsv(int(status), int(saturation.get())) if (name == "saturation"): self.device.set_power_mode(PowerMode.HSV) color = look_for_param(self.values, "color") self.device.set_hsv(int(color.get()), int(status)) def get_All_Info(self): self.update_value() return super().get_All_Info()
#!/usr/bin/env python3 from yeelight import Bulb bulb_desktop = Bulb("192.168.1.253") # bulb_desktop.set_rgb(245, 230, 245) # red green blue bulb_desktop.set_color_temp(4468) bulb_desktop.set_brightness(100)
elif event == '-SLIDER B-': value_b = values['-SLIDER B-'] elif event == '-SEND RGB-' and value_r.isnumeric( ) and value_g.isnumeric() and value_b.isnumeric(): value_r_i = int(value_r) value_g_i = int(value_g) value_b_i = int(value_b) zero_list = [0, 0, 0] value_rgb_list = [value_r_i, value_g_i, value_b_i] if value_rgb_list != zero_list: temp_bulb_obj.set_rgb(value_r_i, value_g_i, value_b_i) elif event == '-SEND BRIGHT-': slider = window[event] slider_brightness = int(values['-BRIGHT-']) temp_bulb_obj.set_brightness(slider_brightness) elif event == '-SEND TEMP-': slider = window[event] slider_temp = int(values['-TEMP-']) temp_bulb_obj.set_color_temp(slider_temp) temp_bulb_obj = None
#!/usr/bin/env python3 from yeelight import * from yeelight import Bulb from time import sleep from datetime import datetime, date, time, timedelta bulb = Bulb("192.168.178.90") bulb.turn_off() bulb.set_brightness(0) bulb.set_color_temp(1000) # bulb.set_rgb(255, 255, 0) # bulb.set_hsv(100, 320, 0) def fade(start, end): current_time = datetime.now().time() now = datetime.now() deltoid = timedelta(hours=now.hour, minutes=now.minute, seconds=now.second) progress = end - deltoid range = end - start brightness = (1 - progress/range) * 100 print(brightness) bulb.set_brightness(brightness) def do_until(action, until): end_time = datetime.combine(date.today(), time(0)) + until while datetime.now() < end_time:
dmbps = dkbps / 1024 ukbps = u / 1024 umbps = ukbps / 1024 bulbright.turn_on() bulbleft.turn_on() print(f'Download speed un-rounded and rounded:\n{dmbps}') print(round(dmbps)) print(f'Upload speed un-rounded and rounded:\n{umbps}') print(round(umbps)) if 0 < dmbps < 2: #If download speed is below 2mbps, set the bulb color to red. bulbright.set_rgb(255, 0, 0) if 2 < dmbps < 5: #If download speed is between 2 and 5mbps, set the bulb color to yellow. bulbright.set_rgb(255, 255, 0) if 5 < dmbps: #If upload speed is greater than 5mbps, set the bulb color to green. bulbright.set_rgb(0, 255, 0) if 0 < umbps < 2: #If upload speed is below 2mbps, set the bulb color to red. bulbleft.set_rgb(255, 0, 0) if 2 < umbps < 5: #If upload speed is between 2 and 5mbps, set the bulb color to yellow. bulbleft.set_rgb(255, 255, 0) if 5 < umbps: #If upload speed is greater than 5mbps, set the bulb color to green. bulbleft.set_rgb(0, 255, 0) time.sleep(20) #Reset bulbs to normal color temperature after X seconds bulbright.set_color_temp(3500) bulbleft.set_color_temp(3500)
#!/usr/bin/python3 from subprocess import Popen, PIPE from yeelight import Bulb import time from globals import * response = Popen(['owread', '28.2E40B4010000/temperature'], stdout=PIPE).communicate()[0].decode('utf-8').strip() bulb1 = Bulb(BULB_DICT["DIN03"]) print(response) if (float(response) > 50.0): bulb1.set_hsv(1, 100, 100) else: bulb1.set_color_temp(4700) response = Popen(['owread', '28.FF6AB4010000/temperature'], stdout=PIPE).communicate()[0].decode('utf-8').strip() bulb2 = Bulb(BULB_DICT["DIN01"]) print(response) if (float(response) > 50.0): bulb2.set_hsv(1, 100, 100) else: bulb2.set_color_temp(4700) response = Popen(['owread', '28.D94FB4010000/temperature'], stdout=PIPE).communicate()[0].decode('utf-8').strip() bulb3 = Bulb(BULB_DICT["DIN02"]) print(response) if (float(response) > 50.0): bulb3.set_hsv(1, 100, 100) else:
class Tests(unittest.TestCase): def setUp(self): self.socket = SocketMock() self.bulb = Bulb(ip="", auto_on=True) self.bulb._Bulb__socket = self.socket def test_rgb1(self): self.bulb.set_rgb(255, 255, 0) self.assertEqual(self.socket.sent["method"], "set_rgb") self.assertEqual(self.socket.sent["params"], [16776960, "smooth", 300]) def test_rgb2(self): self.bulb.effect = "sudden" self.bulb.set_rgb(255, 255, 0) self.assertEqual(self.socket.sent["method"], "set_rgb") self.assertEqual(self.socket.sent["params"], [16776960, "sudden", 300]) def test_rgb3(self): self.bulb.set_rgb(255, 255, 0, effect="sudden") self.assertEqual(self.socket.sent["method"], "set_rgb") self.assertEqual(self.socket.sent["params"], [16776960, "sudden", 300]) def test_hsv1(self): self.bulb.set_hsv(200, 100, effect="sudden") self.assertEqual(self.socket.sent["method"], "set_hsv") self.assertEqual(self.socket.sent["params"], [200, 100, "sudden", 300]) def test_hsv2(self): self.bulb.set_hsv(200, 100, 10, effect="sudden", duration=500) self.assertEqual(self.socket.sent["method"], "start_cf") self.assertEqual(self.socket.sent["params"], [1, 1, "50, 1, 43263, 10"]) def test_hsv3(self): self.bulb.set_hsv(200, 100, 10, effect="smooth", duration=1000) self.assertEqual(self.socket.sent["method"], "start_cf") self.assertEqual(self.socket.sent["params"], [1, 1, "1000, 1, 43263, 10"]) def test_hsv4(self): self.bulb.effect = "sudden" self.bulb.set_hsv(200, 100, 10, effect="smooth", duration=1000) self.assertEqual(self.socket.sent["method"], "start_cf") self.assertEqual(self.socket.sent["params"], [1, 1, "1000, 1, 43263, 10"]) def test_toggle1(self): self.bulb.toggle() self.assertEqual(self.socket.sent["method"], "toggle") self.assertEqual(self.socket.sent["params"], ["smooth", 300]) self.bulb.toggle(duration=3000) self.assertEqual(self.socket.sent["params"], ["smooth", 3000]) def test_turn_off1(self): self.bulb.turn_off() self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["off", "smooth", 300]) self.bulb.turn_off(duration=3000) self.assertEqual(self.socket.sent["params"], ["off", "smooth", 3000]) def test_turn_on1(self): self.bulb.turn_on() self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["on", "smooth", 300]) self.bulb.turn_on(duration=3000) self.assertEqual(self.socket.sent["params"], ["on", "smooth", 3000]) def test_turn_on2(self): self.bulb.effect = "sudden" self.bulb.turn_on() self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["on", "sudden", 300]) def test_turn_on3(self): self.bulb.turn_on(effect="sudden", duration=50) self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["on", "sudden", 50]) def test_turn_on4(self): self.bulb.power_mode = enums.PowerMode.MOONLIGHT self.bulb.turn_on() self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual( self.socket.sent["params"], ["on", "smooth", 300, enums.PowerMode.MOONLIGHT.value]) def test_turn_on5(self): self.bulb.turn_on(power_mode=enums.PowerMode.MOONLIGHT) self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual( self.socket.sent["params"], ["on", "smooth", 300, enums.PowerMode.MOONLIGHT.value]) def test_set_power_mode1(self): self.bulb.set_power_mode(enums.PowerMode.MOONLIGHT) self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual( self.socket.sent["params"], ["on", "smooth", 300, enums.PowerMode.MOONLIGHT.value]) def test_set_power_mode2(self): self.bulb.set_power_mode(enums.PowerMode.NORMAL) self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["on", "smooth", 300, enums.PowerMode.NORMAL.value]) def test_set_power_mode3(self): self.bulb.set_power_mode(enums.PowerMode.LAST) self.assertEqual(self.socket.sent["method"], "set_power") self.assertEqual(self.socket.sent["params"], ["on", "smooth", 300]) def test_color_temp1(self): self.bulb.set_color_temp(1400) self.assertEqual(self.socket.sent["method"], "set_ct_abx") self.assertEqual(self.socket.sent["params"], [1700, "smooth", 300]) self.bulb.set_color_temp(1400, duration=3000) self.assertEqual(self.socket.sent["params"], [1700, "smooth", 3000]) def test_color_temp2(self): self.bulb.set_color_temp(8400, effect="sudden") self.assertEqual(self.socket.sent["method"], "set_ct_abx") self.assertEqual(self.socket.sent["params"], [6500, "sudden", 300]) def test_color_temp_with_model_declared(self): self.bulb.model = "ceiling2" self.bulb.set_color_temp(1800) self.assertEqual(self.socket.sent["method"], "set_ct_abx") self.assertEqual(self.socket.sent["params"], [2700, "smooth", 300]) def test_start_flow(self): transitions = [ TemperatureTransition(1700, duration=40000), TemperatureTransition(6500, duration=40000) ] flow = Flow(count=1, action=Action.stay, transitions=transitions) self.bulb.start_flow(flow) self.assertEqual(self.socket.sent["method"], "start_cf") self.assertEqual(self.socket.sent["params"], [2, 1, "40000, 2, 1700, 100, 40000, 2, 6500, 100"]) def test_set_scene_color(self): self.bulb.set_scene(SceneClass.COLOR, 255, 255, 0, 10) self.assertEqual(self.socket.sent["method"], "set_scene") self.assertEqual(self.socket.sent["params"], ["color", 16776960, 10]) def test_set_scene_color_ambilight(self): self.bulb.set_scene(SceneClass.COLOR, 255, 255, 0, 10, light_type=LightType.Ambient) self.assertEqual(self.socket.sent["method"], "bg_set_scene") self.assertEqual(self.socket.sent["params"], ["color", 16776960, 10]) def test_set_scene_color_temperature(self): self.bulb.set_scene(SceneClass.CT, 2000, 15) self.assertEqual(self.socket.sent["method"], "set_scene") self.assertEqual(self.socket.sent["params"], ["ct", 2000, 15]) def test_set_scene_hsv(self): self.bulb.set_scene(SceneClass.HSV, 200, 100, 10) self.assertEqual(self.socket.sent["method"], "set_scene") self.assertEqual(self.socket.sent["params"], ["hsv", 200, 100, 10]) def test_set_scene_color_flow(self): transitions = [ TemperatureTransition(1700, duration=40000), TemperatureTransition(6500, duration=40000) ] flow = Flow(count=1, action=Action.stay, transitions=transitions) self.bulb.set_scene(SceneClass.CF, flow) self.assertEqual(self.socket.sent["method"], "set_scene") self.assertEqual( self.socket.sent["params"], ["cf", 2, 1, "40000, 2, 1700, 100, 40000, 2, 6500, 100"]) def test_set_scene_auto_delay_off(self): self.bulb.set_scene(SceneClass.AUTO_DELAY_OFF, 20, 1) self.assertEqual(self.socket.sent["method"], "set_scene") self.assertEqual(self.socket.sent["params"], ["auto_delay_off", 20, 1])
class LedLightYeeLight(LedLight): def __init__(self, name, ipAddrOrName=None): if ipAddrOrName is None: ipAddrOrName = name self.bulb = Bulb(ipAddrOrName) self.name = name try: self.bulb.set_name(name) except Exception as exc: print "Caught exception socket.error : %s" % exc # Send an RGB message def sendRGB(self, red, green, blue): try: self.bulb.set_rgb(red, green, blue) except Exception as exc: print "Caught exception socket.error : %s" % exc # Send a white message def sendWhite(self, white): try: self.bulb.set_color_temp(5000) self.bulb.set_brightness(white) except Exception as exc: print "Caught exception socket.error : %s" % exc def turnOff(self): try: return self.bulb.turn_off() except Exception as exc: print "Caught exception socket.error : %s" % exc def turnOn(self): try: self.bulb.turn_on() except Exception as exc: print "Caught exception socket.error : %s" % exc def isOn(self): try: return self.bulb.get_properties()['power'] == 'on' except Exception as exc: print "Caught exception socket.error : %s" % exc def getWhite(self): try: properties = self.bulb.get_properties() if (properties['color_mode'] == '2'): return int(properties['bright']) else: return -1 except Exception as exc: print "Caught exception socket.error : %s" % exc # comment def getRGB(self): try: properties = self.bulb.get_properties() if (properties['color_mode'] == '1'): rgb = int(properties['rgb']) return [(rgb >> 16) & 255, (rgb >> 8) & 255, rgb & 255] else: return -1 except Exception as exc: print "Caught exception socket.error : %s" % exc
parser.add_argument('-b', '--brightness', help='set the brightness', type=int) onoff = parser.add_mutually_exclusive_group() onoff.add_argument('--on', help='turn on the light', action="store_true") onoff.add_argument('--off', help='turn off the light', action="store_true") colors = parser.add_mutually_exclusive_group() colors.add_argument('-t', '--temp', help='set the white color temp', type=int) colors.add_argument('-c', '--color', help='set the rgb color', type=valid_color) args = parser.parse_args() for bulbaddr in args.bulbs: bulb = Bulb(bulbaddr) if args.switch: status = bulb.get_properties() if status['power'] == "off": bulb.turn_on() else: bulb.turn_off() if args.on: bulb.turn_on() elif args.off: bulb.turn_off() if args.brightness is not None: bulb.set_brightness(args.brightness) if args.temp is not None: bulb.set_color_temp(args.temp) elif args.color is not None: bulb.set_rgb(args.color[0], args.color[1], args.color[2])
class LightController: MIN_BRIGHTNESS = 1 MAX_BRIGHTNESS = 100 MIN_TEMPERATURE = 1700 MAX_TEMPERATURE = 6500 MIN_HUE = 0 MAX_HUE = 359 brightness = MIN_BRIGHTNESS temperature = MIN_TEMPERATURE hue = MIN_HUE mode = 0 # TEMP def __init__(self): self.ip = CONFIG["bulbIP"] self.brightnessFactor = CONFIG["brightnessFactor"] self.temperatureFactor = CONFIG["temperatureFactor"] self.hueFactor = CONFIG["hueFactor"] self.reconnectInterval = CONFIG["reconnectInterval"] def initializeBulb(self): try: self.bulb = Bulb(self.ip, effect="smooth", duration=1000) print("Initialized bulb successfully") except: print("Bulb initializatio failed") try: self.bulb.start_music() print("Started music mode successfully") except: print("Music mode failed") threading.Timer(self.reconnectInterval, self.initializeBulb).start() def changeBrightness(self, value): new_value = round(clamp(self.brightness + value * self.brightnessFactor, self.MIN_BRIGHTNESS, self.MAX_BRIGHTNESS)) if not new_value == self.brightness: self.brightness = new_value self.setBrightness() def setBrightness(self): try: self.bulb.set_brightness(self.brightness) except: print("Setting brightness failed") def changeColor(self, value): if self.mode == 0: value = clamp(value, -50, 50) new_value = round(clamp(self.temperature + value * self.temperatureFactor, self.MIN_TEMPERATURE, self.MAX_TEMPERATURE)) if not new_value == self.temperature: self.temperature = new_value self.setTemperature() if self.mode == 1: new_value = round((self.hue + value * self.hueFactor) % self.MAX_HUE) if not new_value == self.hue: self.hue = new_value self.setHue() def setTemperature(self): try: self.bulb.set_color_temp(self.temperature) except: print("Setting temperature failed") def setHue(self): try: self.bulb.set_hsv(self.hue, 100) except: print("Setting hue failed") def toggleLight(self, value): if value: try: self.bulb.toggle() print("Toggle!") except: print("Toggling failed") def toggleMode(self, value): if value: self.mode = (self.mode + 1) % len(MODE) if self.mode == 0: self.setTemperature() if (self.mode == 1): self.setHue()