forked from adamclark-dev/smartthings-lightwave-node-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
onOffDevice.groovy
97 lines (79 loc) · 2.96 KB
/
onOffDevice.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* Lightwave Lights
*
* Copyright 2015 Adam Clark
* For any information or help please contact [email protected]
*
* 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.
*
*/
import java.security.MessageDigest
preferences {
input("serverIP", "text", title: "Server IP Address", description: "IP Address of the Server")
input("lightwaveIP", "text", title: "Lightwave IP Address", description: "IP Address of the Lightwave Hub")
input("roomID", "text", title: "Room ID", description: "The room id")
input("deviceID", "text", title: "Device ID", description: "The device id")
}
metadata {
definition (name: "Lightwave On Off Device", namespace: "smartthings-users", author: "Adam Clark") {
capability "Switch"
command "register"
}
simulator {}
tiles(scale: 2) {
multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
attributeState "on", label:'${name}', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState:"off"
attributeState "off", label:'${name}', action:"switch.on", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"On"
}
}
standardTile("register", "device.status", inactiveLabel:false, decoration:"flat",height: 2, width: 2) {
state "default", label:"Register", icon:"http://www.mocet.com/pic/link-icon.png", action:"register"
}
main "switch"
details(["switch", "register"])
}
}
// parse events into attributes
def parse(String description) {
log.debug "Parsing '${description}'"
// TODO: handle 'switch' attribute
}
// handle commands
def on() {
sendEvent(name: "switch", value: 'on')
apiGet('/on', 0)
}
def off() {
sendEvent(name: "switch", value: 'off')
apiGet('/off', 0)
}
def register() {
apiGet('/register', 0)
}
private apiGet(path, level) {
log.debug settings.serverIP + ':8000'
def httpRequest = [
method: 'GET',
path: path,
headers: [
HOST: settings.serverIP + ':8000',
Accept: "*/*"
],
query: [
ip: settings.lightwaveIP,
room: settings.roomID,
device: settings.deviceID,
level: level
]
]
log.debug httpRequest.query
return new physicalgraph.device.HubAction(httpRequest)
}