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
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())
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())
def shutdown(signum, frame): comm.send_message(app, comm.StopMessage())
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})