//Create a class for valve package Valve import SmartThing.SmartThing public class Valve 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 currentValve = new StringBuilder() // Maps from features to values HashMap deviceValuesMap = new HashMap() Valve(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentValve) { deviceValuesMap = deviceValueSmartThing idSmartThing = id labelSmartThing = label displayNameSmartThing = displayName sendEventSmartThings = sendEvent // Initialization this.id = id this.label = label this.displayName = displayName this.currentValve = currentValve deviceValuesMap.put("valve", currentValve) } // Methods to set values def open() { action(currentValve, "open", "contact") } def open(LinkedHashMap metaData) { open() } def close() { action(currentValve, "closed", "contact") } def close(LinkedHashMap metaData) { close() } def action(StringBuilder variable, String newValue, String feature) { if (!variable.toString().equals(newValue)) { String tmpID = id.toString() variable.replace(0, variable.length(), newValue) println("$feature of the valve with id:$tmpID is $newValue!") sendEvent([name: feature, value: newValue, deviceId: tmpID, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } } // Methods to return values def getCurrentValve() { return currentValve.toString() } }