コード例 #1
0
def cycle_themes(lifx: Group,
                 *themes: ColorTheme,
                 rotate_secs: Optional[int] = 60,
                 duration_mins: Optional[int] = 20,
                 transition_secs=5,
                 all_lights=True):
    """
    set lights to theme every `rotate_secs`.

    will round robin `themes`.
    rotation still works on one theme as it will re-assign the theme each `rotate_secs`
    """
    end_time = arrow.utcnow().shift(minutes=duration_mins or 100000)

    themes = [colors_to_theme(t) for t in themes]
    with lifx.reset_to_orig():
        for t in cycle(themes):
            if arrow.utcnow() > end_time:
                return
            lifx.set_theme(t,
                           power_on=all_lights,
                           duration=transition_secs * 1000)
            if rotate_secs:
                sleep(rotate_secs)
            else:
                sleep(duration_mins * 60 or 10000)
コード例 #2
0
def breathe(lifx: Group,
            breath_time_secs=8,
            min_brightness_pct=30,
            max_brightness_pct=60,
            colors: Optional[ColorTheme] = None,
            duration_mins: Optional[Union[int, float]] = 20):
    """whatever lights you pass in will breathe"""
    theme = colors_to_theme(colors)
    half_period_ms = int(breath_time_secs * 1000.0)
    sleep_time = breath_time_secs
    duration_secs = duration_mins * 60 or float('inf')

    min_brightness = min_brightness_pct / 100.0 * 65535
    max_brightness = max_brightness_pct / 100.0 * 65535

    with lifx.reset_to_orig(half_period_ms):
        lifx.set_brightness(max_brightness, duration=2000)
        if theme:
            lifx.set_theme(theme)
        print("Breathing...")
        try:
            start_time = time()
            while True:
                with lifx.reset_to_orig(half_period_ms):
                    lifx.set_brightness(min_brightness, half_period_ms)
                    sleep(sleep_time)
                sleep(sleep_time)
                if time() - start_time > duration_secs:
                    raise KeyboardInterrupt
        except KeyboardInterrupt:
            print("Restoring original color and power to all lights...")