Exemplo n.º 1
0
def set_sprinkler_on_duration(sprinkler_id, seconds):
    with db.session_scope() as session:
        sprinkler = db.get_sprinkler(session, sprinkler_id)
        _set_sprinkler_state(session, sprinkler, True)
        LOGGER.info("%s will go off in %d seconds", sprinkler, seconds)
        callback = functools.partial(_go_off, sprinkler.id)
        _call_later(callback, sprinkler.id, seconds)
Exemplo n.º 2
0
def get_history(sprinkler_id):
    with db.session_scope() as session:
        sprinkler = db.get_sprinkler(session, sprinkler_id)
        runs = db.get_runs(session, sprinkler.id)
        return [{
            'at'        : run.at.strftime(DATETIME_PATTERN),
            'duration'  : "{0} minutes".format(run.duration // 60),
        } for run in runs]
Exemplo n.º 3
0
def set_sprinkler_state(sprinkler_id, on):
    with db.session_scope() as session:
        sprinkler = db.get_sprinkler(session, sprinkler_id)
        _set_sprinkler_state(session, sprinkler, on)
Exemplo n.º 4
0
def _go_off(sprinkler_id):
    with db.session_scope() as session:
        sprinkler = db.get_sprinkler(session, sprinkler_id)
        LOGGER.debug("Setting %s off now", sprinkler)
        _set_sprinkler_state(session, sprinkler, False)