async def async_set_flash(self, flash) -> None: """Activate flash.""" if not flash: return if int(self._bulb.last_properties["color_mode"]) != 1: _LOGGER.error("Flash supported currently only in RGB mode") return transition = int(self.config[CONF_TRANSITION]) if flash == FLASH_LONG: count = 1 duration = transition * 5 if flash == FLASH_SHORT: count = 1 duration = transition * 2 red, green, blue = color_util.color_hs_to_RGB(*self.hs_color) transitions = [] transitions.append( RGBTransition(255, 0, 0, brightness=10, duration=duration)) transitions.append(SleepTransition(duration=transition)) transitions.append( RGBTransition(red, green, blue, brightness=self.brightness, duration=duration)) flow = Flow(count=count, transitions=transitions) await self._bulb.async_start_flow(flow, light_type=self.light_type)
def set_flash(self, flash) -> None: """Activate flash.""" if flash: from yeelight import (RGBTransition, SleepTransition, Flow, BulbException) if self._bulb.last_properties["color_mode"] != 1: _LOGGER.error("Flash supported currently only in RGB mode.") return transition = int(self.config[CONF_TRANSITION]) if flash == FLASH_LONG: count = 1 duration = transition * 5 if flash == FLASH_SHORT: count = 1 duration = transition * 2 red, green, blue = self.rgb_color transitions = list() transitions.append( RGBTransition(255, 0, 0, brightness=10, duration=duration)) transitions.append(SleepTransition(duration=transition)) transitions.append( RGBTransition(red, green, blue, brightness=self.brightness, duration=duration)) flow = Flow(count=count, transitions=transitions) try: self._bulb.start_flow(flow) except BulbException as ex: _LOGGER.error("Unable to set flash: %s", ex)
def update_yeelight_beacon(beacon, temperature_color, condition_color): ''' Updates a Yeelight beacon ''' brightness = config['lightshow']['brightness'] duration = config['lightshow']['transition']['duration'] * 1000 delay = config['lightshow']['transition']['delay'] * 1000 flow = Flow(0, Flow.actions.recover, [ RGBTransition(*temperature_color, duration, brightness), SleepTransition(delay), RGBTransition(*condition_color, duration, brightness), SleepTransition(delay) ]) bulb = SmartBulb(beacon['ip']) bulb.start_flow(flow)
async def test_effects(hass: HomeAssistant): """Test effects.""" yaml_configuration = { DOMAIN: { CONF_DEVICES: YAML_CONFIGURATION[DOMAIN][CONF_DEVICES], CONF_CUSTOM_EFFECTS: [ { CONF_NAME: "mock_effect", CONF_FLOW_PARAMS: { ATTR_COUNT: 3, ATTR_TRANSITIONS: [ { YEELIGHT_HSV_TRANSACTION: [300, 50, 500, 50] }, { YEELIGHT_RGB_TRANSITION: [100, 100, 100, 300, 30] }, { YEELIGHT_TEMPERATURE_TRANSACTION: [3000, 200, 20] }, { YEELIGHT_SLEEP_TRANSACTION: [800] }, ], }, }, ], } } mocked_bulb = _mocked_bulb() with patch(f"{MODULE}.Bulb", return_value=mocked_bulb): assert await async_setup_component(hass, DOMAIN, yaml_configuration) await hass.async_block_till_done() assert hass.states.get(ENTITY_LIGHT).attributes.get( "effect_list") == YEELIGHT_COLOR_EFFECT_LIST + ["mock_effect"] async def _async_test_effect(name, target=None, called=True): mocked_start_flow = MagicMock() type(mocked_bulb).start_flow = mocked_start_flow await hass.services.async_call( "light", SERVICE_TURN_ON, { ATTR_ENTITY_ID: ENTITY_LIGHT, ATTR_EFFECT: name }, blocking=True, ) if not called: return mocked_start_flow.assert_called_once() if target is None: return args, _ = mocked_start_flow.call_args flow = args[0] assert flow.count == target.count assert flow.action == target.action assert str(flow.transitions) == str(target.transitions) effects = { "mock_effect": Flow( count=3, transitions=[ HSVTransition(300, 50, 500, 50), RGBTransition(100, 100, 100, 300, 30), TemperatureTransition(3000, 200, 20), SleepTransition(800), ], ), EFFECT_DISCO: Flow(transitions=transitions.disco()), EFFECT_FAST_RANDOM_LOOP: None, EFFECT_WHATSAPP: Flow(count=2, transitions=transitions.pulse(37, 211, 102)), EFFECT_FACEBOOK: Flow(count=2, transitions=transitions.pulse(59, 89, 152)), EFFECT_TWITTER: Flow(count=2, transitions=transitions.pulse(0, 172, 237)), } for name, target in effects.items(): await _async_test_effect(name, target) await _async_test_effect("not_existed", called=False)
async def test_effects(hass: HomeAssistant): """Test effects.""" assert await async_setup_component( hass, DOMAIN, { DOMAIN: { CONF_CUSTOM_EFFECTS: [ { CONF_NAME: "mock_effect", CONF_FLOW_PARAMS: { ATTR_COUNT: 3, ATTR_TRANSITIONS: [ {YEELIGHT_HSV_TRANSACTION: [300, 50, 500, 50]}, {YEELIGHT_RGB_TRANSITION: [100, 100, 100, 300, 30]}, {YEELIGHT_TEMPERATURE_TRANSACTION: [3000, 200, 20]}, {YEELIGHT_SLEEP_TRANSACTION: [800]}, ], }, } ] } }, ) config_entry = MockConfigEntry(domain=DOMAIN, data=CONFIG_ENTRY_DATA) config_entry.add_to_hass(hass) mocked_bulb = _mocked_bulb() with _patch_discovery(), _patch_discovery_interval(), patch( f"{MODULE}.AsyncBulb", return_value=mocked_bulb ): assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() assert hass.states.get(ENTITY_LIGHT).attributes.get( "effect_list" ) == YEELIGHT_COLOR_EFFECT_LIST + ["mock_effect"] async def _async_test_effect(name, target=None, called=True): async_mocked_start_flow = AsyncMock() mocked_bulb.async_start_flow = async_mocked_start_flow await hass.services.async_call( "light", SERVICE_TURN_ON, {ATTR_ENTITY_ID: ENTITY_LIGHT, ATTR_EFFECT: name}, blocking=True, ) if not called: return async_mocked_start_flow.assert_called_once() if target is None: return args, _ = async_mocked_start_flow.call_args flow = args[0] assert flow.count == target.count assert flow.action == target.action assert str(flow.transitions) == str(target.transitions) effects = { "mock_effect": Flow( count=3, transitions=[ HSVTransition(300, 50, 500, 50), RGBTransition(100, 100, 100, 300, 30), TemperatureTransition(3000, 200, 20), SleepTransition(800), ], ), EFFECT_DISCO: Flow(transitions=transitions.disco()), EFFECT_FAST_RANDOM_LOOP: None, EFFECT_WHATSAPP: Flow(count=2, transitions=transitions.pulse(37, 211, 102)), EFFECT_FACEBOOK: Flow(count=2, transitions=transitions.pulse(59, 89, 152)), EFFECT_TWITTER: Flow(count=2, transitions=transitions.pulse(0, 172, 237)), EFFECT_HOME: Flow( count=0, action=Action.recover, transitions=[ TemperatureTransition(degrees=3200, duration=500, brightness=80) ], ), EFFECT_NIGHT_MODE: Flow( count=0, action=Action.recover, transitions=[RGBTransition(0xFF, 0x99, 0x00, duration=500, brightness=1)], ), EFFECT_DATE_NIGHT: Flow( count=0, action=Action.recover, transitions=[RGBTransition(0xFF, 0x66, 0x00, duration=500, brightness=50)], ), EFFECT_MOVIE: Flow( count=0, action=Action.recover, transitions=[ RGBTransition( red=0x14, green=0x14, blue=0x32, duration=500, brightness=50 ) ], ), EFFECT_SUNRISE: Flow( count=1, action=Action.stay, transitions=[ RGBTransition( red=0xFF, green=0x4D, blue=0x00, duration=50, brightness=1 ), TemperatureTransition(degrees=1700, duration=360000, brightness=10), TemperatureTransition(degrees=2700, duration=540000, brightness=100), ], ), EFFECT_SUNSET: Flow( count=1, action=Action.off, transitions=[ TemperatureTransition(degrees=2700, duration=50, brightness=10), TemperatureTransition(degrees=1700, duration=180000, brightness=5), RGBTransition( red=0xFF, green=0x4C, blue=0x00, duration=420000, brightness=1 ), ], ), EFFECT_ROMANCE: Flow( count=0, action=Action.stay, transitions=[ RGBTransition( red=0x59, green=0x15, blue=0x6D, duration=4000, brightness=1 ), RGBTransition( red=0x66, green=0x14, blue=0x2A, duration=4000, brightness=1 ), ], ), EFFECT_HAPPY_BIRTHDAY: Flow( count=0, action=Action.stay, transitions=[ RGBTransition( red=0xDC, green=0x50, blue=0x19, duration=1996, brightness=80 ), RGBTransition( red=0xDC, green=0x78, blue=0x1E, duration=1996, brightness=80 ), RGBTransition( red=0xAA, green=0x32, blue=0x14, duration=1996, brightness=80 ), ], ), EFFECT_CANDLE_FLICKER: Flow( count=0, action=Action.recover, transitions=[ TemperatureTransition(degrees=2700, duration=800, brightness=50), TemperatureTransition(degrees=2700, duration=800, brightness=30), TemperatureTransition(degrees=2700, duration=1200, brightness=80), TemperatureTransition(degrees=2700, duration=800, brightness=60), TemperatureTransition(degrees=2700, duration=1200, brightness=90), TemperatureTransition(degrees=2700, duration=2400, brightness=50), TemperatureTransition(degrees=2700, duration=1200, brightness=80), TemperatureTransition(degrees=2700, duration=800, brightness=60), TemperatureTransition(degrees=2700, duration=400, brightness=70), ], ), } for name, target in effects.items(): await _async_test_effect(name, target) await _async_test_effect("not_existed", called=False)
def showPanel(self): self.bulb = Bulb(self.ipEntry.get(), effect="smooth", duration=1000) self.confirmIp.destroy() self.ipEntry.destroy() self.ipText.destroy() # -------------------------------------| RGB FRAME |--------------------------------------------- self.rgb_handler = tk.Frame(master=self.window, bg='black') self.rgb_handler.grid(row=0, column=0, sticky=tk.N, pady=(15, 0), padx=(50, 0)) self.redLabel = tk.Label(master=self.rgb_handler, text="Red", bg="red", fg='white') self.greenLabel = tk.Label(master=self.rgb_handler, text="Green", bg="green", fg='white') self.blueLabel = tk.Label(master=self.rgb_handler, text="Blue", bg="blue", fg='white') self.redLabel.grid(row=0, column=0, sticky=tk.S, pady=(12, 2)) self.greenLabel.grid(row=0, column=1, sticky=tk.S, pady=(12, 2)) self.blueLabel.grid(row=0, column=2, sticky=tk.S, pady=(12, 2)) self.redSlider = tk.Scale(master=self.rgb_handler, from_=1, to=255, tickinterval=60, orient=tk.VERTICAL, bg="red", fg='white', command=self.setRedText) self.greenSlider = tk.Scale(master=self.rgb_handler, from_=1, to=255, tickinterval=60, orient=tk.VERTICAL, bg="green", fg='white', command=self.setGreenText) self.blueSlider = tk.Scale(master=self.rgb_handler, from_=1, to=255, tickinterval=60, orient=tk.VERTICAL, bg="blue", fg='white', command=self.setBlueText) self.redSlider.grid(row=1, column=0, sticky=tk.W, padx=(10, 10), pady=10) self.greenSlider.grid(row=1, column=1, sticky=tk.W, padx=(10, 10)) self.blueSlider.grid(row=1, column=2, sticky=tk.W, padx=(10, 10)) self.redInput = tk.Entry(master=self.rgb_handler, width=5, bg='red', fg='white') self.greenInput = tk.Entry(master=self.rgb_handler, width=5, bg='green', fg='white') self.blueInput = tk.Entry(master=self.rgb_handler, width=5, bg='blue', fg='white') self.redInput.insert(tk.END, 1) self.greenInput.insert(tk.END, 1) self.blueInput.insert(tk.END, 1) self.redInput.grid(row=2, column=0, sticky=tk.N, padx=(10, 10)) self.greenInput.grid(row=2, column=1, sticky=tk.N, padx=(10, 10)) self.blueInput.grid(row=2, column=2, sticky=tk.N, padx=(10, 10)) self.colorFrame = tk.Frame(master=self.rgb_handler, bg="black", width=40, height=40, relief=tk.RIDGE, borderwidth=2) self.colorFrame.grid(row=3, column=1, sticky=tk.S, padx=(10, 10), pady=(10, 15)) self.applyButton = tk.Button(master=self.rgb_handler, command=self.setColors, text="Apply Color") self.applyButton.grid(row=4, column=1, sticky=tk.S) # ---------------------------------| POWER FRAME |---------------------------------------- self.power_handler = tk.Frame(master=self.window, bg='black') self.power_handler.grid(row=0, column=1, sticky=tk.N, padx=(60, 60), pady=20) self.title = tk.Label(master=self.power_handler, text='Xiaomi led Bulb remote control', fg='white', bg='black', font=('Helvetica', 14, 'bold')) self.title.grid(row=0, column=1, sticky=tk.N) self.buttonsHandler = tk.Frame(master=self.power_handler, bg='black') self.buttonsHandler.grid(row=1, column=1, sticky=tk.N, pady=10) self.turnOnButton = tk.Button(master=self.buttonsHandler, text="ON", width=15, command=self.turnOnBulb, padx=5) self.turnOnButton.grid(row=0, column=0, sticky=tk.N, padx=5) self.turnOffButton = tk.Button(master=self.buttonsHandler, text="OFF", width=15, command=self.turnOffBulb) self.turnOffButton.grid(row=0, column=1, sticky=tk.N, padx=5) self.title = tk.Label(master=self.power_handler, text='Brightness', fg='white', bg='black', font=('Helvetica', 12, 'bold')) self.title.grid(row=2, column=1, sticky=tk.N, pady=(20, 5)) self.brightnessSlider = tk.Scale(master=self.power_handler, from_=0, to=100, tickinterval=20, orient=tk.HORIZONTAL, bg="#FFFFFF", fg='#000000', length=200) self.brightnessSlider.set(80) self.brightnessSlider.grid(row=3, column=1, sticky=tk.N, pady=10) self.applyBrightnessButton = tk.Button(master=self.power_handler, text="Apply Brightness", width=15, command=self.setBrightness) self.applyBrightnessButton.grid(row=4, column=1, sticky=tk.N, pady=10) # ---------------------------| MODES FRAME |---------------------------------- self.modes_handler = tk.Frame(master=self.window, bg='black') self.modes_handler.grid(row=0, column=2, sticky=tk.N, padx=30, pady=50) self.mode_1 = tk.Button(master=self.modes_handler, text="Flow 1 (smooth)", width=15, command=lambda: self.showFlow([ RGBTransition(20, 255, 20, 2000), RGBTransition(255, 20, 20, 2000), RGBTransition(20, 20, 255, 2000), RGBTransition(255, 255, 20, 2000), RGBTransition(255, 20, 255, 2000), RGBTransition(20, 255, 255, 2000) ], 10)) self.mode_1.grid(column=0, row=0, pady=(0, 15)) self.mode_2 = tk.Button(master=self.modes_handler, text="Flow 2 (speed)", width=15, command=lambda: self.showFlow([ RGBTransition(20, 255, 20, 100), RGBTransition(255, 20, 20, 100), RGBTransition(20, 20, 255, 100), RGBTransition(255, 255, 20, 100), RGBTransition(255, 20, 255, 100), RGBTransition(20, 255, 255, 100) ], 30)) self.mode_2.grid(column=0, row=1, pady=(0, 15)) self.mode_3 = tk.Button(master=self.modes_handler, text="Flow 3 (temp)", width=15, command=lambda: self.showFlow([ TemperatureTransition(6500, 1000), TemperatureTransition(5200, 1000), TemperatureTransition(4000, 1000), TemperatureTransition(2800, 1000), TemperatureTransition(1700, 1000) ], 5)) self.mode_3.grid(column=0, row=2, pady=(0, 15)) self.mode_4 = tk.Button(master=self.modes_handler, text="Flow 4 (disco)", width=15, command=lambda: self.showFlow(disco(), 5)) self.mode_4.grid(column=0, row=3, pady=(0, 15)) self.mode_5 = tk.Button(master=self.modes_handler, text="Flow 5 (strobe)", width=15, command=lambda: self.showFlow(strobe(), 20)) self.mode_5.grid(column=0, row=4, pady=(0, 15)) self.mode_6 = tk.Button(master=self.modes_handler, text="Flow 6 (alarm)", width=15, command=lambda: self.showFlow(alarm(), 5)) self.mode_6.grid(column=0, row=5, pady=(0, 15)) self.mode_7 = tk.Button(master=self.modes_handler, text="Flow 7 (police)", width=15, command=lambda: self.showFlow(police(), 10)) self.mode_7.grid(column=0, row=6, pady=(0, 15)) self.mode_8 = tk.Button(master=self.modes_handler, text="Flow 8 (smooth)", width=15, command=lambda: self.showFlow(lsd(), 5)) self.mode_8.grid(column=0, row=7, pady=(0, 15)) self.mode_9 = tk.Button(master=self.modes_handler, text="Flow 9 (christmas)", width=15, command=lambda: self.showFlow(christmas(), 5)) self.mode_9.grid(column=0, row=8, pady=(0, 15)) self.mode_10 = tk.Button( master=self.modes_handler, text="Flow 10 (random)", width=15, command=lambda: self.showFlow(random_loop(), 5)) self.mode_10.grid(column=0, row=9, pady=(0, 15)) self.quitBT = tk.Button(master=self.window, text="Quit", font=('Helvetica', 12, 'bold'), command=self.quit) self.quitBT.grid(column=1, row=1, pady=(0, 15))
def set_effect(self, effect) -> None: """Activate effect.""" if effect: from yeelight import (RGBTransition, TemperatureTransition, SleepTransition, Flow, BulbException) transition = int(self.config[CONF_TRANSITION]) if effect == EFFECT_ALARM: count = 0 duration = 100 transitions = list() transitions.append( RGBTransition(255, 0, 0, brightness=100, duration=duration)) transitions.append( RGBTransition(255, 0, 0, brightness=60, duration=duration)) flow = Flow(count=count, transitions=transitions) if effect == EFFECT_DISCO: count = 0 duration = 300 transitions = list() transitions.append( RGBTransition(255, 0, 0, brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(255, 0, 0, brightness=1, duration=duration)) transitions.append( RGBTransition(128, 255, 0, brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(128, 255, 0, brightness=1, duration=duration)) transitions.append( RGBTransition(0, 255, 255, brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(0, 255, 255, brightness=1, duration=duration)) transitions.append( RGBTransition(128, 0, 255, brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(128, 0, 255, brightness=1, duration=duration)) flow = Flow(count=count, transitions=transitions) if effect == EFFECT_STROBE: count = 0 duration = 50 transitions = list() transitions.append( RGBTransition(255, 255, 255, brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(255, 255, 255, brightness=1, duration=duration)) flow = Flow(count=count, transitions=transitions) if effect == EFFECT_COLOR_STROBE: count = 0 duration = 50 transitions = list() transitions.append( RGBTransition(0, 0, 255, brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(255, 255, 0, brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(255, 0, 127, brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(255, 0, 0, brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(0, 255, 255, brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(255, 128, 0, brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(0, 255, 0, brightness=self.brightness, duration=duration)) flow = Flow(count=count, transitions=transitions) if effect == EFFECT_POLICE: count = 0 duration = 300 transitions = list() transitions.append( RGBTransition(255, 0, 0, brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(0, 0, 255, brightness=self.brightness, duration=duration)) flow = Flow(count=count, transitions=transitions) if effect == EFFECT_POLICE2: count = 0 duration = 200 transitions = list() transitions.append( RGBTransition(255, 0, 0, brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(255, 0, 0, brightness=1, duration=duration)) transitions.append( RGBTransition(255, 0, 0, brightness=self.brightness, duration=duration)) transitions.append(SleepTransition(duration=duration)) transitions.append( RGBTransition(0, 0, 255, brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(0, 0, 255, brightness=1, duration=duration)) transitions.append( RGBTransition(0, 0, 255, brightness=self.brightness, duration=duration)) transitions.append(SleepTransition(duration=duration)) flow = Flow(count=count, transitions=transitions) if effect == EFFECT_CHRISTMAS: count = 0 duration = 300 transitions = list() transitions.append( RGBTransition(255, 0, 0, brightness=self.brightness, duration=duration)) transitions.append(SleepTransition(duration=3000)) transitions.append( RGBTransition(0, 255, 0, brightness=self.brightness, duration=duration)) transitions.append(SleepTransition(duration=3000)) flow = Flow(count=count, transitions=transitions) if effect == EFFECT_RGB: count = 0 duration = 300 transitions = list() transitions.append( RGBTransition(255, 0, 0, brightness=self.brightness, duration=duration)) transitions.append(SleepTransition(duration=3000)) transitions.append( RGBTransition(0, 255, 0, brightness=self.brightness, duration=duration)) transitions.append(SleepTransition(duration=3000)) transitions.append( RGBTransition(0, 0, 255, brightness=self.brightness, duration=duration)) transitions.append(SleepTransition(duration=3000)) flow = Flow(count=count, transitions=transitions) if effect == EFFECT_RGB_TRANS: count = 0 duration = 10000 transitions = list() transitions.append( RGBTransition(255, 0, 0, brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(0, 255, 0, brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(0, 0, 255, brightness=self.brightness, duration=duration)) flow = Flow(count=count, transitions=transitions) if effect == EFFECT_ENJOY: count = 0 duration = 40000 transitions = list() transitions.append( TemperatureTransition(1700, duration=duration)) transitions.append( TemperatureTransition(6500, duration=duration)) flow = Flow(count=count, transitions=transitions) if effect == EFFECT_RANDOM_LOOP: count = 0 duration = 3000 transitions = list() transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=duration)) flow = Flow(count=count, transitions=transitions) if effect == EFFECT_RANDOM_FASTLOOP: count = 0 duration = 800 transitions = list() transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=duration)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=duration)) flow = Flow(count=count, transitions=transitions) if effect == EFFECT_SLOWDOWN: count = 0 transitions = list() transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=250)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=500)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=1000)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=200)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=3000)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=4000)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=5000)) transitions.append( RGBTransition(random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), brightness=self.brightness, duration=6000)) flow = Flow(count=count, transitions=transitions) if effect == EFFECT_WHATSAPP_NOTIFY: count = 1 duration = 250 transitions = list() transitions.append( RGBTransition(37, 211, 102, brightness=self.brightness, duration=duration)) transitions.append(SleepTransition(duration=transition)) transitions.append( RGBTransition(37, 211, 102, brightness=10, duration=duration)) transitions.append( RGBTransition(37, 211, 102, brightness=self.brightness, duration=duration)) flow = Flow(count=count, transitions=transitions) if effect == EFFECT_FACEBOOK_NOTIFY: count = 1 duration = 250 transitions = list() transitions.append( RGBTransition(59, 89, 152, brightness=self.brightness, duration=duration)) transitions.append(SleepTransition(duration=transition)) transitions.append( RGBTransition(59, 89, 152, brightness=10, duration=duration)) transitions.append( RGBTransition(59, 89, 152, brightness=self.brightness, duration=duration)) flow = Flow(count=count, transitions=transitions) if effect == EFFECT_TWITTER_NOTIFY: count = 1 duration = 250 transitions = list() transitions.append( RGBTransition(0, 172, 237, brightness=self.brightness, duration=duration)) transitions.append(SleepTransition(duration=transition)) transitions.append( RGBTransition(0, 172, 237, brightness=10, duration=duration)) transitions.append( RGBTransition(0, 172, 237, brightness=self.brightness, duration=duration)) flow = Flow(count=count, transitions=transitions) if effect == EFFECT_STOP: self._bulb.stop_flow() return try: self._bulb.start_flow(flow) except BulbException as ex: _LOGGER.error("Unable to set effect: %s", ex)
#!/usr/bin/env python3 from yeelight import RGBTransition, Flow from bulb_ip import B from state import get_state color = int(get_state(props=['rgb'])['rgb']) b = color & 0xff color >>= 8 g = color & 0xff color >>= 8 r = color & 0xff pink = RGBTransition(0xff, 0x16, 0x94, 500, 100) pink = RGBTransition(0xff, 0x00, 0xff, 500, 100) current = RGBTransition(r, g, b, 500, 100) transitions = [pink if i % 2 == 0 else current for i in range(9)] flow = Flow(count=1, transitions=transitions) B.start_flow(flow)
def flow_bulb(self): transitions = [RGBTransition(255, 0, 255, duration=1000)] flow = Flow(count=0, transitions=transitions) self.bulb.start_flow(flow)
import sys sys.path.append('../') from yeelight import SmartBulb, Flow, RGBTransition, SleepTransition RED = [255, 0, 0] GREEN = [0, 255, 0] BLUE = [0, 0, 255] flow = Flow( 10, Flow.actions.recover, [ RGBTransition(*RED, 1000, 100), SleepTransition(1000), RGBTransition(*GREEN, 1000, 100), SleepTransition(1000), RGBTransition(*BLUE, 1000, 100), SleepTransition(1000) ] ) bulb = SmartBulb('192.168.1.103') bulb.start_flow(flow)
from yeelight import Bulb, HSVTransition, Flow, TemperatureTransition, SleepTransition, RGBTransition import sys ip = sys.argv[1] ip2 = sys.argv[2] bulb = Bulb(ip) bulb2 = Bulb(ip2) bulb.turn_on() bulb2.turn_on() bulb.set_rgb(255, 255, 255) bulb2.set_rgb(255, 255, 255) transitions = [ RGBTransition(255, 0, 0, duration=500), RGBTransition(255, 215, 0, duration=500), RGBTransition(50, 205, 50, duration=500), RGBTransition(0, 206, 209, duration=500), RGBTransition(0, 0, 255, duration=500), RGBTransition(255, 255, 255, duration=500), RGBTransition(139, 0, 139, duration=500) ] flow = Flow( count=0, transitions=transitions ) bulb.start_flow(flow)
#!/usr/bin/env python3 from yeelight import Bulb, BulbException, Flow, RGBTransition from time import sleep from random import uniform from bulb_ip import B from sys import argv B.turn_on() if len(argv) > 1: flow = Flow(count=0, transitions= [RGBTransition(255, 0, 255, duration=1000)]) B.start_flow(flow) sleep(400) else: while True: c = int(uniform(1, 0xffffff)) color = hex(c).replace('0x','').rjust(6,'0') r = color[0:2] g = color[2:4] b = color[4:6] try: B.set_rgb(int(r, 16), int(g, 16), int(b, 16)) print('good ', r, g, b) except BulbException as e: print('error', r, g, b, e) sleep(2)
async def test_effects(hass: HomeAssistant): """Test effects.""" assert await async_setup_component( hass, DOMAIN, { DOMAIN: { CONF_CUSTOM_EFFECTS: [ { CONF_NAME: "mock_effect", CONF_FLOW_PARAMS: { ATTR_COUNT: 3, ATTR_TRANSITIONS: [ { YEELIGHT_HSV_TRANSACTION: [300, 50, 500, 50] }, { YEELIGHT_RGB_TRANSITION: [100, 100, 100, 300, 30] }, { YEELIGHT_TEMPERATURE_TRANSACTION: [3000, 200, 20] }, { YEELIGHT_SLEEP_TRANSACTION: [800] }, ], }, }, ], }, }, ) config_entry = MockConfigEntry( domain=DOMAIN, data={ CONF_ID: "", CONF_HOST: IP_ADDRESS, CONF_TRANSITION: DEFAULT_TRANSITION, CONF_MODE_MUSIC: DEFAULT_MODE_MUSIC, CONF_SAVE_ON_CHANGE: DEFAULT_SAVE_ON_CHANGE, CONF_NIGHTLIGHT_SWITCH: DEFAULT_NIGHTLIGHT_SWITCH, }, ) config_entry.add_to_hass(hass) mocked_bulb = _mocked_bulb() with _patch_discovery(MODULE), patch(f"{MODULE}.Bulb", return_value=mocked_bulb): assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() assert hass.states.get(ENTITY_LIGHT).attributes.get( "effect_list") == YEELIGHT_COLOR_EFFECT_LIST + ["mock_effect"] async def _async_test_effect(name, target=None, called=True): mocked_start_flow = MagicMock() type(mocked_bulb).start_flow = mocked_start_flow await hass.services.async_call( "light", SERVICE_TURN_ON, { ATTR_ENTITY_ID: ENTITY_LIGHT, ATTR_EFFECT: name }, blocking=True, ) if not called: return mocked_start_flow.assert_called_once() if target is None: return args, _ = mocked_start_flow.call_args flow = args[0] assert flow.count == target.count assert flow.action == target.action assert str(flow.transitions) == str(target.transitions) effects = { "mock_effect": Flow( count=3, transitions=[ HSVTransition(300, 50, 500, 50), RGBTransition(100, 100, 100, 300, 30), TemperatureTransition(3000, 200, 20), SleepTransition(800), ], ), EFFECT_DISCO: Flow(transitions=transitions.disco()), EFFECT_FAST_RANDOM_LOOP: None, EFFECT_WHATSAPP: Flow(count=2, transitions=transitions.pulse(37, 211, 102)), EFFECT_FACEBOOK: Flow(count=2, transitions=transitions.pulse(59, 89, 152)), EFFECT_TWITTER: Flow(count=2, transitions=transitions.pulse(0, 172, 237)), } for name, target in effects.items(): await _async_test_effect(name, target) await _async_test_effect("not_existed", called=False)