Fixing some bugs
authoramiraj <amiraj.95@uci.edu>
Tue, 6 Aug 2019 23:13:54 +0000 (16:13 -0700)
committeramiraj <amiraj.95@uci.edu>
Tue, 6 Aug 2019 23:13:54 +0000 (16:13 -0700)
Event/Event.groovy
Methods/timeToday.groovy
MotionSensor/MotionSensor.groovy
MotionSensor/MotionSensors.groovy
RelativeHumidityMeasurement/RelativeHumidityMeasurement.groovy
RelativeHumidityMeasurement/RelativeHumidityMeasurements.groovy
Switch/Switch.groovy
Switch/Switches.groovy
ThreeAxis/ThreeAxis.groovy
ThreeAxis/ThreeAxises.groovy
Variables and events for each device

index eecbc7bda63fbbbee31a5e79751601f08e328cb0..7e834345ac2da8b4b09f47427e99c6f8e806cf4f 100644 (file)
@@ -18,6 +18,8 @@ public class Event {
        private double doubleValue
        private List integerValues = ["battery", "hue", "saturation", "energy", "level", "temperature", 
                                      "heatingSetpoint", "coolingSetpoint", "thermostatSetpoint", "illuminance"]
+       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
@@ -35,5 +37,7 @@ public class Event {
                        this.integerValue = value.toInteger()
                        this.doubleValue = Double.parseDouble(value);           
                }
+               this.physical = true
+               this.date = new Date()
        }
 }
index 0d905b582f29df12c395d22e0a75427f64602c52..07894decb1c270c5d013168e4329702768c2fc51 100644 (file)
@@ -14,3 +14,12 @@ def timeToday(String time) {
        timeOfDay.time = inputTime
        return timeOfDay
 }
