-
Notifications
You must be signed in to change notification settings - Fork 10
/
device handler
123 lines (96 loc) · 3.31 KB
/
device handler
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
metadata {
definition (name: "WLED", namespace: "Damien", author: "Damien") {
capability "Switch"
capability "Switch Level"
capability "Light"
capability "Color Control"
command "on"
command "off"
command "setColor"
command "setLevel"
attribute "color", "String"
attribute "level", "Number"
}
simulator {
}
tiles (scale: 2) {
// void controlTile(String tileName, String attributeName, String controlType [, Map options, Closure closure])
standardTile("switch", "device.switch", width: 3, height: 2, canChangeIcon: true) {
state "on", label:'${name}', action:"off", icon:"st.switches.light.on", backgroundColor:"#00a0dc"
state "off", label:'${name}', action:"on", icon:"st.switches.light.off", backgroundColor:"#ffffff"
}
//BRIGHTNESS
controlTile("level", "level", "slider", width: 3, height: 2, inactiveLabel: false,range:"(0..255)" ) {
state "level", action:"setLevel", label: "Level"
}
//COLOR
controlTile("rgbSelector", "color", "color", width: 6, height: 6, inactiveLabel: false) {
state "color", action:"setColor"
}
main "switch"
details([
"switch","levelLabel", "level","rgbSelector"
])
}
preferences {
input name: "internal_ip", type: "text", title: "Internal IP", required: true
input name: "internal_port", type: "text", title: "Internal Port", defaultValue: 80, required: true
}
}
/*
=============================================
ON/OFF
=============================================
*/
def off() {
sendEvent(name: "switch", value: "off", isStateChange: true)
//log.debug("Turn OFF")
return sendGetRequest("/win&T=0")
}
def on() {
sendEvent(name: "switch", value: "on", isStateChange: true)
//log.debug("Turn ON, Color:${state.SavedColor}, Brightness: ${state.SavedLevel}, Color2: ${state.SavedColor2}")
return sendGetRequest("/win&T=1&FX=0" )
}
/*
=============================================
BRIGHTNESS LEVEL
=============================================
*/
def setLevel(Integer value,rate=0) {
state.SavedLevel = value
sendEvent(name: "switch", value: "on", isStateChange: true)
sendEvent(name: "level", value: state.SavedLevel, isStateChange: true)
//log.debug("Turn ON, Color:${state.SavedColor}, Brightness: ${state.SavedLevel}, Color2: ${state.SavedColor2}")
return sendGetRequest("/win&A=${value}")
}
/*
=============================================
COLOR
=============================================
*/
def setColor(value) {
state.SavedColor = value
//log.debug("Turn ON, Color:${state.SavedColor}, Brightness: ${state.SavedLevel}, Color2: ${state.SavedColor2}")
//sendEvent(name: "switch", value: "on", isStateChange: true)
//log.debug("Set Color:${value}")
def h = (value.hue)*65535/100
def s = (value.saturation)*255/100
return sendGetRequest("/win&HU=${h}&SA=${s}")
}
/*
=============================================
HTTP SEND
=============================================
*/
private sendGetRequest(String url) {
log.debug("${internal_ip}:${internal_port}${url}")
def result = new physicalgraph.device.HubAction(
method: "GET",
path: "${url}",
headers: [
HOST: "${internal_ip}:${internal_port}"
]
)
//return result;
}