Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure
authorrtrimana <rtrimana@uci.edu>
Mon, 5 Aug 2019 00:51:24 +0000 (17:51 -0700)
committerrtrimana <rtrimana@uci.edu>
Mon, 5 Aug 2019 00:51:24 +0000 (17:51 -0700)
19 files changed:
AccelerationSensor/AccelerationSensor.groovy
AccelerationSensor/AccelerationSensors.groovy
Button/Button.groovy [new file with mode: 0644]
Button/Buttons.groovy [new file with mode: 0644]
ColorControl/ColorControl.groovy
ColorControl/ColorControls.groovy
ColorTemperature/ColorTemperature.groovy [new file with mode: 0644]
ColorTemperature/ColorTemperatures.groovy [new file with mode: 0644]
Event/Event.groovy
Extractor/Extractor.groovy
Extractor/ExtractorScript.py
GlobalVariables/GlobalVariablesBothApps.groovy [deleted file]
Methods/parseJson.groovy [new file with mode: 0644]
Methods/unsubscribe.groovy [new file with mode: 0644]
Runner.py
SwitchLevel/SwitchLevel.groovy
SwitchLevel/SwitchLevels.groovy
Variables and events for each device
run.sh

index 78a9bed73ee91a74c48af4af5c3c46897777a28d..fcc1688d8ef80664a9feee982e597a700457d887 100644 (file)
@@ -2,6 +2,9 @@
 package AccelerationSensor
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class AccelerationSensor {
        private String id
        private String label
@@ -9,8 +12,6 @@ public class AccelerationSensor {
        private String acceleration
        private String currentAcceleration
        private String accelerationLatestValue
-       private List states = []
-       private List timeOfStates = []
 
        AccelerationSensor(String id, String label, String displayName, String acceleration, String accelerationLatestValue) {
                this.id = id
@@ -26,18 +27,90 @@ public class AccelerationSensor {
                this.accelerationLatestValue = value
                this.acceleration = value
                this.currentAcceleration = 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: "acceleration", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
+                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
+                                [name: "acceleration.active", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
+                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
+               def evtInactive = [[name: "acceleration", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
+                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
+                                  [name: "acceleration.inactive", value: "inactive", deviceId: "accelerationSensorID0", 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
+               }
+       }
+
+       def eventsSince() {
+               def evtActive = [[name: "acceleration", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
+                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
+                                [name: "acceleration.active", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
+                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
+               def evtInactive = [[name: "acceleration", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
+                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
+                                  [name: "acceleration.inactive", value: "inactive", deviceId: "accelerationSensorID0", 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
        }
 
        
index bf24508f6eaa6d0064a55864d42123d79b1564f2..7df4347f47bea0915b29841bea4374132309c9d9 100644 (file)
@@ -47,6 +47,15 @@ public class AccelerationSensors {
                }
        }
 
+       //methods
+       def eventsSince(Date dateObj) {
+               return accelerationSensors[0].eventsSince()
+       }
+               
+       def statesSince(String info, Date dateObj) {
+               return accelerationSensors[0].statesSince()
+       }
+
        //Methods for closures
        def count(Closure Input) {
                accelerationSensors.count(Input)
@@ -76,10 +85,6 @@ public class AccelerationSensors {
                accelerationSensors[0].latestValue(deviceFeature)//It is called if we have only one device
        }
 
-       def statesSince(String info, Date dateObj) {
-               return accelerationSensors[0].statesSince(info, dateObj)
-       }
-
        def getAt(int ix) {
                accelerationSensors[ix]
        }
diff --git a/Button/Button.groovy b/Button/Button.groovy
new file mode 100644 (file)
index 0000000..45123fa
--- /dev/null
@@ -0,0 +1,65 @@
+//Create a class for button
+package Button
+import Timer.SimulatedTimer
+
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
+public class Button {
+       private String id
+       private String label
+       private String displayName
+       private String button
+       private int numberOfButtons
+
+       Button(String id, String label, String displayName, String button, int numberOfButtons) {
+               this.id = id
+               this.label = label
+               this.displayName = displayName
+               this.button = button
+               this.numberOfButtons = numberOfButtons
+       }
+
+       def setValue(LinkedHashMap eventDataMap) {
+               button = eventDataMap["value"]
+               println("the button is $button!")
+       }
+
+       def eventsSince() {
+               def evtHeld = [[name: "button", value: "held", deviceId: "buttonID0", descriptionText: "",
+                               displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
+               def evtPushed = [[name: "button", value: "pushed", deviceId: "buttonID0", 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
+               }
+       }
+}
diff --git a/Button/Buttons.groovy b/Button/Buttons.groovy
new file mode 100644 (file)
index 0000000..423b956
--- /dev/null
@@ -0,0 +1,65 @@
+//Create a class for button
+package Button
+import Timer.SimulatedTimer
+
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
+public class Buttons {
+       private int deviceNumbers
+       private List buttons
+       def sendEvent
+
+       //For one device(We cannot have obj.id)-> We should have obj[0].id
+       private String id = "buttonID0"
+       private String label = "button0"
+       private String displayName = "button0"
+       private String button = "pushed"
+       private int numberOfButtons = 4
+       
+               
+       Buttons(Closure sendEvent, int deviceNumbers) {
+               this.sendEvent = sendEvent              
+               this.deviceNumbers = deviceNumbers
+               this.buttons = []
+
+               buttons.add(new Button(id, label, displayName, button, numberOfButtons))
+       }
+
+       //By Model Checker
+       def setValue(LinkedHashMap eventDataMap) {
+               buttons[0].setValue(eventDataMap)
+               sendEvent(eventDataMap)
+       }
+
+       //Methods for closures
+       def count(Closure Input) {
+               buttons.count(Input)
+       }
+       def size() {
+               buttons.size()
+       }
+       def each(Closure Input) {
+               buttons.each(Input)
+       }
+       def sort(Closure Input) {
+               buttons.sort(Input)
+       }
+       def find(Closure Input) {
+               buttons.find(Input)
+       }
+       def collect(Closure Input) {
+               buttons.collect(Input)
+       }
+
+
+       //methods
+       def eventsSince(Date dateObj) {
+               return buttons[0].eventsSince()
+       }
+
+
+       def getAt(int ix) {
+               buttons[ix]
+       }
+}
index 4d6eaf7ceb53b54aa58ef2627c49ba14b091300a..cd33e8e6ebc7756d27447d5af1a16809c09ce07d 100644 (file)
@@ -9,10 +9,14 @@ public class ColorControl {
        private String label
        private String displayName
        private String color
+       private String currentColor
        private String currentSwitch
        private int level
+       private int currentLevel
        private int hue
+       private int currentHue
        private int saturation
+       private int currentSaturation
        private int colorTemperature
        
        ColorControl(Closure sendEvent, String id, String label, String displayName, String color, int hue, int saturation, int level, String currentSwitch, int colorTemperature) {
@@ -20,9 +24,13 @@ public class ColorControl {
                this.label = label
                this.displayName = displayName
                this.color = color
+               this.currentColor = color
                this.hue = hue
+               this.currentHue = hue
                this.saturation = saturation
+               this.currentSaturation = saturation
                this.level = level
+               this.currentLevel = level
                this.currentSwitch = currentSwitch
                this.colorTemperature = colorTemperature
                this.sendEvent = sendEvent
@@ -32,14 +40,18 @@ public class ColorControl {
        def setValue(String value, String name) {
                if ((name == "color") && (value != this.color)) {
                        this.color = value
+                       this.currentColor = value
                        println("the color of the light is changed to $value!")
                } else if ((name == "hue") && (value != this.hue)) {
                        this.hue = value.toInteger()
+                       this.currentHue = value.toInteger()
                        println("The hue level of the light is changed to $value!")
                } else if ((name == "saturation") && (value != this.saturation)) {
                        this.saturation = value.toInteger()
+                       this.currentSaturation = value.toInteger()
                        println("The saturation level of the light is changed to $value!")
                } else if ((name == "level") && (value != this.level)) {
+                       this.currentLevel = value.toInteger()
                        this.level = value.toInteger()
                        println("The level of the light is changed to $value!")
                } else if ((name == "currentSwitch") && (value != this.currentSwitch)) {
@@ -54,6 +66,7 @@ public class ColorControl {
        //methods
        def setColor(String color) {
                if (color != this.color) {
+                       this.currentColor = color
                        this.color = color
                        println("The color of the light is changed to $color!")
                        sendEvent([name: "color", value: "$color", deviceId: this.id, descriptionText: "",
@@ -64,6 +77,7 @@ public class ColorControl {
        def setHue(int hue) {
                if (hue != this.hue) {
                        this.hue = hue
+                       this.currentHue = hue
                        println("The hue level of the light is changed to $hue!")
                        sendEvent([name: "hue", value: "$hue", deviceId: this.id, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
@@ -72,6 +86,7 @@ public class ColorControl {
 
        def setSaturation(int saturation) {
                if (saturation != this.saturation) {
+                       this.currentSaturation = saturation
                        this.saturation = saturation
                        println("The saturation level of the light is changed to $saturation!")
                        sendEvent([name: "saturation", value: "$saturation", deviceId: this.id, descriptionText: "",
@@ -81,6 +96,7 @@ public class ColorControl {
 
        def setLevel(int level) {
                if (level != this.level) {
+                       this.currentLevel = level
                        this.level = level
                        println("The level of the light is changed to $level!")
                        sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
index 5262e91b64b9c9fa69a0dcf87b3041d94f3ec9eb..0c0832b3921e650d870b2db8814bd212f4106a9b 100644 (file)
@@ -15,10 +15,14 @@ public class ColorControls {
        private String label = "colorControl0"
        private String displayName = "colorControl0"
        private String color = "red"
+       private String currentColor = "red"
        private String currentSwitch = "off"
        private int level = 50
+       private int currentLevel = 50
        private int hue = 50
+       private int currentHue = 50
        private int saturation = 50
+       private int currentSaturation = 50
        private int colorTemperature = 15000
        
 
@@ -27,18 +31,16 @@ public class ColorControls {
                this.deviceNumbers = deviceNumbers
                this.colorControls = []
 
-               /*def initHue = Verify.getIntFromList(30, 50, 70)
+               def initHue = Verify.getIntFromList(30, 50)
                this.hue = initHue
-               def initSat = Verify.getIntFromList(40, 50, 60)
+               def initSat = Verify.getIntFromList(40, 50)
                this.saturation = initSat
                def init = Verify.getInt(0,2)
                if (init == 0) {
                        this.color = "red"
-               } else if (init == 1) {
-                       this.color = "green"
                } else {
                        this.color = "blue"
-               }*/
+               }
 
                colorControls.add(new ColorControl(sendEvent, id, label, displayName, this.color, this.hue, this.saturation, this.level, this.currentSwitch, this.colorTemperature))
        }
@@ -67,6 +69,7 @@ public class ColorControls {
        def setValue(LinkedHashMap eventDataMap) {
                if (eventDataMap["name"] == "color") {
                        if (eventDataMap["value"] != colorControls[0].color) {
+                               this.currentColor = eventDataMap["value"]
                                this.color = eventDataMap["value"]
                                colorControls[0].setValue(eventDataMap["value"], "color")
                                sendEvent(eventDataMap)
@@ -74,12 +77,14 @@ public class ColorControls {
                } else if (eventDataMap["name"] == "hue") {
                        if (eventDataMap["value"].toInteger() != colorControls[0].hue) {
                                this.hue = eventDataMap["value"].toInteger()
+                               this.currentHue = eventDataMap["value"].toInteger()
                                colorControls[0].setValue(eventDataMap["value"], "hue")
                                sendEvent(eventDataMap)
                        }
                } else if (eventDataMap["name"] == "saturation") {
                        if (eventDataMap["value"].toInteger() != colorControls[0].saturation) {
                                this.saturation = eventDataMap["value"].toInteger()
+                               this.currentSaturation = eventDataMap["value"].toInteger()
                                colorControls[0].setValue(eventDataMap["value"], "saturation")
                                sendEvent(eventDataMap)
                        }
@@ -97,6 +102,7 @@ public class ColorControls {
                        }
                } else if (eventDataMap["name"] == "level") {
                        if (eventDataMap["value"].toInteger() != colorControls[0].level) {
+                               this.currentLevel = eventDataMap["value"].toInteger() 
                                this.level = eventDataMap["value"].toInteger()
                                colorControls[0].setValue(eventDataMap["value"], "level")
                                sendEvent(eventDataMap)
@@ -108,6 +114,7 @@ public class ColorControls {
        //methods
        def setColor(String color) {
                if (color != this.color) {
+                       this.currentColor = color
                        this.color = color
                        colorControls[0].setColor(color)                        
                }
@@ -115,13 +122,15 @@ public class ColorControls {
 
        def setHue(int hue) {
                if (hue != this.hue) {
-                       this.hue = hue  
+                       this.hue = hue
+                       this.currentHue = hue
                        colorControls[0].setHue(hue)
                }
        }
 
        def setSaturation(int saturation) {
                if (saturation != this.saturation) {
+                       this.currentSaturation = saturation
                        this.saturation = saturation
                        colorControls[0].setSaturation(saturation)                      
                }       
@@ -129,6 +138,7 @@ public class ColorControls {
 
        def setLevel(int level) {
                if (level != this.level) {
+                       this.currentLevel = level
                        this.level = level
                        colorControls[0].setLevel(level)
                }
diff --git a/ColorTemperature/ColorTemperature.groovy b/ColorTemperature/ColorTemperature.groovy
new file mode 100644 (file)
index 0000000..d73ed9b
--- /dev/null
@@ -0,0 +1,103 @@
+//Create a class for color temperature
+package ColorTemperature
+import Timer.SimulatedTimer
+
+
+public class ColorTemperature {
+       def sendEvent
+       private String id
+       private String label
+       private String displayName
+       private String currentSwitch
+       private int level
+       private int currentLevel
+       private int colorTemperature
+       
+       ColorTemperature(Closure sendEvent, String id, String label, String displayName, int level, String currentSwitch, int colorTemperature) {
+               this.id = id
+               this.label = label
+               this.displayName = displayName
+               this.level = level
+               this.currentLevel = level
+               this.currentSwitch = currentSwitch
+               this.colorTemperature = colorTemperature
+               this.sendEvent = sendEvent
+       }
+       
+       //By model checker
+       def setValue(String value, String name) {
+               if ((name == "level") && (value != this.level)) {
+                       this.currentLevel = value.toInteger()
+                       this.level = value.toInteger()
+                       println("The level of the light is changed to $value!")
+               } else if ((name == "currentSwitch") && (value != this.currentSwitch)) {
+                       this.currentSwitch = value
+                       println("The light is changed to $value!")
+               } else if ((name == "colorTemperature") && (value != this.colorTemperature)) {
+                       this.colorTemperature = value.toInteger()
+                       println("The color temperature level of the light is changed to $value!")
+               }
+       }
+
+       //methods
+       def setLevel(int level) {
+               if (level != this.level) {
+                       this.currentLevel = level
+                       this.level = level
+                       println("The level of the light is changed to $level!")
+                       sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
+       }
+
+       def setColorTemperature(int colorTemperature) {
+               if (colorTemperature != this.colorTemperature) {
+                       this.colorTemperature = colorTemperature
+                       println("The color temperature level of the light is changed to $colorTemperature!")
+                       sendEvent([name: "colorTemperature", value: "$colorTemperature", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
+       }
+
+       def on(String currentSwitch) {
+               if (currentSwitch != this.currentSwitch) {
+                       this.currentSwitch = currentSwitch
+                       println("The light is changed to $currentSwitch!")
+                       sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                       sendEvent([name: "switch.on", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
+       }
+
+       def off(String currentSwitch) {
+               if (currentSwitch != this.currentSwitch) {
+                       this.currentSwitch = currentSwitch
+                       println("The light is changed to $currentSwitch!")
+                       sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                       sendEvent([name: "switch.off", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
+       }
+
+       def currentValue(String deviceFeature) {
+               if (deviceFeature == "level") {
+                       return level
+               } else if (deviceFeature == "colorTemperature") {
+                       return colorTemperature
+               } else if (deviceFeature == "switch") {
+                       return currentSwitch
+               }
+       }
+
+       def latestValue(String deviceFeature) {
+               if (deviceFeature == "level") {
+                       return level
+               } else if (deviceFeature == "colorTemperature") {
+                       return colorTemperature
+               } else if (deviceFeature == "switch") {
+                       return currentSwitch
+               }
+       }
+}
diff --git a/ColorTemperature/ColorTemperatures.groovy b/ColorTemperature/ColorTemperatures.groovy
new file mode 100644 (file)
index 0000000..aea5279
--- /dev/null
@@ -0,0 +1,128 @@
+//Create a class for color temperature
+package ColorTemperature
+import Timer.SimulatedTimer
+
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
+public class ColorTemperatures {
+       private int deviceNumbers
+       private List colorTemperatues
+       def sendEvent
+
+       //For one device(We cannot have obj.id)-> We should have obj[0].id
+       private String id = "colorTemperatureID0"
+       private String label = "colorTemperature0"
+       private String displayName = "colorTemperature0"
+       private String currentSwitch = "off"
+       private int level = 50
+       private int currentLevel = 50
+       private int colorTemperature = 15000
+       
+
+       ColorTemperatures(Closure sendEvent, int deviceNumbers) {
+               this.sendEvent = sendEvent
+               this.deviceNumbers = deviceNumbers
+               this.colorTemperatues = []
+
+               def initLevel = Verify.getIntFromList(50, 70)
+               this.level = initLevel 
+               def initTemp = Verify.getIntFromList(10000, 15000)
+               this.colorTemperature = initTemp 
+               def init = Verify.getBoolean
+               if (init) {
+                       this.currentSwitch = "off"
+               } else {
+                       this.currentSwitch = "on"
+               }
+
+               colorTemperatues.add(new ColorTemperature(sendEvent, id, label, displayName, this.level, this.currentSwitch, this.colorTemperature))
+       }
+
+       //Methods for closures
+       def count(Closure Input) {
+               colorTemperatues.count(Input)
+       }
+       def size() {
+               colorTemperatues.size()
+       }
+       def each(Closure Input) {
+               colorTemperatues.each(Input)
+       }
+       def find(Closure Input) {
+               colorTemperatues.find(Input)
+       }
+       def sort(Closure Input) {
+               colorTemperatues.sort(Input)
+       }
+       def collect(Closure Input) {
+               colorTemperatues.collect(Input)
+       }
+
+       //By model checker
+       def setValue(LinkedHashMap eventDataMap) {
+               if (eventDataMap["name"] == "switch") {
+                       if (eventDataMap["value"] != colorTemperatues[0].currentSwitch) {
+                               this.currentSwitch = eventDataMap["value"]
+                               colorTemperatues[0].setValue(eventDataMap["value"], "switch")
+                               sendEvent(eventDataMap)
+                       }
+               } else if (eventDataMap["name"] == "colorTemperature") {
+                       if (eventDataMap["value"].toInteger() != colorTemperatues[0].colorTemperature) {
+                               this.colorTemperature = eventDataMap["value"].toInteger()
+                               colorTemperatues[0].setValue(eventDataMap["value"], "colorTemperature")
+                               sendEvent(eventDataMap)
+                       }
+               } else if (eventDataMap["name"] == "level") {
+                       if (eventDataMap["value"].toInteger() != colorTemperatues[0].level) {
+                               this.currentLevel = eventDataMap["value"].toInteger() 
+                               this.level = eventDataMap["value"].toInteger()
+                               colorTemperatues[0].setValue(eventDataMap["value"], "level")
+                               sendEvent(eventDataMap)
+                       }
+               }
+       }
+
+
+       //methods
+       def setLevel(int level) {
+               if (level != this.level) {
+                       this.currentLevel = level
+                       this.level = level
+                       colorTemperatues[0].setLevel(level)
+               }
+       }
+
+       def setColorTemperature(String colorTemperature) {
+               if (colorTemperature != this.colorTemperature) {
+                       this.colorTemperature = colorTemperature
+                       colorTemperatues[0].setColorTemperature(colorTemperature)                       
+               }
+       }
+
+       def on(String currentSwitch) {
+               if (currentSwitch != this.currentSwitch) {
+                       this.currentSwitch = currentSwitch
+                       colorTemperatues[0].on(currentSwitch)                   
+               }
+       }
+
+       def off(String currentSwitch) {
+               if (currentSwitch != this.currentSwitch) {
+                       this.currentSwitch = currentSwitch
+                       colorTemperatues[0].off(currentSwitch)                  
+               }
+       }
+
+       def currentValue(String deviceFeature) {
+               colorTemperatues[0].currentValue(deviceFeature)
+       }
+
+       def latestValue(String deviceFeature) {
+               colorTemperatues[0].latestValue(deviceFeature)
+       }       
+
+       def getAt(int ix) {
+               colorTemperatues[ix]
+       }
+}
index 816ea92a584c4c8870b3d9cf4543043ca27a456e..60d7276f7ce4ad7e46452daaad4d70a198e81341 100644 (file)
@@ -13,6 +13,7 @@ public class Event {
        private String unit
        private String data
        private int integerValue
+       private double doubleValue
        private List integerValues = ["battery", "hue", "saturation", "energy", "level", "temperature", 
                                      "heatingSetpoint", "coolingSetpoint", "thermostatSetpoint", "illuminance"]
        
@@ -27,7 +28,9 @@ public class Event {
                this.unit = unit
                this.data = data
                this.displayed = displayed
-               if (integerValues.contains(name))
+               if (integerValues.contains(name)) {
                        this.integerValue = value.toInteger()
+                       this.doubleValue = Double.parseDouble(value);           
+               }
        }
 }
index b049f6105405bc3f6b60967e9e3b9d5eda11d866..e954203f163e6e9e7c2392ad1109d3849b17a16b 100644 (file)
@@ -70,6 +70,10 @@ import Valve.Valve
 import Valve.Valves
 import MobilePresence.MobilePresence
 import MobilePresence.MobilePresences
+import ColorTemperature.ColorTemperature
+import ColorTemperature.ColorTemperatures
+import Button.Button
+import Button.Buttons
 import Timer.SimulatedTimer
 
 //GlobalVariables
@@ -244,7 +248,7 @@ def timeToday(String time, Object timeZone) {
 @Field def sleepSensorObject0
 @Field def sleepSensorObject1
 @Field def sleepSensorObject2
-//Global Object for class sleep sensor!
+//Global Object for class step sensor!
 @Field stepSensorObjects = 0
 @Field def stepSensorObject0
 @Field def stepSensorObject1
@@ -259,7 +263,7 @@ def timeToday(String time, Object timeZone) {
 @Field def temperatureMeasurementObject0
 @Field def temperatureMeasurementObject1
 @Field def temperatureMeasurementObject2
-//Global Object for class temperature measurement!
+//Global Object for class water sensor!
 @Field waterSensorObjects = 0
 @Field def waterSensorObject0
 @Field def waterSensorObject1
@@ -269,12 +273,21 @@ def timeToday(String time, Object timeZone) {
 @Field def valveObject0
 @Field def valveObject1
 @Field def valveObject2
-//Global Object for class valve!
+//Global Object for class mobile presence!
 @Field mobilePresenceObjects = 0
 @Field def mobilePresenceObject0
 @Field def mobilePresenceObject1
 @Field def mobilePresenceObject2
-
+//Global Object for class color temperature!
+@Field colorTemperatureObjects = 0
+@Field def colorTemperatureObject0
+@Field def colorTemperatureObject1
+@Field def colorTemperatureObject2
+//Global Object for class button!
+@Field buttonObjects = 0
+@Field def buttonObject0
+@Field def buttonObject1
+@Field def buttonObject2
 
 
 //Global variables
@@ -455,6 +468,41 @@ def input(LinkedHashMap metaData) {
                                extractedObjectsConstructorApp2.append(metaData['name']+" = obj.alarmObject\n")
                        }
                        break
+               case "capability.button":
+                       globalObjects.eachLine { line ->
+                               if(line.contains("buttonObject")){
+                                       contains = 1
+                               }
+                       }
+
+                       if (contains == 0)
+                               globalObjects.append("@Field def buttonObject = new Buttons(sendEvent, 1)\n")
+
+                       if (buttonObjects == 0) {
+                               buttonObject0 = metaData['name']
+                               this[buttonObject0] = new Buttons({}, 1)
+                       } else if (buttonObjects == 1) {
+                               buttonObject1 = metaData['name']
+                               this[buttonObject1] = new Buttons({}, 1)
+                       } else if (buttonObjects == 2) {
+                               buttonObject2 = metaData['name']
+                               this[buttonObject2] = new Buttons({}, 1)
+                       }
+
+                       buttonObjects=buttonObjects+1
+
+                       settings.put(metaData['name'], new Buttons({}, 1))
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class Button!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.buttonObject\n")                
+                       } else {
+                               extractedObjectsApp2.append("//Object for class Button!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.buttonObject\n")
+                       }
+                       break
                case "capability.battery":
                        globalObjects.eachLine { line ->
                                if(line.contains("batteryObject")){
@@ -560,6 +608,41 @@ def input(LinkedHashMap metaData) {
                                extractedObjectsConstructorApp2.append(metaData['name']+" = obj.carbonMonoxideDetectorObject\n")
                        }
                        break
+               case "capability.colorTemperature":
+                       globalObjects.eachLine { line ->
+                               if(line.contains("colorTemperatureObject")){
+                                       contains = 1
+                               }
+                       }
+
+                       if (contains == 0)
+                               globalObjects.append("@Field def colorTemperatureObject = new ColorTemperatures(sendEvent, 1)\n")
+
+                       if (colorTemperatureObjects == 0) {
+                               colorTemperatureObject0 = metaData['name']
+                               this[colorTemperatureObject0] = new ColorTemperatures({}, 1)
+                       } else if (colorTemperatureObjects == 1) {
+                               colorTemperatureObject1 = metaData['name']
+                               this[colorTemperatureObject1] = new ColorTemperatures({}, 1)
+                       } else if (colorTemperatureObjects == 2) {
+                               colorTemperatureObject2 = metaData['name']
+                               this[colorTemperatureObject2] = new ColorTemperatures({}, 1)
+                       }
+
+                       colorTemperatureObjects=colorTemperatureObjects+1
+
+                       settings.put(metaData['name'], new ColorTemperatures({}, 1))
+
+                       if (App == "App1") {
+                               extractedObjectsApp1.append("//Object for class color temperature!\n")
+                               extractedObjectsApp1.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp1.append(metaData['name']+" = obj.colorTemperatureObject\n")              
+                       } else {
+                               extractedObjectsApp2.append("//Object for class color control!\n")
+                               extractedObjectsApp2.append("def "+metaData['name']+"\n")
+                               extractedObjectsConstructorApp2.append(metaData['name']+" = obj.colorTemperatureObject\n")
+                       }
+                       break
                case "capability.colorControl":
                        globalObjects.eachLine { line ->
                                if(line.contains("colorControlObject")){
@@ -1435,7 +1518,6 @@ def input(LinkedHashMap metaData) {
                                extractedObjectsConstructorApp2.append(metaData['name']+" = obj.mobilePresenceObject\n")
                        }
                        break
-               case "capability.button":
                case "device.aeonKeyFob":
                        globalObjects.eachLine { line ->
                                if(line.contains("aeonKeyFobObject")){
index 2c53c5653529371ad955017c8283abe584bcfd00..bf8471f1a41935fa0191f93f558dc31b5679966d 100644 (file)
@@ -290,10 +290,8 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write(line)
                        event.close()
                elif eventList[i] == "unlock":
-                       event = open("eventSimulator/unlockEvent.groovy", "r")
-                       for line in event:
-                               extractedEvents.write(line)
-                       event.close()
+                        #Don't do anything for this case
+                        counter = counter - 1
                elif eventList[i] == "contact.open":
                        event = open("eventSimulator/contactOpenEvent.groovy", "r")
                        for line in event:
@@ -398,8 +396,6 @@ def ExtractEvents(extractedEvents):
                        event.close()
                elif eventList[i] == "doorState":
                        #Write two events subsequently
-                       extractedEvents.write("\t\t\tdef event = Verify.getInt(0,1)\n")
-                       extractedEvents.write("\t\t\tif (event == 0) {\n")
                        event = open("eventSimulator/doorOpenEvent.groovy", "r")                        
                        for line in event:
                                extractedEvents.write(line)
@@ -928,6 +924,8 @@ def ExtractEvents(extractedEvents):
                                event = open("eventSimulator/musicPlayerLevelEvent.groovy", "r")
                        elif capability == "capability.switchLevel":
                                event = open("eventSimulator/switchLevelEvent.groovy", "r")
+                       elif capability == "capability.colorControl":
+                               event = open("eventSimulator/colorLevelChangeEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
diff --git a/GlobalVariables/GlobalVariablesBothApps.groovy b/GlobalVariables/GlobalVariablesBothApps.groovy
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/Methods/parseJson.groovy b/Methods/parseJson.groovy
new file mode 100644 (file)
index 0000000..b7de692
--- /dev/null
@@ -0,0 +1,4 @@
+/////////////////////////////////////////////////////////////////////
+def parseJson(String data) {
+       return new groovy.json.JsonSlurper().parseText(data)
+}
\ No newline at end of file
diff --git a/Methods/unsubscribe.groovy b/Methods/unsubscribe.groovy
new file mode 100644 (file)
index 0000000..ba20619
--- /dev/null
@@ -0,0 +1,6 @@
+/////////////////////////////////////////////////////////////////////
+def unsubscribe() {
+       objectList.clear()
+       eventList.clear()
+       functionList.clear()
+}
\ No newline at end of file
index 70bdf3efa135406fbc3261b702a586063e615553..4c02586146cf200d3df9067041407962f613fae4 100644 (file)
--- a/Runner.py
+++ b/Runner.py
@@ -31,6 +31,8 @@ sendNotification = open("Methods/"+"sendNotification.groovy", "r")
 canSchedule = open("Methods/"+"canSchedule.groovy", "r")
 createAccessToken = open("Methods/"+"createAccessToken.groovy", "r")
 runOnce = open("Methods/"+"runOnce.groovy", "r")
+parseJson = open("Methods/"+"parseJson.groovy", "r")
+unsubscribe = open("Methods/"+"unsubscribe.groovy", "r")
 App1 = open("Extractor/"+"App1/App1.groovy", "r")
 extractedObjectsApp1 = open("Extractor/"+"App1/extractedObjectsApp1.groovy", "r")
 extractedObjectsConstructorApp1 = open("Extractor/"+"App1/extractedObjectsConstructorApp1.groovy", "r")
@@ -110,6 +112,10 @@ Out.write("import Valve.Valve\n")
 Out.write("import Valve.Valves\n")
 Out.write("import MobilePresence.MobilePresence\n")
 Out.write("import MobilePresence.MobilePresences\n")
+Out.write("import ColorTemperature.ColorTemperature\n")
+Out.write("import ColorTemperature.ColorTemperatures\n")
+Out.write("import Button.Button\n")
+Out.write("import Button.Buttons\n")
 Out.write("import Event.Event\n")
 Out.write("import Timer.SimulatedTimer\n")
 Out.write("\n")
@@ -186,6 +192,10 @@ for line in createAccessToken:
        Out.write("\t"+line)
 for line in runOnce:
        Out.write("\t"+line)
+for line in parseJson:
+       Out.write("\t"+line)
+for line in unsubscribe:
+       Out.write("\t"+line)
 Out.write("\n")
 Start = 0
 for line in App1:
@@ -219,6 +229,8 @@ sendNotification = open("Methods/"+"sendNotification.groovy", "r")
 canSchedule = open("Methods/"+"canSchedule.groovy", "r")
 createAccessToken = open("Methods/"+"createAccessToken.groovy", "r")
 runOnce = open("Methods/"+"runOnce.groovy", "r")
+parseJson = open("Methods/"+"parseJson.groovy", "r")
+unsubscribe = open("Methods/"+"unsubscribe.groovy", "r")
 App2 = open("Extractor/"+"App2/App2.groovy", "r")
 extractedObjectsApp2 = open("Extractor/"+"App2/extractedObjectsApp2.groovy", "r")
 extractedObjectsConstructorApp2 = open("Extractor/"+"App2/extractedObjectsConstructorApp2.groovy", "r")
@@ -286,6 +298,10 @@ for line in createAccessToken:
        Out.write("\t"+line)
 for line in runOnce:
        Out.write("\t"+line)
+for line in parseJson:
+       Out.write("\t"+line)
+for line in unsubscribe:
+       Out.write("\t"+line)
 Out.write("\n")
 Start = 0
 for line in App2:
index 8782365c322147d3d01655b98b77c51419f8e860..24bd7bfa0f3b03aba3b026067cdfaa1171641297 100644 (file)
@@ -108,4 +108,21 @@ public class SwitchLevel {
                        this.rate = value.toInteger()
                }
        }
+
+
+       def currentValue(String deviceFeature) {
+               if (deviceFeature == "level") {
+                       return level
+               } else if (deviceFeature == "switch") {
+                       return switchState
+               }
+       }
+
+       def latestValue(String deviceFeature) {
+               if (deviceFeature == "level") {
+                       return level
+               } else if (deviceFeature == "switch") {
+                       return switchState
+               }
+       }
 }
index 490e52dc66338184f01c8fef8b3a53a3098d3641..1bae6a1c30ccf519b1f7535cefafde160581c251 100644 (file)
@@ -123,6 +123,15 @@ public class SwitchLevels {
                }
        }
 
+       def currentValue(String deviceFeature) {
+               switchLevels[0].currentValue(deviceFeature)
+       }
+       
+       def latestValue(String deviceFeature) {
+               switchLevels[0].latestValue(deviceFeature)
+       }
+       
+
        def getAt(int ix) {
                switchLevels[ix]
        }
index 66e3f51d8ec0e4d8fa6699e9ad4092408aab5fdd..9594b895eec1695e74d85d0218a8fe337d3eb2cd 100644 (file)
@@ -247,6 +247,10 @@ switchObject.setValue([name: "switch", value: "off", deviceId: "switchID0", desc
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 switchObject.setValue([name: "switch", value: "on", deviceId: "switchID0", descriptionText: "",
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+switchObject.setValue([name: "switch.off", value: "off", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+switchObject.setValue([name: "switch.on", value: "on", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 /////
 /*events*/
 //
@@ -363,6 +367,10 @@ colorControlObject.setValue([name: "switch", value: "on", deviceId: "colorContro
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 colorControlObject.setValue([name: "switch", value: "off", deviceId: "colorControlID0", descriptionText: "",
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorControlObject.setValue([name: "switch.on", value: "on", deviceId: "colorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorControlObject.setValue([name: "switch.off", value: "off", deviceId: "colorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 colorControlObject.setValue([name: "colorTemperature", value: "50", deviceId: "colorControlID0", descriptionText: "",
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 /*events*/
@@ -417,6 +425,10 @@ relaySwitchObject.setValue([name: "switch", value: "off", deviceId: "relaySwitch
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 relaySwitchObject.setValue([name: "switch", value: "on", deviceId: "relaySwitchID0", descriptionText: "",
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+relaySwitchObject.setValue([name: "switch.off", value: "off", deviceId: "relaySwitchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+relaySwitchObject.setValue([name: "switch.on", value: "on", deviceId: "relaySwitchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 /////
 /*events*/
 //
@@ -459,6 +471,10 @@ switchLevelObject.setValue([name: "switch", value: "on", deviceId: "switchLevelI
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 switchLevelObject.setValue([name: "switch", value: "off", deviceId: "switchLevelID0", descriptionText: "",
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+switchLevelObject.setValue([name: "switch.on", value: "on", deviceId: "switchLevelID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+switchLevelObject.setValue([name: "switch.off", value: "off", deviceId: "switchLevelID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 /////
 /*events*/
 //
@@ -503,3 +519,37 @@ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "
 /////
 /*events*/
 //
+-------------------------------------------------------------------------------
+
+
+//For color temperature:
+int colorTemperature
+String switchState
+/*events*/
+colorTemperatureObject.setValue([name: "switch", value: "off", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorTemperatureObject.setValue([name: "switch", value: "on", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorTemperatureObject.setValue([name: "switch.off", value: "off", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorTemperatureObject.setValue([name: "switch.on", value: "on", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorTemperatureObject.setValue([name: "colorTemperature", value: "13000", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+/////
+/*events*/
+//
+-------------------------------------------------------------------------------
+
+
+//For button:
+String button
+/*events*/
+buttonObject.setValue([name: "button", value: "held", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"buttonNumber": 1}'])
+buttonObject.setValue([name: "button", value: "push", deviceId: "switchID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"buttonNumber": 1}'])
+/////
+/*events*/
+//
+
diff --git a/run.sh b/run.sh
index d77af37608a2679ba4ecc430cbca06b17162cb3f..019ba29f014528e07fb6ba2bc11ae0caf166a675 100755 (executable)
--- a/run.sh
+++ b/run.sh
@@ -1,7 +1,9 @@
 #!/bin/bash
 
 # Device conflict
-python ModelCheck.py ../jpf-core/ ../logs/thermostats/ ../smartapps/ appLists/device-interaction/thermostatsAppList appLists/device-interaction/thermostatsAppList2
+python ModelCheck.py ../jpf-core/ ../logs/nonHueLights/ ../smartapps/ appLists/device-interaction/nonHueLightsAppList appLists/device-interaction/nonHueLightsAppList2
+#python ModelCheck.py ../jpf-core/ ../logs/hueLights/ ../smartapps/ appLists/device-interaction/hueLightsAppList
+#python ModelCheck.py ../jpf-core/ ../logs/thermostats/ ../smartapps/ appLists/device-interaction/thermostatsAppList appLists/device-interaction/thermostatsAppList2
 #python ModelCheck.py ../jpf-core/ ../logs/alarms/ ../smartapps/ appLists/device-interaction/alarmsAppList appLists/device-interaction/alarmsAppList2
 #python ModelCheck.py ../jpf-core/ ../logs/locks/ ../smartapps/ appLists/device-interaction/locksAppList appLists/device-interaction/locksAppList2
 #python ModelCheck.py ../jpf-core/ ../logs/musicPlayers/ ../smartapps/ appLists/device-interaction/musicPlayersAppList