From: amiraj Date: Tue, 23 Jul 2019 22:58:27 +0000 (-0700) Subject: Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=16ebbcf5da0fa9989acb5b03129b9706331066c5;p=smartthings-infrastructure.git Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure --- 16ebbcf5da0fa9989acb5b03129b9706331066c5 diff --cc Extractor/ExtractorScript.py index 38124be,4551ca0..d4b26d2 --- a/Extractor/ExtractorScript.py +++ b/Extractor/ExtractorScript.py @@@ -53,6 -51,7 +53,7 @@@ def ExtractFunctions(F, appName) extractedFunctionsApp2.write("//Global Object for functions in subscribe method!\n") extractedFunctionsApp2.write("def %s = this.&" % NameofFunc) extractedFunctionsApp2.write("%s\n" % NameofFunc) - ++ #Check subscribed events if (Temp == "subscribe"): counter = 0 @@@ -75,143 -74,142 +76,276 @@@ AnalyzePhysicalInteraction(app1Capabilities, app2Capabilities) AnalyzePhysicalInteraction(app2Capabilities, app1Capabilities) - + +def AnalyzeCapabilities(Temp, appName): + #Illuminance related + if (Temp == "capability.switch" or + Temp == "capability.switchLevel" or + Temp == "capability.illuminanceMeasurement" or + #Motion related + Temp == "capability.motionSensor" or + #Water related + Temp == "capability.valve" or + Temp == "capability.waterSensor" or + #Sound related + Temp == "capability.musicPlayer" or + Temp == "capability.alarm" or + Temp == "capability.speechSynthesis" or + Temp == "capability.soundSensor"): + if (appName == "App1"): + app1Capabilities.append(Temp) + else: + app2Capabilities.append(Temp) + +def AnalyzePhysicalInteraction(app1Capab, app2Capab): + #Light + if ("capability.illuminanceMeasurement" in app1Capab) and ("capability.switch" in app2Capab or + "capability.switchLevel" in app2Capab): + print ("\nWARNING: Potential PHYSICAL CONFLICT (light) detected between App1 and App2!\n") + #Motion + if ("capability.motionSensor" in app1Capab): + print ("\nWARNING: Potential PHYSICAL CONFLICT (motion) detected between App1 and App2!\n") + #Water + if ("capability.waterSensor" in app1Capab) and ("capability.valve" in app2Capab or + "capability.switch" in app2Capab): + print ("\nWARNING: Potential PHYSICAL CONFLICT (water) detected between App1 and App2!\n") + #Sound + if ("capability.soundSensor" in app1Capab) and ("capability.musicPlayer" in app2Capab or + "capability.alarm" in app2Capab or "capability.speechSynthesis" in app2Capab): + print ("\nWARNING: Potential PHYSICAL CONFLICT (sound) detected between App1 and App2!\n") + +def ExtractEvents(extractedEvents): + global eventMap + extractedEvents.write("Random random = new Random(42)\n") + extractedEvents.write("counter = 1000\n") + extractedEvents.write("while(counter > 0) {\n") + extractedEvents.write("\tdef eventNumber = random.nextInt(%d)\n" % (len(eventMap) - 1)) + extractedEvents.write("\tswitch(eventNumber) {\n") + eventCounter = 0; + for i in range(len(eventMap)): + extractedEvents.write("\t\tcase %d:\n" % eventCounter) + if eventMap[i] == "lock": + event = open("eventSimulator/lockEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "unlock": + event = open("eventSimulator/unlockEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "contact.open": + event = open("eventSimulator/contactOpenEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "contact.closed": + event = open("eventSimulator/contactClosedEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "switch.on": + event = open("eventSimulator/switchOnEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "switch.off": + event = open("eventSimulator/switchOffEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "nfcTouch": + event = open("eventSimulator/nfcTouchEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "Touched": + event = open("eventSimulator/appTouchEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "button": + #Write two events subsequently + event = open("eventSimulator/buttonPushedEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + extractedEvents.write("\t\t\tbreak\n") + eventCounter = eventCounter + 1 + extractedEvents.write("\t\tcase %d:\n" % eventCounter) + event = open("eventSimulator/buttonHeldEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "presence": + #Write two events subsequently + event = open("eventSimulator/presencePresentEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + extractedEvents.write("\t\t\tbreak\n") + eventCounter = eventCounter + 1 + extractedEvents.write("\t\tcase %d:\n" % eventCounter) + event = open("eventSimulator/presenceLeftEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "doorState": + #Write two events subsequently + event = open("eventSimulator/doorOpenEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + extractedEvents.write("\t\t\tbreak\n") + eventCounter = eventCounter + 1 + extractedEvents.write("\t\tcase %d:\n" % eventCounter) + event = open("eventSimulator/doorClosedEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + eventCounter = eventCounter + 1 + + ###TODO: Add more events later + extractedEvents.write("\n\t\t\tbreak\n") + extractedEvents.write("\t}\n") + extractedEvents.write("\tcounter--\n") + extractedEvents.write("}\n") - + + def AnalyzeCapabilities(Temp, appName): + #Illuminance related + if (Temp == "capability.switch" or + Temp == "capability.switchLevel" or + Temp == "capability.illuminanceMeasurement" or + #Motion related + Temp == "capability.motionSensor" or + #Water related + Temp == "capability.valve" or + Temp == "capability.waterSensor" or + #Sound related + Temp == "capability.musicPlayer" or + Temp == "capability.alarm" or + Temp == "capability.speechSynthesis" or + Temp == "capability.soundSensor"): + if (appName == "App1"): + app1Capabilities.append(Temp) + else: + app2Capabilities.append(Temp) + + def AnalyzePhysicalInteraction(app1Capab, app2Capab): + #Light + if ("capability.illuminanceMeasurement" in app1Capab) and ("capability.switch" in app2Capab or + "capability.switchLevel" in app2Capab): + print ("\nWARNING: Potential PHYSICAL CONFLICT (light) detected between App1 and App2!\n") + #Motion + if ("capability.motionSensor" in app1Capab): + print ("\nWARNING: Potential PHYSICAL CONFLICT (motion) detected between App1 and App2!\n") + #Water + if ("capability.waterSensor" in app1Capab) and ("capability.valve" in app2Capab or + "capability.switch" in app2Capab): + print ("\nWARNING: Potential PHYSICAL CONFLICT (water) detected between App1 and App2!\n") + #Sound + if ("capability.soundSensor" in app1Capab) and ("capability.musicPlayer" in app2Capab or + "capability.alarm" in app2Capab or "capability.speechSynthesis" in app2Capab): + print ("\nWARNING: Potential PHYSICAL CONFLICT (sound) detected between App1 and App2!\n") + + def ExtractEvents(extractedEvents): + global eventMap + extractedEvents.write("Random random = new Random(42)\n") + extractedEvents.write("counter = 1000\n") + extractedEvents.write("while(counter > 0) {\n") + extractedEvents.write("\tdef eventNumber = random.nextInt(%d)\n" % (len(eventMap) - 1)) + extractedEvents.write("\tswitch(eventNumber) {\n") + eventCounter = 0; + for i in range(len(eventMap)): + extractedEvents.write("\t\tcase %d:\n" % eventCounter) + if eventMap[i] == "lock": + event = open("eventSimulator/lockEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "unlock": + event = open("eventSimulator/unlockEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "contact.open": + event = open("eventSimulator/contactOpenEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "contact.closed": + event = open("eventSimulator/contactClosedEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "switch.on": + event = open("eventSimulator/switchOnEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "switch.off": + event = open("eventSimulator/switchOffEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "nfcTouch": + event = open("eventSimulator/nfcTouchEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "Touched": + event = open("eventSimulator/appTouchEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "button": + #Write two events subsequently + event = open("eventSimulator/buttonPushedEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + extractedEvents.write("\t\t\tbreak\n") + eventCounter = eventCounter + 1 + extractedEvents.write("\t\tcase %d:\n" % eventCounter) + event = open("eventSimulator/buttonHeldEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "presence": + #Write two events subsequently + event = open("eventSimulator/presencePresentEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + extractedEvents.write("\t\t\tbreak\n") + eventCounter = eventCounter + 1 + extractedEvents.write("\t\tcase %d:\n" % eventCounter) + event = open("eventSimulator/presenceLeftEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + elif eventMap[i] == "doorState": + #Write two events subsequently + event = open("eventSimulator/doorOpenEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + extractedEvents.write("\t\t\tbreak\n") + eventCounter = eventCounter + 1 + extractedEvents.write("\t\tcase %d:\n" % eventCounter) + event = open("eventSimulator/doorClosedEvent.groovy", "r") + for line in event: + extractedEvents.write(line) + event.close() + eventCounter = eventCounter + 1 + + ###TODO: Add more events later + extractedEvents.write("\n\t\t\tbreak\n") + extractedEvents.write("\t}\n") + extractedEvents.write("\tcounter--\n") + extractedEvents.write("}\n") + #Extract objects to call functions from App1 F1 = open("Extractor/App1/App1.groovy", "r") extractedFunctionsApp1 = open("Extractor/App1/extractedFunctionsApp1.groovy", "w+") diff --cc eventSimulator/eventSimulator.groovy index 56b32b7,0000000..6d62806 mode 100644,000000..100644 --- a/eventSimulator/eventSimulator.groovy +++ b/eventSimulator/eventSimulator.groovy @@@ -1,45 -1,0 +1,18 @@@ - def events = [1,2,3,4,5,6,7] - def list = events.permutations() - int count = Verify.getInt(0,list.size()-1) - println "COUNT: " + count ++Random random = new Random(42) ++counter = 1000 ++while(counter > 0) { ++ def eventNumber = random.nextInt(1) ++ switch(eventNumber) { ++ case 0: ++ appObject.setValue([name: "Touched", value: "Touched", deviceId: 0, descriptionText: "", ++ displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) + - list[count].each { - switch(it) { - case 1: - appObject.setValue([name: "Touched", value: "Touched", deviceId: 0, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) - println "1" - break - case 2: - lockObject.setValue([name: "lock0", value: "locked", deviceId: 0, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) - println " 2" + break - case 3: - lockObject.setValue([name: "lock0", value: "unlocked", deviceId: 0, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) - println " 3" - break - case 4: - contactObject.setValue([name: "contact0", value: "open", deviceId: 0, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) - println " 4" - break - case 5: - contactObject.setValue([name: "contact0", value: "closed", deviceId: 0, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) - println " 5" - break - case 6: - switchObject.setValue([name: "switch0", value: "on", deviceId: 0, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) - println " 6" - break - case 7: - switchObject.setValue([name: "switch0", value: "off", deviceId: 0, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) - println " 7" - default: - break - } ++ case 1: ++ appObject.setValue([name: "nfcTouch", value: "Touched", deviceId: 0, descriptionText: "", ++ displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "Touched"]]) ++ ++ break ++ } ++ counter-- +} diff --cc main.groovy index 1d6af3c,5460511..b28d935 --- a/main.groovy +++ b/main.groovy @@@ -770,13 -650,48 +770,13 @@@ class App2 app1.installed() app2.installed() - appObject.setValue([name: "Touched", value: "touched", deviceId: "touchedSensorID0", descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]]) -def events = [1,2,3,4,5,6,7] -def list = events.permutations() -int count = Verify.getInt(0,list.size()-1) -println "COUNT: " + count - -list[count].each { - switch(it) { - case 1: - appObject.setValue([name: "Touched", value: "Touched", deviceId: 0, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) - println "1" - break - case 2: - lockObject.setValue([name: "lock0", value: "locked", deviceId: 0, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) - println " 2" - break - case 3: - lockObject.setValue([name: "lock0", value: "unlocked", deviceId: 0, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) - println " 3" - break - case 4: - contactObject.setValue([name: "contact0", value: "open", deviceId: 0, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) - println " 4" - break - case 5: - contactObject.setValue([name: "contact0", value: "closed", deviceId: 0, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) - println " 5" - break - case 6: - switchObject.setValue([name: "switch0", value: "on", deviceId: 0, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) - println " 6" - break - case 7: - switchObject.setValue([name: "switch0", value: "off", deviceId: 0, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) - println " 7" - default: - break - } -} +appObject.setValue([name: "nfcTouch", value: "touched", deviceId: "nfcSensorID0", descriptionText: "", +displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]]) ++appObject.setValue([name: "Touched", value: "touched", deviceId: "touchedSensorID0", descriptionText: "", ++displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]]) +locationObject.setValue([name: "Location", value: "away", deviceId: "locationID0", descriptionText: "", +displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]]) +locationObject.setValue([name: "Location", value: "home", deviceId: "locationID0", descriptionText: "", +displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]]) +locationObject.setValue([name: "Location", value: "night", deviceId: "locationID0", descriptionText: "", +displayed: true, linkText: "", isStateChange: false, unit: "", data: [info: "info"]])