示例#1
0
def delete_alarm(id):
    alarm = model.Alarm.query.filter(model.Alarm.id == id).first()
    if alarm is None:
        flask.abort(404)
    model.db.session.delete(alarm)
    model.db.session.commit()
    comm.send_message(app, comm.ReloadAlarmsMessage())
    return '', 204
示例#2
0
def add_alarm():
    alarm = model.Alarm()
    alarm.update_from_dict(flask.request.json)
    alarm.schedule_next_alarm()
    model.db.session.add(alarm)
    model.db.session.commit()
    comm.send_message(app, comm.ReloadAlarmsMessage())
    return flask.jsonify(alarm.to_dict())
示例#3
0
def update_alarm(id):
    alarm = model.Alarm.query.filter(model.Alarm.id == id).first()
    if alarm is None:
        flask.abort(404)
    alarm.update_from_dict(flask.request.json)
    alarm.schedule_next_alarm()
    model.db.session.add(alarm)
    model.db.session.commit()
    comm.send_message(app, comm.ReloadAlarmsMessage())
    return flask.jsonify(alarm.to_dict())
示例#4
0
def shutdown(signum, frame):
    comm.send_message(app, comm.StopMessage())
示例#5
0
def patch_light():
    state = comm.get_state(app)
    new_light_on = bool(flask.request.json.get('on'))
    if new_light_on != state.light_on:
        comm.send_message(app, comm.SetLightStateMessage(on=new_light_on))
    return flask.jsonify({'on': new_light_on})