Removing getXXX methods + properties. Adding getProperty feature to SmartThing(s)
[smartthings-infrastructure.git] / ThreeAxis / ThreeAxis.groovy
index 3e5e817f62c5a478c38b9b3d42f96d4b1404fe03..dbd8eb95dea84a0077a585c962a6842fb666c84a 100644 (file)
@@ -1,40 +1,47 @@
 //Create a class for three axis
 package ThreeAxis
-import Timer.SimulatedTimer
-import groovy.json.JsonSlurper
-
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
 
 public class ThreeAxis {
-       private String id
-       private String label
-       private String displayName
-       private LinkedHashMap threeAxis
+       // id, label, and display name of the device
+       String id
+       String label
+       String displayName
+       // Other variables
+       def sendEvent
+       LinkedHashMap currentThreeAxis
+       
 
-       ThreeAxis(String id, String label, String displayName, LinkedHashMap threeAxis) {
+       ThreeAxis(Closure sendEvent, String id, String label, String displayName, LinkedHashMap currentThreeAxis) {
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.threeAxis = threeAxis
+               this.currentThreeAxis = currentThreeAxis
+               this.sendEvent = sendEvent
        }
 
+       // Methods to set values
        def setValue(LinkedHashMap eventDataMap) {
-               threeAxis = new groovy.json.JsonSlurper().parseText(eventDataMap["value"])
-               println("the three axis of cube is chagned to $threeAxis!")
+               currentThreeAxis = new groovy.json.JsonSlurper().parseText(eventDataMap["value"])
+               println("the three axis with id:$id of cube is chagned to $currentThreeAxis!")
+               sendEvent(eventDataMap)
+       }
+
+       // Methods to return values
+       def getCurrentThreeAxis() {
+               return currentThreeAxis
        }
 
        def currentState(String deviceFeature) {
                currentValue(deviceFeature)
        }
 
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "threeAxis" || deviceFeature == "status")
-                       return threeAxis
+       def latestValue(String deviceFeature) {
+               currentValue(deviceFeature)
        }
 
-       def latestValue(String deviceFeature) {
+       def currentValue(String deviceFeature) {
                if (deviceFeature == "threeAxis" || deviceFeature == "status")
-                       return threeAxis
+                       return currentThreeAxis
        }
 }