Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure
authoramiraj <amiraj.95@uci.edu>
Fri, 2 Aug 2019 23:40:31 +0000 (16:40 -0700)
committeramiraj <amiraj.95@uci.edu>
Fri, 2 Aug 2019 23:40:31 +0000 (16:40 -0700)
AeonKeyFob/AeonKeyFob.groovy
AeonKeyFob/AeonKeyFobs.groovy
ColorControl/ColorControl.groovy
ColorControl/ColorControls.groovy
ContactSensor/ContactSensor.groovy
ContactSensor/ContactSensors.groovy
GlobalVariables/GlobalVariablesEachApp.groovy
Methods/runIn.groovy
Methods/runOnce.groovy
Methods/schedule.groovy
Methods/unschedule.groovy

index 8ece0c6..72e5afd 100644 (file)
@@ -2,12 +2,13 @@
 package AeonKeyFob
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class AeonKeyFob {
        private String id
        private String label
        private String displayName
-       private List events = []
-       private List timeOfEvents = []
 
        AeonKeyFob(String id, String label, String displayName) {
                this.id = id
@@ -19,17 +20,43 @@ public class AeonKeyFob {
                def data = eventDataMap["data"]
                def value = eventDataMap["value"]
                println("the button with number $data is $value!")
-               this.events.add(eventDataMap)
-               this.timeOfEvents.add(System.currentTimeMillis())
        }
 
-       def eventsSince(Date dateObj) {
-               def List happenedEvents = []
-               def sinceThen = dateObj.time
-               for (int i = 0;i < timeOfEvents.size();i++) {
-                       if (timeOfEvents[i]>=sinceThen)
-                               happenedEvents.add(events[i])
+       def eventsSince() {
+               def evtHeld = [[name: "button", value: "held", deviceId: "aeonKeyFobID0", descriptionText: "",
+                               displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
+               def evtPushed = [[name: "button", value: "pushed", deviceId: "aeonKeyFobID0", 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 held event
+                       evtHeld.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 2) {//send two held events
+                       evtHeld.each{
+                               evtToSend.add(it)
+                       }
+                       evtHeld.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 3) {//send one pushed event
+                       evtPushed.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 4) {//send two pushed events
+                       evtPushed.each{
+                               evtToSend.add(it)
+                       }
+                       evtPushed.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
                }
-               return happenedEvents
        }
 }
index bbb1a35..6383898 100644 (file)
@@ -2,6 +2,9 @@
 package AeonKeyFob
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class AeonKeyFobs {
        private int deviceNumbers
        private List aeonKeyFobs
@@ -50,7 +53,7 @@ public class AeonKeyFobs {
 
        //methods
        def eventsSince(Date dateObj) {
-               return aeonKeyFobs[0].eventsSince(dateObj)
+               return aeonKeyFobs[0].eventsSince()
        }
 
 
index 53658dc..4d6eaf7 100644 (file)
@@ -4,6 +4,7 @@ import Timer.SimulatedTimer
 
 
 public class ColorControl {
+       def sendEvent
        private String id
        private String label
        private String displayName
@@ -14,7 +15,7 @@ public class ColorControl {
        private int saturation
        private int colorTemperature
        
-       ColorControl(String id, String label, String displayName, String color, int hue, int saturation, int level, String currentSwitch, int colorTemperature) {
+       ColorControl(Closure sendEvent, String id, String label, String displayName, String color, int hue, int saturation, int level, String currentSwitch, int colorTemperature) {
                this.id = id
                this.label = label
                this.displayName = displayName
@@ -24,6 +25,7 @@ public class ColorControl {
                this.level = level
                this.currentSwitch = currentSwitch
                this.colorTemperature = colorTemperature
+               this.sendEvent = sendEvent
        }
        
        //By model checker
index 5b29f55..5262e91 100644 (file)
@@ -40,7 +40,7 @@ public class ColorControls {
                        this.color = "blue"
                }*/
 
-               colorControls.add(new ColorControl(id, label, displayName, this.color, this.hue, this.saturation, this.level, this.currentSwitch, this.colorTemperature))
+               colorControls.add(new ColorControl(sendEvent, id, label, displayName, this.color, this.hue, this.saturation, this.level, this.currentSwitch, this.colorTemperature))
        }
 
        //Methods for closures
index 413b58c..4a10a57 100644 (file)
@@ -2,6 +2,9 @@
 package ContactSensor
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class ContactSensor {
        private String id
        private String label
@@ -24,6 +27,52 @@ public class ContactSensor {
                this.alarmState = alarmState
        }
 
+       def eventsSince() {
+               def evtOpen = [[name: "contact.open", value: "open", deviceId: "contactSensorID0", descriptionText: "",
+                               displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
+                              [name: "contact", value: "open", deviceId: "contactSensorID0", descriptionText: "",
+                               displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
+                              [name: "tamper.tampered", value: "open", deviceId: "contactSensorID0", descriptionText: "",
+                               displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
+               def evtClosed = [[name: "contact.closed", value: "closed", deviceId: "contactSensorID0", descriptionText: "",
+                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
+                                [name: "contact", value: "closed", deviceId: "contactSensorID0", descriptionText: "",
+                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
+                                [name: "tamper.tampered", value: "closed", deviceId: "contactSensorID0", 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
+                       evtOpen.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 2) {//send two open events
+                       evtOpen.each{
+                               evtToSend.add(it)
+                       }
+                       evtOpen.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 3) {//send one closed event
+                       evtClosed.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               } else if (init == 4) {//send two closed events
+                       evtClosed.each{
+                               evtToSend.add(it)
+                       }
+                       evtClosed.each{
+                               evtToSend.add(it)
+                       }
+                       return evtToSend
+               }
+       }
+
        def setValue(String value) {
                println("the contact sensor with id:$id is triggered to $value!")
                this.contactState = value
index 74508a8..5f5f20e 100644 (file)
@@ -59,6 +59,10 @@ public class ContactSensors {
                }
        }
 
+       def eventsSince(Date dateObj) {
+               return contacts[0].eventsSince()
+       }
+
        def on() {
                this.alarmState = "armed"
                contacts[0].on()
index 8ae34ad..ae8b936 100644 (file)
@@ -8,10 +8,6 @@ def functionList = []
 def objectList = []
 //Create a global variable for Events in Subscribe method
 def eventList = []
-//Create a global list for function schedulers
-def timersFuncList = []
-//Create a global list for timer schedulers
-def timersList = []
 //Create a global variable for settings
 def settings
 //Zip code
index 6e4bea3..1ca8d95 100644 (file)
@@ -1,14 +1,15 @@
 /////////////////////////////////////////////////////////////////////
 ////runIn(time, func)
 def runIn(int seconds, Closure functionToCall) {
-       if (timersFuncList.contains(functionToCall)) {
+       /*if (timersFuncList.contains(functionToCall)) {
                timersList[timersFuncList.indexOf(functionToCall)].cancel()
                def task = timersList[timersFuncList.indexOf(functionToCall)].runAfter(1000*seconds*0, functionToCall)
        } else {
                timersFuncList.add(functionToCall)
                timersList.add(new SimulatedTimer())
                def task = timersList[timersFuncList.indexOf(functionToCall)].runAfter(1000*seconds*0, functionToCall)
-       }
+       }*/
+       functionToCall()
 }
 
 def runIn(int seconds, Closure functionToCall, LinkedHashMap metaData) {
@@ -20,9 +21,10 @@ def runIn(int seconds, String nameOfFunction, LinkedHashMap metaData) {
 }
 
 def runIn(int seconds, String nameOfFunction) {
-       timersFuncList.add(nameOfFunction)
+       /*timersFuncList.add(nameOfFunction)
        timersList.add(new SimulatedTimer())
        def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(seconds*1000*0) {
                "$nameOfFunction"()
-       }
+       }*/
+       "$nameOfFunction"()
 }
index 335cc19..308f6c3 100644 (file)
@@ -1,4 +1,4 @@
 /////////////////////////////////////////////////////////////////////
 def runOnce(Date date, Closure methodToCall) {
-       methodTocall()
+       methodToCall()
 }
index 307b221..1d8c810 100644 (file)
@@ -1,49 +1,51 @@
 /////////////////////////////////////////////////////////////////////
 ////schedule(time, nameOfFunction as String)
 def schedule(String time, String nameOfFunction) {
-       //def _inputTime = time.split(':')
-       //Date date = new Date()        
-       //def _currentTime = date.format("HH:mm:ss").split(':')
+       /*def _inputTime = time.split(':')
+       Date date = new Date()  
+       def _currentTime = date.format("HH:mm:ss").split(':')
 
-       //Convert input time and current time to minutes
-       //def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
-       //def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
-       //def delay
+       Convert input time and current time to minutes
+       def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
+       def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
+       def delay
 
-       //if (inputTime < currentTime) {
-       //      delay = 24*60*60-inputTime+currentTime
-       //} else {
-       //      delay = inputTime-currentTime
-       //}
+       if (inputTime < currentTime) {
+               delay = 24*60*60-inputTime+currentTime
+       } else {
+               delay = inputTime-currentTime
+       }
        timersFuncList.add(nameOfFunction)
        timersList.add(new SimulatedTimer())
-       def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(/*delay*1000*0*/0) {
+       def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*1000*0) {
                "$nameOfFunction"()
-       }
+       }*/
+       "$nameOfFunction"()
 }
 ////schedule(time, nameOfFunction as Closure)
 def schedule(String time, Closure nameOfFunction) {
-       //def _inputTime = time.split(':')
-       //Date date = new Date()        
-       //def _currentTime = date.format("HH:mm:ss").split(':')
+       /*def _inputTime = time.split(':')
+       Date date = new Date()  
+       def _currentTime = date.format("HH:mm:ss").split(':')
 
-       //Convert input time and current time to minutes
-       //def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
-       //def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
-       //def delay
+       Convert input time and current time to minutes
+       def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
+       def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
+       def delay
 
-       //if (inputTime < currentTime) {
-       //      delay = 24*60*60-inputTime+currentTime
-       //} else {
-       //      delay = inputTime-currentTime
-       //}
+       if (inputTime < currentTime) {
+               delay = 24*60*60-inputTime+currentTime
+       } else {
+               delay = inputTime-currentTime
+       }
 
        if (timersFuncList.contains(nameOfFunction)) {
                timersList[timersFuncList.indexOf(nameOfFunction)].cancel()
-               def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(/*delay*0*/0, nameOfFunction0)
+               def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(0, nameOfFunction)
        } else {
                timersFuncList.add(nameOfFunction)
                timersList.add(new SimulatedTimer())
-               def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(/*delay*0*/0, nameOfFunction)
-       }
+               def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(0, nameOfFunction)
+       }*/
+       nameOfFunction()
 }
index 7f6ca1f..22ff922 100644 (file)
@@ -1,29 +1,29 @@
 /////////////////////////////////////////////////////////////////////
 ////unschedule(func)
 def unschedule(Closure functionToUnschedule) {
-       for (int i = 0;i < timersFuncList.size();i++) {
+       /*for (int i = 0;i < timersFuncList.size();i++) {
                if (timersFuncList[i] == functionToUnschedule) {
                        if (timersList != null)
                                timersList[i].cancel()
                }
-       }
+       }*/
 }
 
 def unschedule(String nameOfFunctionToUnschedule) {
-       for (int i = 0;i < timersFuncList.size();i++) {
+       /*for (int i = 0;i < timersFuncList.size();i++) {
                if (timersFuncList[i] instanceof String) {
                        if (timersFuncList[i] == nameOfFunctionToUnschedule) {
                                if (timersList != null)
                                        timersList[i].cancel()
                        }
                }
-       }
+       }*/
 }
 
 
 def unschedule() {
-       for (int i = 0;i < timersFuncList.size();i++) {
+       /*for (int i = 0;i < timersFuncList.size();i++) {
                if (timersList != null)
                        timersList[i].cancel()
-       }
+       }*/
 }