<commit_before>""" RGBW 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


RGBW = 'rgbw'
BRIDGE_LED = 'bridge-led'
RGB_WHITE = Color(255, 255, 255)


class RgbwGroup(Group):
    """ RGBW LimitlessLED group. """

    def __init__(self, bridge, number, name, led_type=RGBW):
        """ Initialize RGBW group.

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

    @property
    def color(self):
        """ Color property.

        :returns: Color.
        """
        return self._color

    @color.setter
    def color(self, color):
        """ Set group color.

        Color is set on a best-effort basis.

        :param color: RGB color tuple.
        """
        if color == RGB_WHITE:
            self.white()
            return
        self._color = color
        self.hue = hue_of_color(color)

    def white(self):
        """ Set color to white. """
        self._color = RGB_WHITE
        cmd = self.command_set.white()
        self.send(cmd)

    @property
    def brightness(self):
        """ Brightness property.

        :returns: Brightness.
        """
        return self._brightness

    @brightness.setter
    def brightness(self, brightness):
        """ Set the group brightness.

        :param brightness: Brightness in decimal percent (0.0-1.0).
        """
        if brightness < 0 or brightness > 1:
            raise ValueError("Brightness must be a percentage "
                             "represented as decimal 0-1.0")
        self._brightness = brightness
        cmd = self.command_set.brightness(brightness)
        self.send(cmd)

    @property
    def hue(self):
        """ Hue property.

        :returns: Hue.
        """
        return self._hue

    @hue.setter
    def hue(self, hue):
        """ Set the group hue.

        :param hue: Hue in decimal percent (0.0-1.0).
        """
        if hue < 0 or hue > 1:
            raise ValueError("Hue must be a percentage "
                             "represented as decimal 0-1.0")
        self._hue = hue
        cmd = self.command_set.hue(hue)
        self.send(cmd)

    def transition(self, duration, color=None, brightness=None):
        """ Transition wrapper.

        Short-circuit transition as necessary.

        :param duration: Time to transition.
        :param color: Transition to this color.
        :param brightness: Transition to this brightness.
        """
        # Transition to white immediately.
        if color == RGB_WHITE:
            self.white()
            color = None
        # Transition away from white immediately.
        elif self.color == RGB_WHITE and color is not None:
            self.color = color
            color = None
        # Transition immediately if duration is zero.
        if duration == 0:
            if color:
                self.color = color
            if brightness is not None:
                self.brightness = brightness
            return
        # Perform transition
        if color != self.color or brightness != self.brightness:
            if color is None and brightness == self.brightness:
                return
            self._transition(duration, hue_of_color(color), brightness)

    @rate(wait=0.025, reps=1)
    def _transition(self, duration, hue, brightness):
        """ Transition.

        :param duration: Time to transition.<commit_msg>Do not try to convert None color to hue.<commit_after>""" RGBW 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


RGBW = 'rgbw'
BRIDGE_LED = 'bridge-led'
RGB_WHITE = Color(255, 255, 255)


class RgbwGroup(Group):
    """ RGBW LimitlessLED group. """

    def __init__(self, bridge, number, name, led_type=RGBW):
        """ Initialize RGBW group.

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

    @property
    def color(self):
        """ Color property.

        :returns: Color.
        """
        return self._color

    @color.setter
    def color(self, color):
        """ Set group color.

        Color is set on a best-effort basis.

        :param color: RGB color tuple.
        """
        if color == RGB_WHITE:
            self.white()
            return
        self._color = color
        self.hue = hue_of_color(color)

    def white(self):
        """ Set color to white. """
        self._color = RGB_WHITE
        cmd = self.command_set.white()
        self.send(cmd)

    @property
    def brightness(self):
        """ Brightness property.

        :returns: Brightness.
        """
        return self._brightness

    @brightness.setter
    def brightness(self, brightness):
        """ Set the group brightness.

        :param brightness: Brightness in decimal percent (0.0-1.0).
        """
        if brightness < 0 or brightness > 1:
            raise ValueError("Brightness must be a percentage "
                             "represented as decimal 0-1.0")
        self._brightness = brightness
        cmd = self.command_set.brightness(brightness)
        self.send(cmd)

    @property
    def hue(self):
        """ Hue property.

        :returns: Hue.
        """
        return self._hue

    @hue.setter
    def hue(self, hue):
        """ Set the group hue.

        :param hue: Hue in decimal percent (0.0-1.0).
        """
        if hue < 0 or hue > 1:
            raise ValueError("Hue must be a percentage "
                             "represented as decimal 0-1.0")
        self._hue = hue
        cmd = self.command_set.hue(hue)
        self.send(cmd)

    def transition(self, duration, color=None, brightness=None):
        """ Transition wrapper.

        Short-circuit transition as necessary.

        :param duration: Time to transition.
        :param color: Transition to this color.
        :param brightness: Transition to this brightness.
        """
        # Transition to white immediately.
        if color == RGB_WHITE:
            self.white()
            color = None
        # Transition away from white immediately.
        elif self.color == RGB_WHITE and color is not None:
            self.color = color
            color = None
        # Transition immediately if duration is zero.
        if duration == 0:
            if color:
                self.color = color
            if brightness is not None:
                self.brightness = brightness
            return
        # Perform transition
        if color != self.color or brightness != self.brightness:
            if color is None and brightness == self.brightness:
                return
            if color is None:
                self._transition(duration, brightness=brightness)
            else:
                self._transition(duration, hue_of_color(color), brightness)

    @rate(wait=0.025, reps=1)
    def _transition(self, duration, hue=None, brightness=None):
        """ Transition.

        :param duration: Time to transition.
{'fraction_non_alphanumeric': 0.09466051417270929, 'fraction_numerical': 0.00949241924851681, 'mean_word_length': 1.815887156644395, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2820615', 'n_tokens_mistral': 2243, 'n_tokens_neox': 2029, 'n_words': 658}