Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure
authoramiraj <amiraj.95@uci.edu>
Mon, 5 Aug 2019 19:28:05 +0000 (12:28 -0700)
committeramiraj <amiraj.95@uci.edu>
Mon, 5 Aug 2019 19:28:05 +0000 (12:28 -0700)
16 files changed:
ColorControl/ColorControls.groovy
ColorTemperature/ColorTemperature.groovy
ColorTemperature/ColorTemperatures.groovy
Extractor/Extractor.groovy
Extractor/ExtractorScript.py
Switch/Switches.groovy
SwitchLevel/SwitchLevel.groovy
SwitchLevel/SwitchLevels.groovy
eventSimulator/aeonKeyFobHeldEvent.groovy [new file with mode: 0644]
eventSimulator/aeonKeyFobPushedEvent.groovy [new file with mode: 0644]
eventSimulator/buttonHeldEvent.groovy
eventSimulator/buttonPushedEvent.groovy
eventSimulator/locationSunriseEvent.groovy [new file with mode: 0644]
eventSimulator/locationSunriseTimeEvent.groovy [new file with mode: 0644]
eventSimulator/locationSunsetEvent.groovy [new file with mode: 0644]
eventSimulator/locationSunsetTimeEvent.groovy [new file with mode: 0644]

index 7a54980..4919ebe 100644 (file)
@@ -16,7 +16,7 @@ public class ColorControls {
        private String displayName = "colorControl0"
        private String color = "red"
        private String currentColor = "red"
-       private String currentSwitch = "off"
+       private String currentSwitch = "on"
        private int level = 50
        private int currentLevel = 50
        private int hue = 50
@@ -31,16 +31,22 @@ public class ColorControls {
                this.deviceNumbers = deviceNumbers
                this.colorControls = []
 
-               def initHue = Verify.getIntFromList(30, 50)
+               /*def initHue = Verify.getIntFromList(30, 50)
                this.hue = initHue
                def initSat = Verify.getIntFromList(40, 50)
                this.saturation = initSat
-               def init = Verify.getInt(0,2)
-               if (init == 0) {
+               def initColor = Verify.getBoolean()
+               if (initColor) {
                        this.color = "red"
                } else {
                        this.color = "blue"
                }
+               def init = Verify.getBoolean()
+               if (init) {
+                       this.currentSwitch = "off"
+               } else {
+                       this.currentSwitch = "on"
+               }*/
 
                colorControls.add(new ColorControl(sendEvent, id, label, displayName, this.color, this.hue, this.saturation, this.level, this.currentSwitch, this.colorTemperature))
        }
@@ -179,7 +185,7 @@ public class ColorControls {
                }
        }
 
