Created
August 7, 2018 22:34
-
-
Save leoforney/10d387168f83bd213710dcea99d739c5 to your computer and use it in GitHub Desktop.
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
/** | |
* Raspberry Pi Doors | |
* | |
* Copyright 2016 Leo Foney | |
* | |
*/ | |
definition( | |
name: "Raspberry Pi Doors", | |
namespace: "leoforney", | |
author: "Leo Forney", | |
description: "Update the door contacts from http put requests from raspberry pi", | |
category: "Convenience", | |
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png", | |
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png", | |
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png", | |
oauth: true, | |
singleInstance: true) | |
preferences { | |
page(name: "pageMain") | |
} | |
def pageMain() { | |
dynamicPage(name: "pageMain", title: none, uninstall: true, install: true){ | |
section ("Front Door") { | |
input "FrontDoor", "capability.doorControl", required: false | |
} | |
section ("Patio Door") { | |
input "PatioDoor", "capability.doorControl", required: false | |
} | |
section ("Garage Door") { | |
input "GarageDoor", "capability.doorControl", required: false | |
} | |
section ("Front Left Door") { | |
input "FrontLeftDoor", "capability.doorControl", required: false | |
} | |
section ("Front Right Door") { | |
input "FrontRightDoor", "capability.doorControl", required: false | |
} | |
} | |
} | |
def pageRPISettings(){ | |
dynamicPage(name: "pageRPISettings", title: none, uninstall: false){ | |
section { paragraph "Settings" } | |
section ("Other Values/Variables"){ | |
if (!state.accessToken) OAuthToken() | |
if (!state.accessToken) paragraph "**You must enable OAuth via the IDE to setup this app**" | |
else href url:"${getApiServerUrl()}/api/smartapps/installations/${app.id}/setup?access_token=${state.accessToken}", style:"embedded", required:false, title:"HTTP Requests", description: none | |
} | |
section ("Advanced") { | |
href "pageConfirmation", title: "Revoke/Reset Access Token", description: "Tap to confirm this action", | |
image: "" | |
} | |
} | |
} | |
mappings { | |
path("/setup") { action: [GET: "displayData"] } | |
path("/doors/FrontDoor/:command") { | |
action: [ | |
PUT: "frontDoorUpdate" | |
] | |
} | |
path("/doors/PatioDoor/:command") { | |
action: [ | |
PUT: "patioDoorUpdate" | |
] | |
} | |
path("/doors/GarageDoor/:command") { | |
action: [ | |
PUT: "garageDoorUpdate" | |
] | |
} | |
path("/doors/FrontLeftDoor/:command") { | |
action: [ | |
PUT: "frontLeftDoorUpdate" | |
] | |
} | |
path("/doors/FrontRightDoor/:command") { | |
action: [ | |
PUT: "frontRightDoorUpdate" | |
] | |
} | |
} | |
def installed() { | |
log.info "Installed with settings: ${settings}" | |
initialize() | |
} | |
def updated() { | |
log.info "Updated with settings: ${settings}" | |
unsubscribe() | |
initialize() | |
} | |
def initialize() { | |
// TODO: subscribe to attributes, devices, locations, etc. | |
} | |
void frontDoorUpdate() { | |
switch(params.command) { | |
case "open": | |
FrontDoor.open() | |
log.info "open command called!" | |
break | |
case "close": | |
FrontDoor.close() | |
log.info "closed command called!" | |
break | |
default: | |
httpError(400, "$command is not a valid command for all switches specified") | |
} | |
} | |
void patioDoorUpdate() { | |
switch(params.command) { | |
case "open": | |
PatioDoor.open() | |
log.info "open command called!" | |
break | |
case "close": | |
PatioDoor.close() | |
log.info "closed command called!" | |
break | |
default: | |
httpError(400, "$command is not a valid command for all switches specified") | |
} | |
} | |
void garageDoorUpdate() { | |
switch(params.command) { | |
case "open": | |
GarageDoor.open() | |
log.info "open command called!" | |
break | |
case "close": | |
GarageDoor.close() | |
log.info "closed command called!" | |
break | |
default: | |
httpError(400, "$command is not a valid command for all switches specified") | |
} | |
} | |
void frontLeftDoorUpdate() { | |
switch(params.command) { | |
case "open": | |
FrontLeftDoor.open() | |
log.info "open command called!" | |
break | |
case "close": | |
FrontLeftDoor.close() | |
log.info "closed command called!" | |
break | |
default: | |
httpError(400, "$command is not a valid command for all switches specified") | |
} | |
} | |
void frontRightDoorUpdate() { | |
switch(params.command) { | |
case "open": | |
FrontRightDoor.open() | |
log.info "open command called!" | |
break | |
case "close": | |
FrontRightDoor.close() | |
log.info "closed command called!" | |
break | |
default: | |
httpError(400, "$command is not a valid command for all switches specified") | |
} | |
} | |
def setupData(){ | |
log.info "Set up web page located at : ${getApiServerUrl()}/api/smartapps/installations/${app.id}/setup?access_token=${state.accessToken}" | |
def result = """ | |
<b> Use PUT as http reqeust type!</b> </br> | |
""" | |
} | |
def displayData(){ | |
render contentType: "text/html", data: """<!DOCTYPE html><html><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/></head><body style="margin: 0;">${setupData()}</body></html>""" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment