Last active
November 4, 2016 14:54
-
-
Save LarsBergqvist/a3413e241764e272a9c4823bc3ec0696 to your computer and use it in GitHub Desktop.
REST api for remote controlled outlets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, jsonify, request, render_template, abort | |
from outletdefinitions import outlets | |
import codesender | |
app = Flask(__name__) | |
@app.route("/Outlets/api/outlets", methods=["GET"]) | |
def get_outlets(): | |
return jsonify({"outlets" : outlets}) | |
@app.route("/Outlets/",methods=["GET"]) | |
def index(): | |
return render_template("index.html") | |
@app.route("/Outlets/api/outlets/<int:groupNumber>/<int:buttonNumber>",methods=["PUT"]) | |
def clickButton(groupNumber, buttonNumber): | |
state=request.json.get("state") | |
if (state is None): | |
abort(400) | |
if (state.lower() != 'on' and state.lower() != 'off'): | |
abort(400) | |
codesender.sendCode(groupNumber,buttonNumber,state) | |
return state | |
if __name__ == "__main__": | |
app.debug = True | |
app.run(host="0.0.0.0",port=5000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment