Fixing bug in Mobile Presence class
[smartthings-infrastructure.git] / ThreeAxis / ThreeAxis.groovy
1 //Create a class for three axis
2 package ThreeAxis
3
4 public class ThreeAxis {
5         // id, label, and display name of the device
6         String id
7         String label
8         String displayName
9         // Other variables
10         def sendEvent
11         LinkedHashMap currentThreeAxis
12         
13
14         ThreeAxis(Closure sendEvent, String id, String label, String displayName, LinkedHashMap currentThreeAxis) {
15                 // Initialization
16                 this.id = id
17                 this.label = label
18                 this.displayName = displayName
19                 this.currentThreeAxis = currentThreeAxis
20                 this.sendEvent = sendEvent
21         }
22
23         // Methods to set values
24         def setValue(LinkedHashMap eventDataMap) {
25                 currentThreeAxis = new groovy.json.JsonSlurper().parseText(eventDataMap["value"])
26                 println("the three axis with id:$id of cube is chagned to $currentThreeAxis!")
27                 sendEvent(eventDataMap)
28         }
29
30         // Methods to return values
31         def getCurrentThreeAxis() {
32                 return currentThreeAxis
33         }
34
35         def currentState(String deviceFeature) {
36                 currentValue(deviceFeature)
37         }
38
39         def latestValue(String deviceFeature) {
40                 currentValue(deviceFeature)
41         }
42
43         def currentValue(String deviceFeature) {
44                 if (deviceFeature == "threeAxis" || deviceFeature == "status")
45                         return currentThreeAxis
46         }
47 }