X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Event%2FEvent.groovy;h=d7abdf490dbb9658f191c955369e06536eecf2e1;hb=6d292c921178f1446efa72c7412a0efe3609fcf6;hp=816ea92a584c4c8870b3d9cf4543043ca27a456e;hpb=31da25f02c14814f402e84b35a174f3c0958cd38;p=smartthings-infrastructure.git diff --git a/Event/Event.groovy b/Event/Event.groovy index 816ea92..d7abdf4 100644 --- a/Event/Event.groovy +++ b/Event/Event.groovy @@ -1,5 +1,6 @@ //Create a class for Events package Event +import groovy.json.JsonSlurper public class Event { private String deviceId @@ -12,9 +13,11 @@ public class Event { private boolean isStateChange private String unit private String data + private jsonData private int integerValue - private List integerValues = ["battery", "hue", "saturation", "energy", "level", "temperature", - "heatingSetpoint", "coolingSetpoint", "thermostatSetpoint", "illuminance"] + private double doubleValue + private boolean physical + private def date Event(String value, String name, String deviceId, String descriptionText, boolean displayed, String linkText, String displayName, boolean isStateChange, String unit, String data) { this.deviceId = deviceId @@ -26,8 +29,16 @@ public class Event { this.isStateChange = isStateChange this.unit = unit this.data = data + this.jsonData = new groovy.json.JsonSlurper().parseText(data) this.displayed = displayed - if (integerValues.contains(name)) + if (["battery", "hue", "saturation", "energy", "level", "temperature", "heatingSetpoint", "coolingSetpoint", "thermostatSetpoint", "illuminance"].contains(name)) { + int dot = value.indexOf('.') + if (dot != -1) + value = value.substring(0, dot) this.integerValue = value.toInteger() + this.doubleValue = Double.parseDouble(value); + } + this.physical = true + this.date = new Date() } }