mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-08 05:31:56 +00:00
Compare commits
1 Commits
PROD_2017.
...
MSA-1799-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8b38c1073 |
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* Web Services SmartApp
|
||||
*
|
||||
* Copyright 2017 Light Engine R&D
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing permissions and limitations under the License.
|
||||
*
|
||||
*/
|
||||
definition(
|
||||
name: "Web Services SmartApp",
|
||||
namespace: "lightenginernd",
|
||||
author: "Light Engine R&D",
|
||||
description: "Web Services SmartApp 1st",
|
||||
category: "",
|
||||
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: [displayName: "Web Services SmartApp", displayLink: "http://localhost:4567"]
|
||||
)
|
||||
|
||||
preferences {
|
||||
section ("Allow external service to control these things...") {
|
||||
input "switches", "capability.switch", multiple: true, required: true
|
||||
}
|
||||
}
|
||||
|
||||
mappings {
|
||||
path("/switches") {
|
||||
action: [
|
||||
GET: "listSwitches"
|
||||
]
|
||||
}
|
||||
path("/switches/:command") {
|
||||
action: [
|
||||
PUT: "updateSwitches"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
// returns a list like
|
||||
// [[name: "kitchen lamp", value: "off"], [name: "bathroom", value: "on"]]
|
||||
def listSwitches() {
|
||||
|
||||
def resp = []
|
||||
switches.each {
|
||||
resp << [name: it.displayName, value: it.currentValue("switch")]
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
void updateSwitches() {
|
||||
// use the built-in request object to get the command parameter
|
||||
def command = params.command
|
||||
|
||||
// all switches have the comand
|
||||
// execute the command on all switches
|
||||
// (note we can do this on the array - the command will be invoked on every element
|
||||
switch(command) {
|
||||
case "on":
|
||||
switches.on()
|
||||
break
|
||||
case "off":
|
||||
switches.off()
|
||||
break
|
||||
default:
|
||||
httpError(400, "$command is not a valid command for all switches specified")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
def installed() {
|
||||
log.debug "Installed with settings: ${settings}"
|
||||
|
||||
initialize()
|
||||
}
|
||||
|
||||
def updated() {
|
||||
log.debug "Updated with settings: ${settings}"
|
||||
|
||||
unsubscribe()
|
||||
initialize()
|
||||
}
|
||||
|
||||
def initialize() {
|
||||
// TODO: subscribe to attributes, devices, locations, etc.
|
||||
}
|
||||
|
||||
// TODO: implement event handlers
|
||||
Reference in New Issue
Block a user