-       def setColorTemperature(String colorTemperature) {
+       def setColorTemperature(int colorTemperature) {
                if (colorTemperature != this.colorTemperature) {
                        this.colorTemperature = colorTemperature
                        colorControls[0].setColorTemperature(colorTemperature)                  
index d73ed9b..4956e04 100644 (file)
@@ -49,6 +49,16 @@ public class ColorTemperature {
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
+       
+       def setLevel(long 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) {
index 77f0175..99fe7e6 100644 (file)
@@ -14,7 +14,7 @@ public class ColorTemperatures {
        private String id = "colorTemperatureID0"
        private String label = "colorTemperature0"
        private String displayName = "colorTemperature0"
-       private String currentSwitch = "off"
+       private String currentSwitch = "on"
        private int level = 50
        private int currentLevel = 50
        private int colorTemperature = 15000
@@ -25,7 +25,7 @@ public class ColorTemperatures {
                this.deviceNumbers = deviceNumbers
                this.colorTemperatues = []
 
-               def initLevel = Verify.getIntFromList(50, 70)
+               /*def initLevel = Verify.getIntFromList(50, 70)
                this.level = initLevel 
                def initTemp = Verify.getIntFromList(10000, 15000)
                this.colorTemperature = initTemp 
@@ -34,7 +34,7 @@ public class ColorTemperatures {
                        this.currentSwitch = "off"
                } else {
                        this.currentSwitch = "on"
-               }
+               }*/
 
                colorTemperatues.add(new ColorTemperature(sendEvent, id, label, displayName, this.level, this.currentSwitch, this.colorTemperature))
        }
@@ -85,6 +85,14 @@ public class ColorTemperatures {
 
 
        //methods
+       def setLevel(long level) {
+               if (level != this.level) {
+                       this.currentLevel = level
+                       this.level = level
+                       colorTemperatues[0].setLevel(level)
+               }
+       }
+
        def setLevel(int level) {
                if (level != this.level) {
                        this.currentLevel = level
@@ -99,6 +107,13 @@ public class ColorTemperatures {
                        colorTemperatues[0].setColorTemperature(colorTemperature)                       
                }
        }
+       
+       def setColorTemperature(int colorTemperature) {
+               if (colorTemperature != this.colorTemperature) {
+                       this.colorTemperature = colorTemperature
+                       colorTemperatues[0].setColorTemperature(colorTemperature)                       
+               }
+       }
 
        def on(String currentSwitch) {
                if (currentSwitch != this.currentSwitch) {
index e954203..19e5016 100644 (file)
@@ -1555,7 +1555,7 @@ def input(LinkedHashMap metaData) {
                case "mode":
                        //def randomVariable = Math.abs(new Random().nextInt() % 3)
                        def modes = ["away", "home", "night"]
-                       def userInput = modes[0]
+                       def userInput = modes[1]
 
                        if (modeVariables == 0) {
                                mode0 = metaData['name']
index 37c294d..bd7a320 100644 (file)
@@ -48,6 +48,10 @@ eventTypeCounterMap =  {'lock': 2,
                                                'switch.off' : 1,
                                                'location' : 3,
                                                'mode' : 3,
+                                               'sunset' : 1,
+                                               'sunsetTime' : 1,
+                                               'sunrise' : 1,
+                                               'sunriseTime' : 1,
                                                'acceleration' : 2,
                                                'acceleration.active' : 1,
                                                'acceleration.inactive' : 1,
@@ -150,12 +154,22 @@ def ExtractFunctions(F, appName):
                        variable = Temp
                        while (Temp != "\"" and Temp != "app" and Temp != "location"):
                                Temp = GetToken(F)
+                       if Temp == "location":
+                               # See if we have another case for location
+                               Temp = GetToken(F) # Get ','
+                               Temp = GetToken(F) # Get '"'
+                               if Temp == "\"":
+                                       Temp = GetToken(F)                      
+                               else:
+                                       # This is the special case where we will see, e.g., sunset, sunrise, etc.
+                                       Temp = "location"
                        if Temp == "\"":
-                               Temp = GetToken(F)              
+                               Temp = GetToken(F)
 
                        #print "DEBUG: %s - %s" % (variable, Temp)
                        #print capabilityMap
-                       if Temp == "app" or Temp == "location":
+                       #print "DEBUG: location variable: %s" % Temp    
+                       if Temp == "app" or Temp == "location" or Temp == "mode" or Temp == "sunset" or Temp == "sunrise" or Temp == "sunsetTime" or Temp == "sunriseTime":
                                if Temp not in eventList:
                                        eventList.append(Temp)
                                        if (appName == "App1"):
@@ -241,7 +255,9 @@ def AnalyzePhysicalInteraction(app1Capab, app2Capab):
 def CountEvents():
        global eventList
        numOfActualEvents = 0
+       #print "DEBUG: eventlist: %d" % len(eventList)
        for event in eventList:
+               #print "DEBUG: Event: %s %d" % (event, eventTypeCounterMap[event])
                numOfActualEvents = numOfActualEvents + eventTypeCounterMap[event]
        return numOfActualEvents
 
@@ -264,7 +280,7 @@ def ExtractEvents(extractedEvents):
        #print "DEBUG: App2: %d" % indexApp2
        #print "DEBUG: eventList: %d" % len(eventList)
        isApp1 = True
-       while counter < len(eventList):
+       while counter < numOfActualEvents:
                # Interleave events from App1 and App2
                if isApp1 is True:
                        i = indexApp1
@@ -276,7 +292,7 @@ def ExtractEvents(extractedEvents):
                        indexApp2 = indexApp2 + 1
                        if indexApp1 < indexApp2Start:
                                isApp1 = True
-               print "DEBUG: i: %d" % i
+               #print "DEBUG: i: %d" % i
                extractedEvents.write("\t\tcase %d:\n" % counter)
                if eventList[i] == "lock":
                        #Write two events subsequently
@@ -328,15 +344,30 @@ def ExtractEvents(extractedEvents):
                                extractedEvents.write(line)
                        event.close()
                elif eventList[i] == "button":
+                       #Check which capability
+                       variable = eventVarMap[eventList[i]]
+                       if eventList[i] not in eventVarCounterMap.keys():
+                               eventVarCounterMap[eventList[i]] = 1
+                               eventVarCount = 0
+                       else:
+                               eventVarCount = eventVarCounterMap[eventList[i]]
+                               eventVarCounterMap[eventList[i]] = eventVarCount + 1
+                       capability = capabilityMap[variable[eventVarCount]]
                        #Write two events subsequently
-                       event = open("eventSimulator/buttonPushedEvent.groovy", "r")                    
+                       if capability == "capability.button":
+                               event = open("eventSimulator/buttonHeldEvent.groovy", "r")
+                       elif capability == "device.aeonKeyFob":
+                               event = open("eventSimulator/aeonKeyFobHeldEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
                        extractedEvents.write("\n\t\t\tbreak\n")
                        counter = counter + 1
                        extractedEvents.write("\t\tcase %d:\n" % counter)
-                       event = open("eventSimulator/buttonHeldEvent.groovy", "r")
+                       if capability == "capability.button":
+                               event = open("eventSimulator/buttonPushedEvent.groovy", "r")
+                       elif capability == "device.aeonKeyFob":
+                               event = open("eventSimulator/aeonKeyFobPushedEvent.groovy", "r")
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
@@ -803,6 +834,26 @@ def ExtractEvents(extractedEvents):
                        for line in event:
                                extractedEvents.write(line)
                        event.close()
+               elif eventList[i] == "sunrise":
+                       event = open("eventSimulator/locationSunriseEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventList[i] == "sunset":
+                       event = open("eventSimulator/locationSunsetEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventList[i] == "sunsetTime":
+                       event = open("eventSimulator/locationSunsetTimeEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
+               elif eventList[i] == "sunriseTime":
+                       event = open("eventSimulator/locationSunriseTimeEvent.groovy", "r")
+                       for line in event:
+                               extractedEvents.write(line)
+                       event.close()
                elif eventList[i] == "acceleration":
                        #Write two events subsequently
                        event = open("eventSimulator/accelerationActiveEvent.groovy", "r")                      
index 5a27540..a13030a 100644 (file)
@@ -26,10 +26,10 @@ public class Switches {
                this.deviceNumbers = deviceNumbers
                this.switches = []
 
-               /*def initLevel = Verify.getIntFromList(30, 50, 70)
+               def initLevel = Verify.getIntFromList(30, 50, 70)
                this.currentLevel = initLevel
                def init = Verify.getBoolean()
-               if (init) {
+               /*if (init) {
                        this.switchState = "off"
                        this.currentSwitch = "off"
                        this.switchLatestValue = "off"
index 24bd7bf..ccd8e96 100644 (file)
@@ -38,6 +38,16 @@ public class SwitchLevel {
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
+       
+       def setLevel(long level) {
+               if (this.level != level) {
+                       println("the switch with id:$id is setted to level $level!")
+                       this.level = level
+                       this.rate = level
+                       sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
+       }
 
        def on() {
                if (this.switchState != "on") {
index 1bae6a1..6ceaf8f 100644 (file)
@@ -17,9 +17,9 @@ public class SwitchLevels {
        private String displayName = "switchLevel0"
        private int level = 50
        private int rate = 50
-       private String switchState = "off"
-       private String currentSwitch = "off"
-       private String switchLatestValue = "off"
+       private String switchState = "on"
+       private String currentSwitch = "on"
+       private String switchLatestValue = "on"
 
        SwitchLevels(Closure sendEvent, int deviceNumbers) {
                this.sendEvent = sendEvent
@@ -70,6 +70,14 @@ public class SwitchLevels {
                        this.rate = level
                }
        }
+       
+       def setLevel(long level) {
+               if (this.level != level) {
+                       switchLevels[0].setLevel(level)
+                       this.level = level
+                       this.rate = level
+               }
+       }
 
        def on() {
                switchLatestValue = "on"
diff --git a/eventSimulator/aeonKeyFobHeldEvent.groovy b/eventSimulator/aeonKeyFobHeldEvent.groovy
new file mode 100644 (file)
index 0000000..3937ff6
--- /dev/null
@@ -0,0 +1,2 @@
+                       aeonKeyFobObject.setValue([name: "button", value: "held", deviceId: "aeonKeyFobID0", descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
diff --git a/eventSimulator/aeonKeyFobPushedEvent.groovy b/eventSimulator/aeonKeyFobPushedEvent.groovy
new file mode 100644 (file)
index 0000000..889af89
--- /dev/null
@@ -0,0 +1,2 @@
+                       aeonKeyFobObject.setValue([name: "button", value: "pushed", deviceId: "aeonKeyFobID0", descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
index 3937ff6..29d13a0 100644 (file)
@@ -1,2 +1,2 @@
-                       aeonKeyFobObject.setValue([name: "button", value: "held", deviceId: "aeonKeyFobID0", descriptionText: "",
-                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                       buttonObject.setValue([name: "button", value: "held", deviceId: "switchID0", descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"buttonNumber": 1}'])
index 889af89..6f1a8c6 100644 (file)
@@ -1,2 +1,2 @@
-                       aeonKeyFobObject.setValue([name: "button", value: "pushed", deviceId: "aeonKeyFobID0", descriptionText: "",
-                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                       buttonObject.setValue([name: "button", value: "push", deviceId: "switchID0", descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"buttonNumber": 1}'])
diff --git a/eventSimulator/locationSunriseEvent.groovy b/eventSimulator/locationSunriseEvent.groovy
new file mode 100644 (file)
index 0000000..df4a7cd
--- /dev/null
@@ -0,0 +1,2 @@
+                       locationObject.setValue([name: "sunrise", value: "sunrise", deviceId: "locationID0", descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
diff --git a/eventSimulator/locationSunriseTimeEvent.groovy b/eventSimulator/locationSunriseTimeEvent.groovy
new file mode 100644 (file)
index 0000000..e70070c
--- /dev/null
@@ -0,0 +1,2 @@
+                       locationObject.setValue([name: "sunriseTime", value: "sunriseTime", deviceId: "locationID0", descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
diff --git a/eventSimulator/locationSunsetEvent.groovy b/eventSimulator/locationSunsetEvent.groovy
new file mode 100644 (file)
index 0000000..1852b78
--- /dev/null
@@ -0,0 +1,2 @@
+                       locationObject.setValue([name: "sunset", value: "sunset", deviceId: "locationID0", descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
diff --git a/eventSimulator/locationSunsetTimeEvent.groovy b/eventSimulator/locationSunsetTimeEvent.groovy
new file mode 100644 (file)
index 0000000..b3f3596
--- /dev/null
@@ -0,0 +1,2 @@
+                       locationObject.setValue([name: "sunsetTime", value: "sunsetTime", deviceId: "locationID0", descriptionText: "",
+                                       displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])