//Create a class for three axis package ThreeAxis public class ThreeAxis { // id, label, and display name of the device StringBuilder id = new StringBuilder() StringBuilder label = new StringBuilder() StringBuilder displayName = new StringBuilder() // Other variables def sendEvent LinkedHashMap currentThreeAxis ThreeAxis(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, LinkedHashMap currentThreeAxis) { // Initialization this.id = id this.label = label this.displayName = displayName this.currentThreeAxis = currentThreeAxis this.sendEvent = sendEvent } // Methods to set values def setValue(LinkedHashMap eventDataMap) { def tmpID = id.toString() currentThreeAxis = new groovy.json.JsonSlurper().parseText(eventDataMap["value"]) println("the three axis with id:$tmpID of cube is chagned to $currentThreeAxis!") sendEvent(eventDataMap) } // Methods to return values def getCurrentThreeAxis() { return currentThreeAxis } def currentState(String deviceFeature) { currentValue(deviceFeature) } def latestValue(String deviceFeature) { currentValue(deviceFeature) } def currentValue(String deviceFeature) { if (deviceFeature == "threeAxis" || deviceFeature == "status") return currentThreeAxis } }