def _transition_stage(self, step, total_steps, brightness=None, color=None): """ Get a transition stage at a specific step. :param step: The current step. :param total_steps: The total number of steps. :param brightness: The brightness to transition to (0.0-1.0). :param color: The color to transition to. :return: The stage at the specific step. """ if brightness is not None: self._assert_is_brightness(brightness) brightness = self._interpolate(self.brightness, brightness, step, total_steps) if color is not None: self._assert_is_color(color) color = Color(*[ self._interpolate(self.color[i], color[i], step, total_steps) for i in range(3) ]) return {'brightness': brightness, 'color': color}
def __init__(self, driver): """ Initialize the led. :param driver: The driver that is used to control the led. """ super().__init__(driver) self._color = Color(255, 255, 255)
def step(self): """Apply the current stage of the transition based on current time.""" if self.cancelled or self.finished: return if self.progress == 1: self._finish() return state = {} src_is_on = self._src_state.get('is_on') dest_is_on = self._dest_state.get('is_on') if dest_is_on: state['is_on'] = True src_brightness = self._src_state.get('brightness') dest_brightness = self._dest_state.get('brightness') if src_is_on is False: if dest_brightness is None: dest_brightness = src_brightness src_brightness = 0 if dest_is_on is False: dest_brightness = 0 if src_brightness is not None and dest_brightness is not None: state['brightness'] = self._interpolate( src_brightness, dest_brightness, ) src_color = self._src_state.get('color') dest_color = self._dest_state.get('color') if src_is_on is False: src_color = dest_color if src_color is not None and dest_color is not None: state['color'] = Color( *(self._interpolate(src_color[i], dest_color[i]) for i in range(3))) self._led.set(**state, cancel_transition=False)
def _from_hass_color(color): """Convert Home Assistant RGB list to Color tuple.""" rgb = color_util.color_hs_to_RGB(*color) return Color(*tuple(rgb))
def _from_hass_color(color): """Convert Safegate Pro RGB list to Color tuple.""" rgb = color_util.color_hs_to_RGB(*color) return Color(*tuple(rgb))
def _from_hass_color(color): """Convert Home Assistant RGB list to Color tuple.""" from pwmled import Color return Color(*tuple(color))