mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-21 13:10:51 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ca31ced7df |
@@ -1,5 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2015 SmartThings
|
* 정창환
|
||||||
|
*
|
||||||
|
* Copyright 2016 정창환
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
* 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:
|
* in compliance with the License. You may obtain a copy of the License at:
|
||||||
@@ -10,120 +12,39 @@
|
|||||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
* 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.
|
* for the specific language governing permissions and limitations under the License.
|
||||||
*
|
*
|
||||||
* Alfred Workflow
|
|
||||||
*
|
|
||||||
* Author: SmartThings
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
definition(
|
definition(
|
||||||
name: "윤정은",
|
name: "정창환",
|
||||||
namespace: "윤정은",
|
namespace: "정창환",
|
||||||
author: "SmartThings",
|
author: "정창환",
|
||||||
description: "This SmartApp allows you to interact with the things in your physical graph through Alfred.",
|
description: "\u3139\u3139\u3139",
|
||||||
category: "Convenience",
|
category: "Green Living",
|
||||||
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/alfred-app.png",
|
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
|
||||||
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/alfred-app@2x.png",
|
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
|
||||||
oauth: [displayName: "SmartThings Alfred Workflow", displayLink: ""]
|
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
|
||||||
)
|
|
||||||
|
|
||||||
preferences {
|
preferences {
|
||||||
section("Allow Alfred to Control These Things...") {
|
section("Title") {
|
||||||
input "switches", "capability.switch", title: "Which Switches?", multiple: true, required: false
|
// TODO: put inputs here
|
||||||
input "locks", "capability.lock", title: "Which Locks?", multiple: true, required: false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mappings {
|
def installed() {
|
||||||
path("/switches") {
|
log.debug "Installed with settings: ${settings}"
|
||||||
action: [
|
|
||||||
GET: "listSwitches",
|
initialize()
|
||||||
PUT: "updateSwitches"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
path("/switches/:id") {
|
|
||||||
action: [
|
|
||||||
GET: "showSwitch",
|
|
||||||
PUT: "updateSwitch"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
path("/locks") {
|
|
||||||
action: [
|
|
||||||
GET: "listLocks",
|
|
||||||
PUT: "updateLocks"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
path("/locks/:id") {
|
|
||||||
action: [
|
|
||||||
GET: "showLock",
|
|
||||||
PUT: "updateLock"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def installed() {}
|
def updated() {
|
||||||
|
log.debug "Updated with settings: ${settings}"
|
||||||
|
|
||||||
def updated() {}
|
unsubscribe()
|
||||||
|
initialize()
|
||||||
def listSwitches() {
|
|
||||||
switches.collect { device(it,"switch") }
|
|
||||||
}
|
|
||||||
void updateSwitches() {
|
|
||||||
updateAll(switches)
|
|
||||||
}
|
|
||||||
def showSwitch() {
|
|
||||||
show(switches, "switch")
|
|
||||||
}
|
|
||||||
void updateSwitch() {
|
|
||||||
update(switches)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def listLocks() {
|
def initialize() {
|
||||||
locks.collect { device(it, "lock") }
|
// TODO: subscribe to attributes, devices, locations, etc.
|
||||||
}
|
|
||||||
void updateLocks() {
|
|
||||||
updateAll(locks)
|
|
||||||
}
|
|
||||||
def showLock() {
|
|
||||||
show(locks, "lock")
|
|
||||||
}
|
|
||||||
void updateLock() {
|
|
||||||
update(locks)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateAll(devices) {
|
// TODO: implement event handlers
|
||||||
def command = request.JSON?.command
|
|
||||||
if (command) {
|
|
||||||
devices."$command"()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void update(devices) {
|
|
||||||
log.debug "update, request: ${request.JSON}, params: ${params}, devices: $devices.id"
|
|
||||||
def command = request.JSON?.command
|
|
||||||
if (command) {
|
|
||||||
def device = devices.find { it.id == params.id }
|
|
||||||
if (!device) {
|
|
||||||
httpError(404, "Device not found")
|
|
||||||
} else {
|
|
||||||
device."$command"()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private show(devices, name) {
|
|
||||||
def device = devices.find { it.id == params.id }
|
|
||||||
if (!device) {
|
|
||||||
httpError(404, "Device not found")
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
def s = device.currentState(name)
|
|
||||||
[id: device.id, label: device.displayName, name: device.displayName, state: s]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private device(it, name) {
|
|
||||||
if (it) {
|
|
||||||
def s = it.currentState(name)
|
|
||||||
[id: it.id, label: it.displayName, name: it.displayName, state: s]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user