Update sunrise-sunset.groovy
[smartapps.git] / third-party / VirtualButton.groovy
1 /**
2  *  Virtual Button
3  *
4  *  Copyright 2015 obycode
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7  *  in compliance with the License. You may obtain a copy of the License at:
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
12  *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
13  *  for the specific language governing permissions and limitations under the License.
14  *
15  */
16 metadata {
17         definition (name: "Virtual Button", namespace: "com.obycode", author: "obycode") {
18                 capability "Button"
19                 capability "Sensor"
20
21                 command "push"
22                 command "hold"
23                 command "release"
24         }
25
26         simulator {
27                 // TODO: define status and reply messages here
28         }
29
30         tiles {
31                 standardTile("button", "device.button", canChangeIcon: true, inactiveLabel: false, width: 2, height: 2) {
32                         state "default", label: '', icon: "st.secondary.off", action: "push"
33                         state "pressed", label: 'Pressed', icon: "st.illuminance.illuminance.dark", backgroundColor: "#66ccff", action: "release"
34                         state "held", label: 'Held', icon: "st.illuminance.illuminance.light", backgroundColor: "#0066ff", action: "release"
35                 }
36
37                 main "button"
38                 details(["button"])
39         }
40 }
41
42 // parse events into attributes
43 def parse(String description) {
44         log.debug "Parsing '${description}'"
45         if (description == "updated") {
46         sendEvent(name: "button", value: "released")
47     }
48 }
49
50 // handle commands
51 def push() {
52         log.debug "Executing 'push'"
53     sendEvent(name: "button", value: "pushed", /*data: [buttonNumber: button], descriptionText: "$device.displayName button $button was pressed",*/ isStateChange: true)
54 }
55
56 def hold() {
57         log.debug "Executing 'hold'"
58         sendEvent(name: "button", value: "held", /*data: [buttonNumber: button], descriptionText: "$device.displayName button $button was held",*/ isStateChange: true)
59 }
60
61 def release() {
62         log.debug "Executing 'release'"
63         sendEvent(name: "button", value: "default", /*data: [buttonNumber: button], descriptionText: "$device.displayName button $button was held",*/ isStateChange: true)
64 }