コード例 #1
0
    def _execute_stage(self, index, stage, stop):
        """ Execute a pipeline stage.

        :param index: Stage index.
        :param stage: Stage object.
        """
        if stop.is_set():
            _LOGGER.info("Stopped pipeline on group %s", self._group)
            return
        _LOGGER.info(" -> Running stage '%s' on group %s", stage, self._group)
        if stage.name == 'on':
            self._group.on = True
        elif stage.name == 'off':
            self._group.on = False
        elif stage.name == 'color':
            self._group.color = Color(*stage.args)
        elif stage.name == 'brightness':
            self._group.brightness = stage.args[0]
        elif stage.name == 'temperature':
            self._group.temperature = stage.args[0]
        elif stage.name == 'transition':
            self._group.transition(*stage.args, **stage.kwargs)
        elif stage.name == 'white':
            self._group.white()
        elif stage.name == 'flash':
            self._group.flash(**stage.kwargs)
        elif stage.name == 'repeat':
            self._repeat(index, stage, stop)
        elif stage.name == 'wait':
            time.sleep(*stage.args)
        elif stage.name == 'callback':
            stage.args[0](*stage.args[1:], **stage.kwargs)
コード例 #2
0
ファイル: util.py プロジェクト: smonkbr/python-limitlessled
def to_rgb(hue, saturation):
    """
    Converts hue and saturation to RGB color.
    :param hue: The hue of the color.
    :param saturation: The saturation of the color.
    :return: The RGB color tuple.
    """
    return Color(*hsv_to_rgb(hue, saturation, 1))
コード例 #3
0
    def _transition(self, duration, color, brightness):
        """ Transition.

        :param duration: Time to transition.
        :param color: Transition to this color.
        :param brightness: Transition to this brightness.
        """
        # Calculate brightness steps.
        b_steps = 0
        if brightness is not None:
            b_steps = steps(self.brightness, brightness, BRIGHTNESS_STEPS)
            b_start = self.brightness
        # Calculate color steps.
        c_steps = 0
        if color is not None:
            c_steps = abs(
                util.rgb_to_hue(*self.color) - util.rgb_to_hue(*color))
            c_start = rgb_to_hsv(*self._color)
            c_end = rgb_to_hsv(*color)
        # Compute ideal step amount (at least one).
        total = max(c_steps + b_steps, 1)
        # Calculate wait.
        wait = self._wait(duration, total)
        # Scale down steps if no wait time.
        if wait == 0:
            total = self._scaled_steps(duration, total, total)
        # Perform transition.
        j = 0
        for i in range(total):
            # Brightness.
            if (b_steps > 0 and i % math.ceil(total / b_steps) == 0):
                j += 1
                self.brightness = util.transition(j, b_steps, b_start,
                                                  brightness)
            # Color.
            elif c_steps > 0:
                rgb = hsv_to_rgb(*util.transition3(i - j + 1, total -
                                                   b_steps, c_start, c_end))
                self.color = Color(*rgb)
            # Wait.
            time.sleep(wait)
コード例 #4
0
 def limitlessled_color(self):
     """Convert Home Assistant HS list to RGB Color tuple."""
     from limitlessled import Color
     return Color(*color_hs_to_RGB(*tuple(self._color)))
コード例 #5
0
ファイル: light.py プロジェクト: Claret-Srl/core
    def limitlessled_color(self):
        """Convert Safegate Pro HS list to RGB Color tuple."""

        return Color(*color_hs_to_RGB(*tuple(self._color)))
コード例 #6
0
def _from_hass_color(color):
    """Convert Home Assistant RGB list to Color tuple."""
    from limitlessled import Color
    return Color(*tuple(color))
コード例 #7
0
ファイル: rgb.py プロジェクト: dapfa/python-limitlessled
""" RGB LimitlessLED group. """

import math
import time

from limitlessled import Color, util
from limitlessled.group import Group, rate
from limitlessled.util import steps, hue_of_color, saturation_of_color

RGB = 'rgb'
BRIDGE_LED = 'bridge-led'
RGB_WHITE = Color(255, 255, 255)


class RgbGroup(Group):
    """ RGB LimitlessLED group. """
    def __init__(self, bridge, number, name, led_type=RGB):
        """ Initialize RGB group.

        :param bridge: Associated bridge.
        :param number: Group number (1-4).
        :param name: Group name.
        :param led_type: The type of the led. (RGB or BRIDGE_LED)
        """
        super().__init__(bridge, number, name, led_type)
        self._hue = 0
        self._color = RGB_WHITE

    @property
    def color(self):
        """ Color property.
コード例 #8
0
 def limitlessled_color(self):
     """Convert Home Assistant RGB list to Color tuple."""
     from limitlessled import Color
     return Color(*tuple(self._color))
コード例 #9
0
ファイル: light.py プロジェクト: OpenPeerPower/core
    def limitlessled_color(self):
        """Convert Open Peer Power HS list to RGB Color tuple."""

        return Color(*color_hs_to_RGB(*tuple(self._color)))
コード例 #10
0
 def test_saturation_of_color(self):
     red = Color(255, 0, 0)
     self.assertEqual(util.saturation_of_color(red), 1.0)
コード例 #11
0
 def test_hue_of_color(self):
     red = Color(255, 0, 0)
     self.assertEqual(util.hue_of_color(red), 0.0)
コード例 #12
0
 def test_to_rgb(self):
     red = Color(255, 0, 0)
コード例 #13
0
ファイル: light.py プロジェクト: jbouwh/core
 def limitlessled_color(self) -> Color:
     """Convert Home Assistant HS list to RGB Color tuple."""
     assert self.hs_color is not None
     return Color(*color_hs_to_RGB(*self.hs_color))
コード例 #14
0
""" Various preset pipelines. """

from limitlessled import Color
from limitlessled.pipeline import Pipeline

# Alarm (flash red).
ALARM = Pipeline() \
    .on() \
    .color(255, 0, 0) \
    .flash() \
    .repeat()

# Color loop (R->G->B).
COLORLOOP = Pipeline() \
    .on() \
    .transition(10, color=Color(255, 0, 0)) \
    .transition(10, color=Color(0, 255, 0)) \
    .transition(10, color=Color(0, 0, 255)) \
    .repeat(stages=3)