Пример #1
0
def get_sprinklers():
    with db.session_scope() as session:
        sprinklers = db.get_sprinklers(session)
        data = [{
            'id'    : sprinkler.id,
            'name'  : sprinkler.name,
            'port'  : sprinkler.port,
            'pin'   : sprinkler.pin,
            'description'   : sprinkler.description
        } for sprinkler in sprinklers]
    return data
Пример #2
0
def get_status():
    with db.session_scope() as session:
        sprinklers = db.get_sprinklers(session)
        states = ubw.get_status()
        statuses = {}
        for sprinkler in sprinklers:
            status = {
                'state'     : 'on' if states[sprinkler.port][sprinkler.pin] else 'off',
                'last_ran'  : _get_last_ran(session, sprinkler.id)
            }
            statuses[sprinkler.name] = status
    return statuses