-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqVS Device Handler
116 lines (94 loc) · 3.6 KB
/
sqVS 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
/**
* sqVS
*
* Copyright 2014 Mike Maxwell
* Orginal update by Lee Charlton to handle volume control and refresh status.
*
* 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.
*
*/
metadata {
definition (name: "sqVS", namespace: "LeeC77", author: "Lee Charlton") {
capability "Switch"
capability "Refresh"
command "PlayerResp", ["string"]
command "refresh"
command "volumeUp", ["string"]
command "volumeDown", ["string"]
}
// Don't think this is currently working enum needs defining.
// preferences {
// input name: "sq", type: "enum", title: "squeezeBox", description: "Squeeze Box to Connect to", required: true
//}
simulator {
// TODO: define status and reply messages here
}
tiles (scale: 2){
standardTile("switch", "device.switch", width: 5, height: 3, canChangeBackground: true) {
state "on", label: '${name}', action: "switch.off", icon: "st.Electronics.electronics10", backgroundColor: "#79b821"
state "off", label: '${name}', action: "switch.on", icon: "st.Electronics.electronics10", backgroundColor: "#ffffff"
// to handle the change of state.
state "turningOn", label:'Turning on', action: "switch.off", icon:"st.Electronics.electronics10", backgroundColor:"#00a0dc"
state "turningOff", label:'Turning off', action: "switch.on", icon:"st.Electronics.electronics10", backgroundColor:"#ffffff"
}
}
standardTile("volumeUp", "device.volume", inactiveLabel: false, decoration: "flat") {
state "up", action:"volumeUp", icon:"st.thermostat.thermostat-up"
}
standardTile("volumeDown", "device.volume", inactiveLabel: false, decoration: "flat") {
state "down", action:"volumeDown", icon:"st.thermostat.thermostat-down"
}
standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
}
main "switch"
details(["switch","volumeUp","volumeDown", "refresh"])
}
// parse events into attributes
def parse(String description) {
log.debug "Parsing '${description}'"
// TODO: handle 'switch' attribute
}
// handle commands
def on() {
log.debug "On"
sendEvent (name: "switch", value: "turningOn")
}
def off() {
// Always on //
log.debug "Off"
sendEvent (name: "switch", value: "turningOff")
}
def refresh() {
log.debug "Refresh"
sendEvent (name: "refresh", value: "refresh")
sendEvent (name: "refresh", value: "done")
}
def volumeUp() {
log.debug "Volume up"
sendEvent (name: "volume", value: "up")
sendEvent (name: "volume", value: "done")
}
def volumeDown() {
log.debug "Volume down"
sendEvent (name: "volume", value: "down")
sendEvent (name: "volume", value: "done")
}
def PlayerResp (response){
log.debug "Response is:${response}"
if (response.indexOf("play")>=0){
log.debug " switched on"
sendEvent (name: "switch", value: "on")
}
else if (response.indexOf("power 0")>=0){
log.debug " switched off"
sendEvent (name: "switch", value: "off")
}
}