Adding a feature to extract scheduled method as an event when it is scheduled inside...
[smartthings-infrastructure.git] / Extractor / ExtractorScript.py
index 5f18f9f80a8bb61db3f1ff60b1d6c4f5803f3590..e3947bcea00246461b50bb5e39ce58c72eafc579 100644 (file)
@@ -68,6 +68,7 @@ eventTypeCounterMap =  {'lock': 2,
                                                'shock': 1,
                                                'lqi': 1,
                                                'rssi': 1,
+                                               'schedule': 1,
                                                'sound': 1,
                                                'soundPressureLevel' : 1,
                                                'tamper' : 1,
@@ -189,6 +190,31 @@ def ExtractFunctions(F, appName):
                                        extractedFunctionsApp2.write("def %s = this.&" % NameofFunc)
                                        extractedFunctionsApp2.write("%s\n" % NameofFunc)
                
+               #Check subscribed events
+               if (Temp == "initialize" or Temp == "installed"):
+                       Temp = GetToken(F)
+                       Temp = GetToken(F)
+                       Temp = GetToken(F)
+                       # If it is a schedule function, then extract the scheduled method and put it as one of the events
+                       if (Temp == "schedule"):
+                               eventList.append("schedule")
+                               if (appName == "App1"):
+                                       eventAppList.append("App1")
+                               else:
+                                       eventAppList.append("App2")
+                               while Temp != ",":
+                                       Temp = GetToken(F)
+                               Temp = GetToken(F)
+                               # If this is a " then get the next one still---we are interested in the scheduled function name
+                               if (Temp == "\""):
+                                       Temp = GetToken(F)
+                               # Insert function name into the map
+                               if "schedule" in eventVarMap.keys():
+                                       listOfEvents = eventVarMap["schedule"]
+                                       listOfEvents.append(Temp)
+                               else:
+                                       eventVarMap["schedule"] = [Temp]
+               
                #Check input capability
                if (Temp == "input"):
                        while Temp != "\"":
@@ -229,9 +255,9 @@ def ExtractFunctions(F, appName):
                        #print capabilityMap
                        #print "DEBUG: location variable: %s" % Temp    
 
-                        #This is a bogus event, just skip it...
-                        if Temp == "unlock":
-                                continue                        
+            #This is a bogus event, just skip it...
+                       if Temp == "unlock":
+                               continue                        
                        #Translate and reduce through mapping
                        if Temp in eventTypesMap.keys():                
                                Temp = eventTypesMap[Temp]
@@ -356,6 +382,8 @@ def ExtractEvents(extractedEvents):
        #print "DEBUG: App1: %d" % indexApp1
        #print "DEBUG: App2: %d" % indexApp2
        #print "DEBUG: eventList: %d" % len(eventList)
+       #print capabilityMap
+       #print eventVarMap
        #print eventAppList
        #print eventList
        if indexApp2Start > 0:
@@ -376,7 +404,18 @@ def ExtractEvents(extractedEvents):
                                isApp1 = True
                #print "DEBUG: i: %d" % i
                extractedEvents.write("\t\tcase %d:\n" % counter)
-               if eventList[i] == "lock":
+               if eventList[i] == "schedule":
+                       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
+                       currentMethod = variable[eventVarCount]
+                       extractedEvents.write("\t\t\t// Scheduled method in installed() or intialize()\n")
+                       extractedEvents.write("\t\t\t%s.%s()" % (eventAppList[i].lower(), currentMethod))
+               elif eventList[i] == "lock":
                        #Write two events subsequently
                        event = open("eventSimulator/lockLockedEvent.groovy", "r")                      
                        for line in event: