From: Seyed Amir Hossein Aqajari Date: Sat, 1 Feb 2020 01:20:16 +0000 (-0800) Subject: Infrastructure compatible with swiches X-Git-Url: http://plrg.eecs.uci.edu/git/?p=smartthings-infrastructure.git;a=commitdiff_plain;h=13eaa2aa4abc92483f370cd74f1d79b4caafed55;hp=a3f4618b470eb84dec709f3ea98104365543c6cb Infrastructure compatible with swiches --- diff --git a/Event/Event.groovy b/Event/Event.groovy index aac847b..83ba658 100644 --- a/Event/Event.groovy +++ b/Event/Event.groovy @@ -4,7 +4,7 @@ import groovy.json.JsonSlurper public class Event { private String deviceId - private Object value + private String value private String linkText private String displayName private boolean displayed @@ -19,7 +19,7 @@ public class Event { private boolean physical private def date - Event(Object value, String name, String deviceId, String descriptionText, boolean displayed, String linkText, String displayName, boolean isStateChange, String unit, String data) { + Event(String value, String name, String deviceId, String descriptionText, boolean displayed, String linkText, String displayName, boolean isStateChange, String unit, String data) { this.deviceId = deviceId this.linkText = linkText this.value = value @@ -32,8 +32,11 @@ public class Event { this.jsonData = new groovy.json.JsonSlurper().parseText(data) this.displayed = displayed if (["battery", "hue", "saturation", "energy", "level", "temperature", "heatingSetpoint", "coolingSetpoint", "thermostatSetpoint", "illuminance"].contains(name)) { - this.integerValue = value - this.doubleValue = value + 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() diff --git a/SmartThing/SmartThing.groovy b/SmartThing/SmartThing.groovy index b869773..ec4907a 100644 --- a/SmartThing/SmartThing.groovy +++ b/SmartThing/SmartThing.groovy @@ -26,8 +26,8 @@ public class SmartThing { sendEventSmartThings(eventDataMap) } } else if (deviceIntValueSmartThing.containsKey(name)) { - if (!value.equals(deviceIntValueSmartThing.get(name))) { - deviceIntValueSmartThing.put(name, value) + if (!value.toInteger().equals(deviceIntValueSmartThing.get(name))) { + deviceIntValueSmartThing.put(name, value.toInteger()) println("the $name of the $displayNameSmartThing with id:$tmpID is triggered to $value!") sendEventSmartThings(eventDataMap) } @@ -50,7 +50,7 @@ public class SmartThing { } def sendCurrentValue() { - def evtTemp = [[name: labelSmartThing, value: deviceIntValueSmartThing.get(labelSmartThing), deviceId: idSmartThing, descriptionText: "", + def evtTemp = [[name: labelSmartThing, value: deviceIntValueSmartThing.get(labelSmartThing).toString(), deviceId: idSmartThing, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']] def init = Verify.getInt(0,1) def evtToSend = [] @@ -116,7 +116,7 @@ public class SmartThing { 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: "", + sendEventSmartThings([name: feature, value: newValue.toString(), deviceId: idSmartThing, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } } diff --git a/SmartThing/SmartThings.groovy b/SmartThing/SmartThings.groovy index 469c3c0..f2cc9e7 100644 --- a/SmartThing/SmartThings.groovy +++ b/SmartThing/SmartThings.groovy @@ -30,6 +30,10 @@ public class SmartThings { } // Methods to handle events + def eventsSince(Date dateObj, LinkedHashMap info) { + return smartThings[0].eventsSince() + } + def eventsSince(Date dateObj) { return smartThings[0].eventsSince() }