//Create a class for SmartThing package SmartThing //JPF's Verify API import gov.nasa.jpf.vm.Verify public class SmartThing { def sendEventSmartThings String idSmartThing String labelSmartThing String displayNameSmartThing HashMap deviceValueSmartThing = new HashMap() HashMap deviceIntValueSmartThing = new HashMap() List possibleValuesSmartThings = new ArrayList() // Method for handling events def setValue(LinkedHashMap eventDataMap) { def name = eventDataMap["name"] def tmpID = eventDataMap["deviceId"] def value = eventDataMap["value"] if (deviceValueSmartThing.containsKey(name)) { if (!value.equals(deviceValueSmartThing.get(name))) { deviceValueSmartThing.put(name, value) println("the $name of the $displayNameSmartThing with id:$tmpID is triggered to $value!") sendEventSmartThings(eventDataMap) } } else if (deviceIntValueSmartThing.containsKey(name)) { if (!value.equals(deviceIntValueSmartThing.get(name))) { deviceIntValueSmartThing.put(name, value) println("the $name of the $displayNameSmartThing with id:$tmpID is triggered to $value!") sendEventSmartThings(eventDataMap) } } else { println("the $name of the $displayNameSmartThing with id:$tmpID is triggered to $value!") sendEventSmartThings(eventDataMap) } } def statesSince() { eventsSince() } def eventsSince() { if (labelSmartThing.equals("humidity") || labelSmartThing.equals("temperature")) { sendCurrentValue() } else { sendPossibleValues() } } def sendCurrentValue() { def evtTemp = [[name: labelSmartThing, value: deviceIntValueSmartThing.get(labelSmartThing), deviceId: idSmartThing, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']] def init = Verify.getInt(0,1) def evtToSend = [] if (init == 0) {// return empty set return evtToSend } else if (init == 1) {// send one open event evtTemp.each{ evtToSend.add(it) } return evtToSend } } def sendPossibleValues() { def evtA = [[name: labelSmartThing, value: possibleValuesSmartThings[0], deviceId: idSmartThing, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']] def evtB = [[name: labelSmartThing, value: possibleValuesSmartThings[1], deviceId: idSmartThing, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']] def init = Verify.getInt(0,4) def evtToSend = [] if (init == 0) {// return empty set return evtToSend } else if (init == 1) {// send one event A evtA.each{ evtToSend.add(it) } return evtToSend } else if (init == 2) {// send two events A evtA.each{ evtToSend.add(it) } evtA.each{ evtToSend.add(it) } return evtToSend } else if (init == 3) {// send one event B evtB.each{ evtToSend.add(it) } return evtToSend } else if (init == 4) {// send two events B evtB.each{ evtToSend.add(it) } evtB.each{ evtToSend.add(it) } return evtToSend } } // Methods to set values def action(String newValue, String feature) { if (!deviceValueSmartThing.get(feature).equals(newValue)) { deviceValueSmartThing.put(feature, newValue) println("$feature of the $displayNameSmartThing with id:$idSmartThing is changed to $newValue!") sendEventSmartThings([name: feature, value: newValue, deviceId: idSmartThing, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } } def action(int newValue, String feature) { if (!deviceIntValueSmartThing.get(feature).equals(newValue)) { deviceIntValueSmartThing.put(feature, newValue) println("$feature of the $displayNameSmartThing with id:$idSmartThing is changed to $newValue!") sendEventSmartThings([name: feature, value: newValue, deviceId: idSmartThing, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } } // Methods to return values def propertyMissing(String currentProperty) { String property = currentProperty if (property.contains("current")) // Check to see if we have currentXXX or xxx property = property.substring(7,8).toLowerCase()+property.substring(8); if (deviceValueSmartThing.containsKey(property)) { return deviceValueSmartThing.get(property) } else if (deviceIntValueSmartThing.containsKey(property)) { return deviceIntValueSmartThing.get(property) } else { println("This capability does not support this property!") } } def currentState(String deviceFeature) { return [rawDateCreated: [time: System.currentTimeMillis()]] } def currentValue(String deviceFeature) { if (deviceValueSmartThing.containsKey(deviceFeature)) { return deviceValueSmartThing.get(deviceFeature) } else if (deviceIntValueSmartThing.containsKey(deviceFeature)) { return deviceIntValueSmartThing.get(deviceFeature) } else { println("Wrong device feature is sent to this method!") } } def latestValue(String deviceFeature) { currentValue(deviceFeature) } }