Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure
[smartthings-infrastructure.git] / Alarm / Alarm.groovy
1 //Create a class for alarm device
2 package Alarm
3 import Timer.SimulatedTimer
4
5 public class Alarm {
6         private String id
7         private String label
8         private String displayName
9         private String alarm
10         private String currentAlarm
11         private String alarmLatestValue
12         def sendEvent   
13         def timers
14         
15
16         Alarm(Closure sendEvent, String id, String label, String displayName, String alarm, String currentAlarm, String alarmLatestValue) {
17                 this.sendEvent = sendEvent
18                 this.timers = new SimulatedTimer()
19                 this.id = id
20                 this.label = label
21                 this.displayName = displayName
22                 this.alarm = alarm
23                 this.currentAlarm = currentAlarm
24                 this.alarmLatestValue = alarmLatestValue
25         }
26
27         //By Apps
28         def both() {
29                 println("the alarm with id:$id is changed to both!")
30                 this.alarmLatestValue = this.alarm
31                 this.alarm = "both"
32                 this.currentAlarm = "both"
33                 sendEvent([name: "alarm", value: "both", deviceId: this.id, descriptionText: "",
34                     displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "both"]])
35         }
36
37         def on() {
38                 both()
39         }
40
41         def off() {
42                 println("the alarm with id:$id is changed to off!")
43                 this.alarmLatestValue = this.alarm
44                 this.alarm = "off"
45                 this.currentAlarm = "off"
46                 sendEvent([name: "alarm", value: "off", deviceId: this.id, descriptionText: "",
47                     displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "off"]])
48         }
49
50         def siren() {
51                 println("the alarm with id:$id is changed to siren!")
52                 this.alarmLatestValue = this.alarm
53                 this.alarm = "siren"
54                 this.currentAlarm = "siren"
55                 sendEvent([name: "alarm", value: "siren", deviceId: this.id, descriptionText: "",
56                     displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "siren"]])
57         }
58
59         def strobe() {
60                 println("the alarm with id:$id is changed to strobe!")
61                 this.alarmLatestValue = this.alarm
62                 this.alarm = "strobe"
63                 this.currentAlarm = "strobe"
64                 sendEvent([name: "alarm", value: "strobe", deviceId: this.id, descriptionText: "",
65                     displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "strobe"]])
66         }
67
68         def currentValue(String deviceFeature) {
69                 if (deviceFeature == "alarm") {
70                         return currentAlarm
71                 }
72         }
73
74         def latestValue(String deviceFeature) {
75                 if (deviceFeature == "alarm") {
76                         return alarmLatestValue
77                 }
78         }
79 }