How to use the yeelight.transitions function in yeelight

To help you get started, we’ve selected a few yeelight examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github home-assistant / home-assistant / homeassistant / components / yeelight / light.py View on Github external
EFFECT_RGB: yee_transitions.rgb,
                EFFECT_RANDOM_LOOP: yee_transitions.randomloop,
                EFFECT_LSD: yee_transitions.lsd,
                EFFECT_SLOWDOWN: yee_transitions.slowdown,
            }

            if effect in self.custom_effects_names:
                flow = Flow(**self.custom_effects[effect])
            elif effect in effects_map:
                flow = Flow(count=0, transitions=effects_map[effect]())
            elif effect == EFFECT_FAST_RANDOM_LOOP:
                flow = Flow(
                    count=0, transitions=yee_transitions.randomloop(duration=250)
                )
            elif effect == EFFECT_WHATSAPP:
                flow = Flow(count=2, transitions=yee_transitions.pulse(37, 211, 102))
            elif effect == EFFECT_FACEBOOK:
                flow = Flow(count=2, transitions=yee_transitions.pulse(59, 89, 152))
            elif effect == EFFECT_TWITTER:
                flow = Flow(count=2, transitions=yee_transitions.pulse(0, 172, 237))

            try:
                self._bulb.start_flow(flow, light_type=self.light_type)
            except BulbException as ex:
                _LOGGER.error("Unable to set effect: %s", ex)
github skorokithakis / yeecli / yeecli / cli.py View on Github external
def pulse(hex_color, pulses):
    """Pulse the bulb in a specific color."""
    red, green, blue = hex_color_to_rgb(hex_color)
    transitions = tr.pulse(red, green, blue)

    for bulb in BULBS:
        # Get the initial bulb state.
        if bulb.get_properties().get("power", "off") == "off":
            action = yeelight.Flow.actions.off
        else:
            action = yeelight.Flow.actions.recover

        bulb.start_flow(yeelight.Flow(count=pulses, action=action, transitions=transitions))
github home-assistant / home-assistant / homeassistant / components / yeelight / light.py View on Github external
def set_effect(self, effect) -> None:
        """Activate effect."""
        if effect:
            if effect == EFFECT_STOP:
                self._bulb.stop_flow(light_type=self.light_type)
                return

            effects_map = {
                EFFECT_DISCO: yee_transitions.disco,
                EFFECT_TEMP: yee_transitions.temp,
                EFFECT_STROBE: yee_transitions.strobe,
                EFFECT_STROBE_COLOR: yee_transitions.strobe_color,
                EFFECT_ALARM: yee_transitions.alarm,
                EFFECT_POLICE: yee_transitions.police,
                EFFECT_POLICE2: yee_transitions.police2,
                EFFECT_CHRISTMAS: yee_transitions.christmas,
                EFFECT_RGB: yee_transitions.rgb,
                EFFECT_RANDOM_LOOP: yee_transitions.randomloop,
                EFFECT_LSD: yee_transitions.lsd,
                EFFECT_SLOWDOWN: yee_transitions.slowdown,
            }

            if effect in self.custom_effects_names:
                flow = Flow(**self.custom_effects[effect])
            elif effect in effects_map:
github Nekmo / then / then / components / yeelight.py View on Github external
def send(self):
        from yeelight import Flow
        from yeelight import transitions
        bulb = self.get_bulb()
        state = self.state
        if state == 'TOGGLE':
            state = {'off': 'ON', 'on': 'OFF'}[bulb.get_properties(['power'])['power']]
        if state == 'ON':
            bulb.turn_on(effect=self.effect, duration=self.effect_duration)
        elif state == 'OFF':
            bulb.turn_off(effect=self.effect, duration=self.effect_duration)
        if self.flow_transition:
            trans = getattr(transitions, self.flow_transition)
            if self.flow_transition == 'pulse':
                trans = trans(*self._color, self.flow_duration or 250, self.brightness or 100)
            else:
                kwargs = {'duration': self.flow_duration, 'brightness': self.brightness,
                          'sleep': self.flow_sleep}
                spec = inspect.getargspec(trans)
                kwargs = {key: value for key, value in kwargs.items() if key in spec.args and value is not None}
                trans = trans(**kwargs)
            bulb.start_flow(Flow(count=self.flow_count, transitions=trans))
        elif self._color:
            bulb.set_rgb(*self._color)
        elif self.brightness:
            bulb.set_brightness(self.brightness)
        elif self.temperature:
            bulb.set_color_temp(self.temperature)
github CodeLabClub / codelab_adapter_extensions / servers_v2 / yeelight_server.py View on Github external
def run(self):
        while self._running:
            time.sleep(0.1)
            if not self.q.empty():
                payload = self.q.get()
                self.logger.info(f'python: {payload}')
                message_id = payload.get("message_id")
                python_code = payload["content"]
                try:
                    output = eval(python_code, {"__builtins__": None}, {
                        "yeelight": yeelight,
                        "bulb_ctl": self.bulb_ctl,
                        "transitions": transitions
                    })
                except Exception as e:
                    output = e
                payload["content"] = str(output)
                message = {"payload": payload}
                self.publish(message)