Changeset - 411cab5fae51
[Not reviewed]
default
0 2 0
Dennis Fink - 9 years ago 2016-10-25 19:39:18
dennis.fink@c3l.lu
Use pass_active_status
2 files changed with 6 insertions and 10 deletions:
0 comments (0 inline, 0 general)
spaceapi/sensors.py
Show inline comments
 
@@ -8,7 +8,7 @@ import jsonschema
 
from flask import Blueprint, jsonify, request, abort, current_app
 

	
 
from .auth import httpauth
 
from .utils import first, fuzzy_list_find, ActiveStatus
 
from .utils import first, fuzzy_list_find, pass_active_status
 

	
 
sensors_views = Blueprint('sensors', __name__)
 

	
 
@@ -38,7 +38,6 @@ def set_value(data, key):
 
    except ValueError:
 
        active['sensors'][key].append(data)
 

	
 
    active.save_last_state()
 
    return jsonify(active)
 

	
 

	
 
@@ -68,15 +67,13 @@ def set_radiation_value(data):
 
        except ValueError:
 
            active['sensors']['radiaton'][first_subkey].append(data)
 

	
 
    active.save_last_state()
 
    return jsonify(active)
 

	
 

	
 
@sensors_views.route('/set/<key>', methods=['POST'])
 
@httpauth.login_required
 
def set_sensors(key):
 

	
 
    active = ActiveStatus()
 
@pass_active_status
 
def set_sensors(active, key):
 

	
 
    if key in ALLOWED_SENSORS_KEYS and key in active['sensors']:
 
        data = request.data.decode('utf-8')
spaceapi/state.py
Show inline comments
 
@@ -4,7 +4,7 @@ from time import time
 

	
 
from flask import Blueprint, jsonify, request, current_app, abort
 

	
 
from .utils import ActiveStatus
 
from .utils import pass_active_status
 
from .auth import httpauth
 

	
 
state_views = Blueprint('state', __name__)
 
@@ -12,11 +12,10 @@ state_views = Blueprint('state', __name_
 

	
 
@state_views.route('/set/<key>', methods=['POST'])
 
@httpauth.login_required
 
def set_state(key):
 
    active = ActiveStatus()
 
@pass_active_status
 
def set_state(active, key):
 
    value = json.loads(request.data.decode('utf-8'))['value']
 
    current_app.logger.info(value)
 
    current_app.logger.info(type(value))
 
    active.set_new_state(**{key: value})
 
    active.save_last_state()
 
    return jsonify(active)
0 comments (0 inline, 0 general)