Removing getXXX methods + properties. Adding getProperty feature to SmartThing(s)
[smartthings-infrastructure.git] / Alarm / Alarm.groovy
index f03f5d6952897d43937bf20d6d0a2d42e4c2b4f1..a5cd6f0dca5a62fba267d0702297f6baaacd589c 100644 (file)
@@ -4,16 +4,14 @@ import SmartThing.SmartThing
 
 public class Alarm extends SmartThing {
        // id, label, and display name of the device
-       StringBuilder id = new StringBuilder()
-       StringBuilder label = new StringBuilder()
-       StringBuilder displayName = new StringBuilder()
-       // Features with string values
-       StringBuilder currentAlarm = new StringBuilder()
+       String id
+       String label
+       String displayName
        // Maps from features to values
-       HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+       HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
 
-       Alarm(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentAlarm) {
-               deviceValuesMap = deviceValueSmartThing
+       Alarm(Closure sendEvent, String id, String label, String displayName, String currentAlarm) {
+               deviceValueSmartThing = deviceValuesMap 
                idSmartThing = id
                labelSmartThing = label
                displayNameSmartThing = displayName
@@ -23,44 +21,28 @@ public class Alarm extends SmartThing {
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.currentAlarm = currentAlarm
 
                deviceValuesMap.put("alarm", currentAlarm)
        }
 
        // Methods to set values
        def both() {
-               action("both")
+               action("both", "alarm")
        }
 
        def on() {
-               action("both")
+               action("both", "alarm")
        }
 
        def off() {
-               action("off")
+               action("off", "alarm")
        }
 
        def siren() {
-               action("siren")
+               action("siren", "alarm")
        }
 
        def strobe() {
-               action("strobe")
-       }
-
-       def action(String newValue) {
-               if (!currentAlarm.equals(newValue)) {
-                       String tmpID = id.toString()
-                       currentAlarm.replace(0, currentAlarm.length(), newValue)
-                       println("the alarm with id:$tmpID is changed to $newValue!")
-                       sendEvent([name: "alarm", value: newValue, deviceId: tmpID, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-               }
-       }
-
-       // Methods to return values
-       def getCurrentAlarm() {
-               return currentAlarm.toString()
+               action("strobe", "alarm")
        }
 }