Adding sunset and sunrise events.
[smartthings-infrastructure.git] / Extractor / ExtractorScript.py
index 37c294decf2823615df580ceda7af4dfe7c76cb8..bd7a320e6726a38726a7d6d864a66dc0b6c281b1 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")