How to use yeelight - 10 common examples

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 Nekmo / then / tests / components / test_yeelight.py View on Github external
def test_color(self):
        from yeelight import Bulb
        with patch('yeelight.discover_bulbs', return_value=[Bulb('')]):
            self.get_component().send(color='#FAEBD7')
            self.bulb_mock.return_value.set_rgb.assert_called_with(250, 235, 215)
github skorokithakis / python-yeelight / yeelight / tests.py View on Github external
def setUp(self):
        self.socket = SocketMock()
        self.bulb = Bulb(ip="", auto_on=True)
        self.bulb._Bulb__socket = self.socket
github Nekmo / then / tests / components / test_yeelight.py View on Github external
def test_christmas_transition(self):
        from yeelight import Bulb
        with patch('yeelight.discover_bulbs', return_value=[Bulb('')]):
            self.get_component().send(flow_transition='christmas', flow_duration=500,
                                      brightness=80, flow_sleep=600)
            flow = self.bulb_mock.return_value.start_flow.call_args[0][0]
            self.assertEqual(flow.transitions[0].brightness, 80)
            self.assertEqual(flow.transitions[0].duration, 500)
            self.assertEqual(flow.transitions[1].duration, 600)
            self.bulb_mock.return_value.set_brightness.assert_not_called()
github skorokithakis / python-yeelight / yeelight / tests.py View on Github external
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])
github skorokithakis / python-yeelight / yeelight / tests.py View on Github external
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])
github skorokithakis / python-yeelight / yeelight / tests.py View on Github external
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])
github redaxmedia / chroma-feedback / chroma_feedback / consumer / xiaomi_yeelight / api.py View on Github external
def api_factory(ip : str) -> Any:
	api = None

	try:
		from yeelight import Bulb, BulbException

		try:
			api = Bulb(ip)
		except BulbException:
			exit(wording.get('connection_no').format('XIAOMI YEELIGHT') + wording.get('exclamation_mark'))
		try:
			api.turn_on()
		except BulbException:
			exit(wording.get('enable_feature').format('LAN CONTROL', 'XIAOMI YEELIGHT') + wording.get('exclamation_mark'))
		return api
	except ImportError:
		exit(wording.get('package_no').format('XIAOMI YEELIGHT') + wording.get('exclamation_mark'))
github skorokithakis / yeecli / yeecli / cli.py View on Github external
def cli(ip, port, effect, duration, bulb, auto_on):
    """Easily control the YeeLight RGB LED lightbulb."""
    config = ConfigParser.SafeConfigParser()
    config.read([os.path.expanduser('~/.config/yeecli/yeecli.cfg')])

    ip = param_or_config(ip, config, bulb, "ip", None)
    port = param_or_config(port, config, bulb, "port", 55443)
    effect = param_or_config(effect, config, bulb, "effect", "sudden")
    duration = param_or_config(duration, config, bulb, "duration", 500)

    if not ip:
        click.echo("No IP address specified.")
        sys.exit(1)

    BULBS.append(yeelight.Bulb(
        ip=ip,
        port=port,
        effect=effect,
        duration=duration,
        auto_on=auto_on,
    ))
github skorokithakis / python-yeelight / yeelight / main.py View on Github external
def set_rgb(self, red, green, blue, **kwargs):
        """
        Set the bulb's RGB value.

        :param int red: The red value to set (0-255).
        :param int green: The green value to set (0-255).
        :param int blue: The blue value to set (0-255).
        """
        self.ensure_on()

        red = _clamp(red, 0, 255)
        green = _clamp(green, 0, 255)
        blue = _clamp(blue, 0, 255)
        return "set_rgb", [red * 65536 + green * 256 + blue]
github skorokithakis / python-yeelight / yeelight / transitions.py View on Github external
def randomloop(duration=750, brightness=100, count=9):
    """
    Color changes between `count` randomly chosen colors.

    :param int duration: The duration to fade to next color, in milliseconds.
    :param int brightness: The brightness of the transition.
    :param int count: The number of random chosen colors in transition.

    :returns: A list of transitions.
    :rtype: list
    """
    count = _clamp(count, 1, 9)
    transitions = [HSVTransition(random.randint(0, 360), 100, duration=duration) for _ in range(count)]
    return transitions