Ejemplo n.º 1
0
def party():
    global party_process
    json = flask.request.get_json()
    enabled = json.get("enabled", False)
    logger.info("Got party state %r" % enabled)
    if enabled and not env.is_party_mode():
        # Start party XD
        party_process = Popen(["python3", "./animate_web.py", "run"])  # async
        env.set_party_mode(True)
    elif not enabled and env.is_party_mode():
        # Stop party :(
        env.set_party_mode(False)
        if party_process is not None:
            party_process.kill()
            party_process = None

        # Return lights to circadian color
        command = copy.deepcopy(COMMAND_FULL_ON)
        circadian_color = get_current_circadian_color(date=get_local_time())
        command_all_lights(circadian_color.apply_to_command(command))
    return "Party mode is now %r" % enabled
Ejemplo n.º 2
0
import time

from support.color import get_next_circadian_color
from support.hue import command_all_lights, hue
from support.logger import get_logger
from support.room import LightsOnDuringDayRoom
from support.time_utils import get_local_time
from settings import ROOMS

# Logging
logger = get_logger("circadian")

while 1:
    now = get_local_time()
    next_color_date, next_color = get_next_circadian_color(date=now)

    sleep_time_s = (next_color_date - now).seconds
    logger.info("Sleeping until %s at %s", next_color.name, next_color_date.strftime('%Y/%m/%d %I:%M:%S %p'))
    time.sleep(sleep_time_s + 30)  # Add padding to compensate for sleep inaccuracy
    logger.info("Adjusting hue for %s", next_color.name)
    command = next_color.apply_to_command({'transitiontime': 60 * 10})  # 60 s transition

    if next_color.name == 'Day':
        lights = []
        for room in ROOMS:
            if not isinstance(room, LightsOnDuringDayRoom):
                lights += room.lights
        hue.set_light(lights, command)
    else:
        command_all_lights(command)