예제 #1
0
def get_location(request, response):
    """
    Get the location and timezone
    """
    location_data = data.get_location()
    gc.collect()
    yield from jsonify(response, location_data)
예제 #2
0
def get_door_config(request, response):
    """
    Return the door status
    """
    door_data = data.get_door_config() or {'duration': 0}
    gc.collect()
    yield from jsonify(response, door_data)
예제 #3
0
def force_door_close(request, response):
    """
    Close the door
    """
    close_door()
    gc.collect()
    yield from jsonify(response, {'status': data.get_door_status()})
예제 #4
0
def force_door_open(request, response):
    """
    Open the door
    """
    open_door()
    gc.collect()
    yield from jsonify(response, {'status': data.get_door_status()})
예제 #5
0
def get_door_status(request, response):
    """
    Return the door status
    """
    door_data = {'status': data.get_door_status() or '(unknown)'}
    gc.collect()
    yield from jsonify(response, door_data)
예제 #6
0
def get_network(request, response):
    """
    Return the WiFi config
    """
    network_config = data.get_network()
    network_config['ip_address'] = get_ip()
    gc.collect()
    yield from jsonify(response, network_config)
예제 #7
0
def save_door_status(request, response):
    """
    Save the door status
    """
    yield from request.read_form_data()
    if 'status' in request.form:
        data.save_door_status(request.form['status'])
    gc.collect()
    yield from jsonify(response, {'status': request.form['status']})
예제 #8
0
def save_door_config(request, response):
    """
    Save the door config or status
    """
    yield from request.read_form_data()
    updated_config = data.get_door_config()
    for key in ['duration']:
        if key in request.form:
            updated_config[key] = request.form[key]
    if updated_config:
        data.save_door_config(updated_config)
    gc.collect()
    yield from jsonify(response, updated_config)
예제 #9
0
def save_location(request, response):
    """
    Save the location and timezone
    """
    yield from request.read_form_data()
    updated_data = {
        'latitude': request.form['latitude'],
        'longitude': request.form['longitude'],
        'timezone': request.form['timezone']
    }
    data.save_location(**updated_data)
    gc.collect()
    yield from jsonify(response, request.form)
예제 #10
0
def save_network(request, response):
    """
    Save the network config
    """
    yield from request.read_form_data()
    updated_config = {}
    for key in ['essid', 'password', 'can_start_ap']:
        if key in request.form:
            updated_config[key] = request.form[key]
    data.save_network(**updated_config)
    gc.collect()
    # Now try to connect to the WiFi network
    connect()
    gc.collect()
    if 'can_start_ap' in updated_config:
        updated_config['can_start_ap'] = updated_config['can_start_ap'].lower(
        ) == 'true'
        if updated_config['can_start_ap'] is False:
            stop_ap()
        else:
            start_ap()
    updated_config['ip_address'] = get_ip()
    gc.collect()
    yield from jsonify(response, updated_config)