Infrastructure compatible with swiches
authorSeyed Amir Hossein Aqajari <saqajari@circinus-17.ics.uci.edu>
Sat, 1 Feb 2020 01:20:16 +0000 (17:20 -0800)
committerSeyed Amir Hossein Aqajari <saqajari@circinus-17.ics.uci.edu>
Sat, 1 Feb 2020 01:20:16 +0000 (17:20 -0800)
Event/Event.groovy
SmartThing/SmartThing.groovy
SmartThing/SmartThings.groovy

index aac847b5ccd32d51d30b8581d35e418059f4403f..83ba658355e5d838fa72c10b92f1c184b57bba5b 100644 (file)
@@ -4,7 +4,7 @@ import groovy.json.JsonSlurper
 
 public class Event {
        private String deviceId
 
 public class Event {
        private String deviceId
-       private Object value
+       private String value
        private String linkText
        private String displayName
        private boolean displayed
        private String linkText
        private String displayName
        private boolean displayed
@@ -19,7 +19,7 @@ public class Event {
        private boolean physical
        private def date
        
        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
                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.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()
                }
                this.physical = true
                this.date = new Date()
index b869773031db6367270e65edbc88d3291137f6a9..ec4907a79e9a795f86fb81d8853dfb83ccba950e 100644 (file)
@@ -26,8 +26,8 @@ public class SmartThing {
                                 sendEventSmartThings(eventDataMap)
                         }
                 } else if (deviceIntValueSmartThing.containsKey(name)) {
                                 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)
                         }
                                 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 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 = []
                                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!")
                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"}'])
                }
        }
                                              displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
index 469c3c007f130edcf8ed444f37977d96914fb496..f2cc9e70a7e7010ffe8330be86bd3ce6f14c3862 100644 (file)
@@ -30,6 +30,10 @@ public class SmartThings {
        }
 
        // Methods to handle events
        }
 
        // Methods to handle events
+       def eventsSince(Date dateObj, LinkedHashMap info) {
+               return smartThings[0].eventsSince()
+       }
+
        def eventsSince(Date dateObj) {
                return smartThings[0].eventsSince()
        }
        def eventsSince(Date dateObj) {
                return smartThings[0].eventsSince()
        }