1 //Create a class for three axis
4 public class ThreeAxis {
5 // id, label, and display name of the device
6 StringBuilder id = new StringBuilder()
7 StringBuilder label = new StringBuilder()
8 StringBuilder displayName = new StringBuilder()
11 LinkedHashMap currentThreeAxis
14 ThreeAxis(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, LinkedHashMap currentThreeAxis) {
18 this.displayName = displayName
19 this.currentThreeAxis = currentThreeAxis
20 this.sendEvent = sendEvent
23 // Methods to set values
24 def setValue(LinkedHashMap eventDataMap) {
25 def tmpID = id.toString()
26 currentThreeAxis = new groovy.json.JsonSlurper().parseText(eventDataMap["value"])
27 println("the three axis with id:$tmpID of cube is chagned to $currentThreeAxis!")
28 sendEvent(eventDataMap)
31 // Methods to return values
32 def getCurrentThreeAxis() {
33 return currentThreeAxis
36 def currentState(String deviceFeature) {
37 currentValue(deviceFeature)
40 def latestValue(String deviceFeature) {
41 currentValue(deviceFeature)
44 def currentValue(String deviceFeature) {
45 if (deviceFeature == "threeAxis" || deviceFeature == "status")
46 return currentThreeAxis