def color(self, color): """ Set group color. Color is set on a best-effort basis. :param color: RGB color tuple. """ self._color = color self.saturation = saturation_of_color(color) if self.saturation != 0: self.hue = hue_of_color(color)
def color(self, color): """ Set group color. Color is set on a best-effort basis. :param color: RGB color tuple. """ if saturation_of_color(color) == 0: self.white() return self._color = color self.hue = hue_of_color(color)
def transition(self, duration, color=None, brightness=None, temperature=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. :param temperature: Transition to this temperature. """ if color and temperature is not None: raise ValueError("Cannot transition to color and temperature " "simultaneously.") # Transition to white immediately. if color == RGB_WHITE: self.white() # Transition away from white immediately. elif self.color == RGB_WHITE and color is not None: self.color = color # Transition immediately if duration is zero. if duration == 0: if color: self.color = color if brightness is not None: self.brightness = brightness if temperature is not None: self.temperature = temperature return # Perform transition if color and color != self.color: self._transition(duration, brightness, hue=hue_of_color(color), saturation=saturation_of_color(color)) elif temperature != self.temperature: self._transition(duration, brightness, temperature=temperature) elif brightness != self.brightness: self._transition(duration, brightness)
def test_saturation_of_color(self): red = Color(255, 0, 0) self.assertEqual(util.saturation_of_color(red), 1.0)