+
+
+def timeTodayAfter(Date date, String time, Object timeZone) {
+       def timeOfDay = new Date()
+       def _inputTime = time.split(':')
+       def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60+1564191100415
+       timeOfDay.time = inputTime
+       return timeOfDay
+}
index 79fbf9b5b018b71054fe72ac8de51005fd005b7d..01f1363256190d9c5411bcfc4da8b475c974a588 100644 (file)
@@ -9,8 +9,6 @@ public class MotionSensor {
        private String motion
        private String currentMotion
        private String motionLatestValue
-       private List states = []
-       private List timeOfStates = []
 
        MotionSensor(String id, String label, String displayName, String motion, String motionLatestValue) {
                this.id = id
@@ -26,18 +24,48 @@ public class MotionSensor {
                this.motionLatestValue = value
                this.motion = value
                this.currentMotion = value
-               this.states.add(value)
-               this.timeOfStates.add(System.currentTimeMillis())
        }
 
-       def statesSince(String info, Date dateObj) {
-               def List happenedStates = []
-               def sinceThen = dateObj.time
-               for (int i = 0;i < timeOfStates.size();i++) {
-                       if (timeOfStates[i]>=sinceThen)
-                               happenedStates.add(states[i])
+       def statesSince() {
+               def evtActive = [[name: "motion", value: "active", deviceId: "motionSensorID0", descriptionText: "",
+                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
+               def evtInactive = [[name: "motion", value: "inactive", deviceId: "motionSensorID0", 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 active event
+                       evtActive.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 2) {//send two active events
+                       evtActive.each{
+                               evtToSend.add(it)
+                       }
+                       evtActive.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 3) {//send one inactive event
+                       evtInactive.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 4) {//send two inactive events
+                       evtInactive.each{
+                               evtToSend.add(it)
+                       }
+                       evtInactive.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
                }
-               return happenedStates
+       }
+
+       def currentState(String deviceFeature) {
+               currentValue(deviceFeature)
        }
 
        
index 0ae021a9531fc10f5d3255a7ce3e848f9d90a4d3..c799b0e77766697fd893a67c8bebcdfe314452e5 100644 (file)
@@ -63,7 +63,10 @@ public class MotionSensors {
        def collect(Closure Input) {
                motionSensors.collect(Input)
        }
-
+       
+       def currentState(String deviceFeature) {
+               currentValue(deviceFeature)
+       }
 
        def currentValue(String deviceFeature) {
                motionSensors[0].currentValue(deviceFeature)//It is called if we have only one device
@@ -74,7 +77,7 @@ public class MotionSensors {
        }
 
        def statesSince(String info, Date dateObj) {
-               return motionSensors[0].statesSince(info, dateObj)
+               return motionSensors[0].statesSince()
        }
 
        def getAt(int ix) {
index c9ad722cf3859012e012549a5a9f9aa47afc47ea..47da3b5972653b99d9c66859718469b213edd2de 100644 (file)
@@ -16,6 +16,21 @@ public class RelativeHumidityMeasurement {
                this.humidity = humidity
        }
 
+       def eventsSince() {
+               def evtHumidity = [[name: "humidity", value: this.humidity.toString(), deviceId: "humidityMeasurementID0", 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
+                       evtHumidity.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               }
+       }
+
        //By Model Checker
        def setValue(String value) {
                println("the humidity is changed to $value!")
index a2cd5cdb422763c4fb93c336d4facf19520d5a82..4859ae0a192c54afaacd95cdd9b58af3ecabae54 100644 (file)
@@ -40,6 +40,10 @@ public class RelativeHumidityMeasurements {
                }
        }
 
+       def eventsSince(Date dateObj) {
+               return humidityMeasurements[0].eventsSince()
+       }
+
        //Methods for closures
        def count(Closure Input) {
                humidityMeasurements.count(Input)
index 8bea530901861fb341c8d998f554748785d58e4e..e017b55182ada1f4d49b2a3c976bdbaa788d0f0b 100644 (file)
@@ -26,6 +26,44 @@ public class Switch {
                this.switchLatestValue = switchLatestValue
        }
 
+       def eventsSince() {
+               def evtOn = [[name: "switch", value: "on", deviceId: "switchID0", descriptionText: "",
+                               displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
+               def evtOff = [[name: "switch", value: "off", deviceId: "switchID0", 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 open event
+                       evtOn.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 2) {//send two open events
+                       evtOn.each{
+                               evtToSend.add(it)
+                       }
+                       evtOn.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 3) {//send one closed event
+                       evtOff.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 4) {//send two closed events
+                       evtOff.each{
+                               evtToSend.add(it)
+                       }
+                       evtOff.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               }
+       }
+
        //By Apps
        def setLevel(int level) {
                if (this.currentLevel != level) {
index e6ac8646571f6c4580146f0cb8a2fb08f22339d1..a0e191cf4f61e4b92c33aafcf3670b273aa8946d 100644 (file)
@@ -58,6 +58,10 @@ public class Switches {
        }
 
        //By Apps
+       def eventsSince(Date dateObj, LinkedHashMap metaData) {
+               return switches[0].eventsSince()
+       }
+
        def setLevel(int level) {
                currentLevel = level
                switches[0].setLevel(level)
index 83c1a5966765cd5b402f3d1dfce65f1e6bf62cbc..3e5e817f62c5a478c38b9b3d42f96d4b1404fe03 100644 (file)
@@ -24,13 +24,17 @@ public class ThreeAxis {
                println("the three axis of cube is chagned to $threeAxis!")
        }
 
+       def currentState(String deviceFeature) {
+               currentValue(deviceFeature)
+       }
+
        def currentValue(String deviceFeature) {
-               if (deviceFeature == "threeAxis")
+               if (deviceFeature == "threeAxis" || deviceFeature == "status")
                        return threeAxis
        }
 
        def latestValue(String deviceFeature) {
-               if (deviceFeature == "threeAxis")
+               if (deviceFeature == "threeAxis" || deviceFeature == "status")
                        return threeAxis
        }
 }
index e9c027e5a9a4834d4c9bef865c10945780f745b8..7077514c973e425a67b6f96433372d1deaae8c42 100644 (file)
@@ -52,7 +52,10 @@ public class ThreeAxises {
        def collect(Closure Input) {
                threeAxises.collect(Input)
        }
-
+       
+       def currentState(String deviceFeature) {
+               threeAxises[0].currentValue(deviceFeature)
+       }
 
        def currentValue(String deviceFeature) {
                threeAxises[0].currentValue(deviceFeature)
index 6f6d6e38dc6706d6cf8fa7de1d9f22d10082343e..cd0d297502e32dbfdf9f1c84dbe0b683d76c0713 100644 (file)
@@ -490,6 +490,8 @@ LinkedHashMap threeAxis
 /*events*/
 threeAxisObject.setValue([name: "threeAxis", value: '{"x": 1, "y": 2, "z": 3}', deviceId: "threeAxisID0", descriptionText: "",
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+threeAxisObject.setValue([name: "status", value: '{"x": 1, "y": 2, "z": 3}', deviceId: "threeAxisID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 /////
 /*events*/
 //