def enqueue(self, pipeline): """ Start a pipeline. :param pipeline: Start this pipeline. """ copied = Pipeline().append(pipeline) copied.group = self self._queue.put(copied)
def wrapper(self, **kwargs): """Wrap a group state change.""" from limitlessled.pipeline import Pipeline pipeline = Pipeline() transition_time = DEFAULT_TRANSITION # Stop any repeating pipeline. if self.repeating: self.repeating = False self.group.stop() # Not on and should be? Turn on. if not self.is_on and new_state is True: pipeline.on() # Set transition time. if ATTR_TRANSITION in kwargs: transition_time = kwargs[ATTR_TRANSITION] # Do group type-specific work. function(self, transition_time, pipeline, **kwargs) # Update state. self._is_on = new_state self.group.enqueue(pipeline) self.update_ha_state()
def wrapper(self, **kwargs): """Wrap a group state change.""" from limitlessled.pipeline import Pipeline pipeline = Pipeline() transition_time = DEFAULT_TRANSITION if self._effect == EFFECT_COLORLOOP: self.group.stop() self._effect = None # Set transition time. if ATTR_TRANSITION in kwargs: transition_time = int(kwargs[ATTR_TRANSITION]) # Do group type-specific work. function(self, transition_time, pipeline, **kwargs) # Update state. self._is_on = new_state self.group.enqueue(pipeline) self.schedule_update_ha_state()
def wrapper(self: LimitlessLEDGroup, **kwargs: Any) -> None: """Wrap a group state change.""" # pylint: disable=protected-access pipeline = Pipeline() transition_time = DEFAULT_TRANSITION if self.effect == EFFECT_COLORLOOP: self.group.stop() self._attr_effect = None # Set transition time. if ATTR_TRANSITION in kwargs: transition_time = int(kwargs[ATTR_TRANSITION]) # Do group type-specific work. function(self, transition_time, pipeline, **kwargs) # Update state. self._attr_is_on = new_state self.group.enqueue(pipeline) self.schedule_update_ha_state()
import limitlessled import time import logging terminate = False def my_function(): global terminate terminate = True pass logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger() logger.info("Setup group") bridge = Bridge('192.168.178.232') gartenhaus = bridge.add_group(1, 'gartenhaus', RGB) pipeline = Pipeline().wait(10).on().wait(4).off() pipeline.callback(my_function) gartenhaus.enqueue(pipeline) logger.info("Switch on group %s", gartenhaus) while terminate == False: time.sleep(1)
def turn_on(self, transition_time: int, pipeline: Pipeline, **kwargs: Any) -> None: """Turn on (or adjust property of) a group.""" # The night effect does not need a turned on light if kwargs.get(ATTR_EFFECT) == EFFECT_NIGHT: if self.effect_list and EFFECT_NIGHT in self.effect_list: pipeline.night_light() self._attr_effect = EFFECT_NIGHT return pipeline.on() # Set up transition. args = {} if self.config[CONF_FADE] and not self.is_on and self.brightness: args["brightness"] = self.limitlessled_brightness() if ATTR_BRIGHTNESS in kwargs: self._attr_brightness = kwargs[ATTR_BRIGHTNESS] args["brightness"] = self.limitlessled_brightness() if ATTR_HS_COLOR in kwargs: self._attr_hs_color = kwargs[ATTR_HS_COLOR] # White is a special case. assert self.hs_color is not None if self.hs_color[1] < MIN_SATURATION: pipeline.white() self._attr_hs_color = WHITE else: args["color"] = self.limitlessled_color() if ATTR_COLOR_TEMP in kwargs: assert self.supported_color_modes if ColorMode.HS in self.supported_color_modes: pipeline.white() self._attr_hs_color = WHITE self._attr_color_temp = kwargs[ATTR_COLOR_TEMP] args["temperature"] = self.limitlessled_temperature() if args: pipeline.transition(transition_time, **args) # Flash. if ATTR_FLASH in kwargs and self.supported_features & LightEntityFeature.FLASH: duration = 0 if kwargs[ATTR_FLASH] == FLASH_LONG: duration = 1 pipeline.flash(duration=duration) # Add effects. if ATTR_EFFECT in kwargs and self.effect_list: if kwargs[ATTR_EFFECT] == EFFECT_COLORLOOP: self._attr_effect = EFFECT_COLORLOOP pipeline.append(COLORLOOP) if kwargs[ATTR_EFFECT] == EFFECT_WHITE: pipeline.white() self._attr_hs_color = WHITE
def turn_off(self, transition_time: int, pipeline: Pipeline, **kwargs: Any) -> None: """Turn off a group.""" if self.config[CONF_FADE]: pipeline.transition(transition_time, brightness=0.0) pipeline.off()
""" 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)