//JPF's Verify API
import gov.nasa.jpf.vm.Verify
-//Importing mutable integer class
-import MutableInteger.MutableInteger
-
-public class SmartThing {
- List nonStoredDevices = ["aeonKeyFob", "appTouch", "button", "momentary", "nfcTouch"] // Devices with no stored value
- List locationTimeFeatures = ["sunset", "sunrise", "sunriseTime", "sunsetTime"]
+public class SmartThing {
def sendEventSmartThings
-
- StringBuilder idSmartThing = new StringBuilder()
- StringBuilder labelSmartThing = new StringBuilder()
- StringBuilder displayNameSmartThing = new StringBuilder()
- HashMap<String, StringBuilder> deviceValueSmartThing = new HashMap<String, StringBuilder>()
- HashMap<String, MutableInteger> deviceIntValueSmartThing = new HashMap<String, MutableInteger>()
- List<StringBuilder> possibleValuesSmartThings = new ArrayList<StringBuilder>();
+ String idSmartThing
+ String labelSmartThing
+ String displayNameSmartThing
+ HashMap<String, String> deviceValueSmartThing = new HashMap<String, String>()
+ HashMap<String, Integer> deviceIntValueSmartThing = new HashMap<String, Integer>()
+ List<String> possibleValuesSmartThings = new ArrayList<String>()
// Method for handling events
- def setValue(LinkedHashMap eventDataMap) {
- def name = eventDataMap["name"]
- def tmpID = eventDataMap["deviceId"]
- def value = eventDataMap["value"]
+ def setValue(LinkedHashMap eventDataMap) {
+ def name = eventDataMap["name"]
+ def tmpID = eventDataMap["deviceId"]
+ def value = eventDataMap["value"]
- if (deviceValueSmartThing.containsKey(name)) {
- StringBuilder tmpStr = deviceValueSmartThing.get(name)
- if (!value.equals(tmpStr.toString())) {
- tmpStr.replace(0, tmpStr.length(), value)
- println("the $name with id:$tmpID is triggered to $value!")
- sendEventSmartThings(eventDataMap)
- }
- } else if (deviceIntValueSmartThing.containsKey(name)) {
- MutableInteger tmpInt = deviceIntValueSmartThing.get(name)
- if (!value.equals(tmpInt.getValue())) {
- tmpInt.setValue(value)
- println("the $name with id:$tmpID is triggered to $value!")
- sendEventSmartThings(eventDataMap)
- }
- } else if (nonStoredDevices.contains(name)) {
- println("the $name with id:$tmpID is triggered to $value!")
- sendEventSmartThings(eventDataMap)
- } else if (locationTimeFeatures.contains(name)) {
- return System.currentTimeMillis()
- println("This is $name!")
- sendEventSmartThings(eventDataMap)
- }
- }
+ 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.toString().equals("humidity") || labelSmartThing.toString().equals("temperature")) {
+ if (labelSmartThing.equals("humidity") || labelSmartThing.equals("temperature")) {
sendCurrentValue()
} else {
sendPossibleValues()
}
def sendCurrentValue() {
- def label = labelSmartThing.toString()
- def evtTemp = [[name: label, value: deviceIntValueSmartThing.get(label).getValue(), deviceId: idSmartThing.toString(), descriptionText: "",
+ 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 = []
}
def sendPossibleValues() {
- def evtA = [[name: labelSmartThing.toString(), value: possibleValuesSmartThings[0].toString(), deviceId: idSmartThing.toString(), descriptionText: "",
+ def evtA = [[name: labelSmartThing, value: possibleValuesSmartThings[0], deviceId: idSmartThing, descriptionText: "",
displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
- def evtB = [[name: labelSmartThing.toString(), value: possibleValuesSmartThings[1].toString(), deviceId: idSmartThing.toString(), descriptionText: "",
+ 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 = []
}
}
+ // 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 getProperty(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 latestValue(String deviceFeature) {
currentValue(deviceFeature)
}
-
- def getId() {
- return idSmartThing.toString()
- }
-
- def getLabel() {
- return labelSmartThing.toString()
- }
-
- def getDisplayName() {
- return displayNameSmartThing.toString()
- }
}