def init_data(): print "Init gateway data ..." for gw in DEFAULT_GATEWAYS: gateway.add_gateway(gw) print "Init user data ..." for usr in DEFAULT_USERS: user.add_user(usr) print "Init sensor type data ..." for st in SENSOR_TYPES: sensor_type.new({'type': st[1], 'mapping_class': st[0]}) print "Init sensor groups ..." for sg in SENSOR_GROUPS: for i in range(len(DEFAULT_GATEWAYS)): sensor_group.new({'gateway_id': i+1, 'name': sg[0], 'color': sg[1]}) print "Done."
def add_sensor_group(): """ update sensor group Http POST: { 'gateway_id': 1, 'color': '#fff', 'name': 'name', } """ content = request.get_json(silent=True) gateway_id = content.get('gateway_id') if not gateway_id or not content.get('color') or not content.get('name'): abort(400) if not isinstance(gateway_id, int): if not isinstance(gateway_id, str): abort(400) elif not gateway_id.isdigit(): abort(400) try: return jsonify(sensor_group.new(content)), 201 except: abort(500)