Skip to content

Instantly share code, notes, and snippets.

@LarsBergqvist
Created February 7, 2017 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LarsBergqvist/d219189cbebf98e0416985f927d9ef91 to your computer and use it in GitHub Desktop.
Save LarsBergqvist/d219189cbebf98e0416985f927d9ef91 to your computer and use it in GitHub Desktop.
Accept both json and raw data payloads for the state of the switch
@app.route("/Outlets/api/outlets/<int:groupNumber>/<int:buttonNumber>",methods=["PUT","POST"])
def update_outlet_state(groupNumber, buttonNumber):
state=None
if request.json is not None:
state=request.json.get("state")
else:
state=request.data
if (state is None):
abort(400)
if (state.lower() != 'on' and state.lower() != 'off'):
abort(400)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment