1 //Create a class for alarm device
3 import SmartThing.SmartThing
5 public class Alarm extends SmartThing {
6 // id, label, and display name of the device
7 StringBuilder id = new StringBuilder()
8 StringBuilder label = new StringBuilder()
9 StringBuilder displayName = new StringBuilder()
10 // Features with string values
11 StringBuilder currentAlarm = new StringBuilder()
12 // Maps from features to values
13 HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
15 Alarm(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentAlarm) {
16 deviceValuesMap = deviceValueSmartThing
18 labelSmartThing = label
19 displayNameSmartThing = displayName
20 sendEventSmartThings = sendEvent
25 this.displayName = displayName
26 this.currentAlarm = currentAlarm
28 deviceValuesMap.put("alarm", currentAlarm)
31 // Methods to set values
52 def action(String newValue) {
53 if (!currentAlarm.equals(newValue)) {
54 String tmpID = id.toString()
55 currentAlarm.replace(0, currentAlarm.length(), newValue)
56 println("the alarm with id:$tmpID is changed to $newValue!")
57 sendEvent([name: "alarm", value: newValue, deviceId: tmpID, descriptionText: "",
58 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
62 // Methods to return values
63 def getCurrentAlarm() {
64 return currentAlarm.toString()