Add support for values to subscribe function
authorbdemsky <bdemsky@uci.edu>
Wed, 7 Aug 2019 02:24:54 +0000 (19:24 -0700)
committerbdemsky <bdemsky@uci.edu>
Wed, 7 Aug 2019 02:24:54 +0000 (19:24 -0700)
Extractor/ExtractorScript.py
GlobalVariables/GlobalVariablesEachApp.groovy
Methods/subscribe.groovy

index 1172b4e..63f0111 100644 (file)
@@ -15,7 +15,6 @@ app2Subscribe = False
 # Mapping for event type and number of events
 # e.g., switch has 2 events: on and off
 eventTypeCounterMap =  {'lock': 2,
-                                               'unlock' : 1,
                                                'nfcTouch' : 1,
                                                'app' : 1,
                                                'button' : 2,
@@ -76,7 +75,6 @@ eventTypesMap =          {'alarm.both': 'alarm',
                                                'mode.away' : 'location',
                                                'mode.home' : 'location',
                                                'mode.night' : 'location',
-                                               'unlock' : 'lock',
                                                'lock.locked' : 'lock',
                                                'lock.unlocked' : 'lock',
                                                'motion.active' : 'motion',
@@ -214,7 +212,10 @@ def ExtractFunctions(F, appName):
                        #print "DEBUG: %s - %s" % (variable, Temp)
                        #print capabilityMap
                        #print "DEBUG: location variable: %s" % Temp    
-                       
+
+                        #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]
index ba78f98..f0e6cc7 100644 (file)
@@ -8,6 +8,7 @@ def functionList = new ArrayList(20)
 def objectList = new ArrayList(20)
 //Create a global variable for Events in Subscribe method
 def eventList = new ArrayList(20)
+def valueList = new ArrayList(20)
 //Create a global variable for settings
 def settings
 //Zip code
index f2dfb56..b60cb45 100644 (file)
@@ -4,185 +4,64 @@ def subscribe(Object obj, Closure FunctionToCall) {
        if (obj == app) {
                objectList.add(obj)
                eventList.add("Touched")
+                valueList.add("")
                functionList.add(FunctionToCall)
        } else if (obj == location) {
                objectList.add(obj)
                eventList.add("Location")
+                valueList.add("")
                functionList.add(FunctionToCall)
        }
 }
+
 ////subscribe(obj, event, func)
 def subscribe(Object obj, String event, Closure FunctionToCall) {
-       if ((event == "alarm.both")||(event == "alarm.siren")||(event == "alarm.strobe")||(event == "alarm.off")||(event == "alarm")) {
-               objectList.add(obj)
-               eventList.add("alarm")
-               functionList.add(FunctionToCall)
-       } else if ((event == "contact.open")||(event == "contact.closed")||(event == "contact")||(event == "tamper.tampered")) {
-               objectList.add(obj)
-               eventList.add("contact")
-               functionList.add(FunctionToCall)
-       } else if ((event == "doorState.open")||(event == "doorState.closed")||(event == "doorState")) {
-               objectList.add(obj)
-               eventList.add("doorState")
-               functionList.add(FunctionToCall)
-       } else if ((event == "mode")||(event == "mode.away")||(event == "mode.home")||(event == "mode.night")) {
-               objectList.add(obj)
-               eventList.add("Location")
-               functionList.add(FunctionToCall)
-       } else if ((event == "lock.locked")||(event == "lock.unlocked")||(event == "lock")||(event == "unlock")) {
-               objectList.add(obj)
-               eventList.add("lock")
-               functionList.add(FunctionToCall)
-       } else if ((event == "motion.active")||(event == "motion.inactive")||(event == "motion")) {
-               objectList.add(obj)
-               eventList.add("motion")
-               functionList.add(FunctionToCall)
-       } else if ((event == "status")||(event == "status.playing")||(event == "status.stopped")||(event == "status.paused")) {
-               objectList.add(obj)
-               eventList.add("status")
-               functionList.add(FunctionToCall)
-       } else if ((event == "mute")||(event == "mute.muted")||(event == "mute.unmuted")) {
-               objectList.add(obj)
-               eventList.add("mute")
-               functionList.add(FunctionToCall)
-       } else if ((event == "presence")||(event == "presence.present")||(event == "presence.not present")) {
-               objectList.add(obj)
-               eventList.add("presence")
-               functionList.add(FunctionToCall)
-       } else if ((event == "smoke")||(event == "smoke.detected")||(event == "smoke.clear")||(event == "smoke.tested")) {
-               objectList.add(obj)
-               eventList.add("smoke")
-               functionList.add(FunctionToCall)
-       } else if ((event == "carbonMonoxide")||(event == "carbonMonoxide.detected")||(event == "carbonMonoxide.clear")||(event == "carbonMonoxide.tested")) {
-               objectList.add(obj)
-               eventList.add("carbonMonoxide")
-               functionList.add(FunctionToCall)
-       } else if ((event == "thermostatMode")||(event == "thermostatMode.cool")||(event == "thermostatMode.auto")||(event == "thermostatMode.emergencyHeat")||(event == "thermostatMode.heat")||(event == "thermostatMode.off")) {
-               objectList.add(obj)
-               eventList.add("thermostatMode")
-               functionList.add(FunctionToCall)
-       } else if ((event == "thermostatFanMode")||(event == "thermostatFanMode.auto")||(event == "thermostatFanMode.fanCirculate")||(event == "thermostatFanMode.circulate")||(event == "thermostatFanMode.fanOn")||(event == "thermostatFanMode.on")
-                  ||(event == "fanMode")||(event == "fanMode.auto")||(event == "fanMode.fanCirculate")||(event == "fanMode.circulate")||(event == "fanMode.fanOn")||(event == "fanMode.on")) {
-               objectList.add(obj)
-               eventList.add("thermostatFanMode")
-               functionList.add(FunctionToCall)
-       } else if ((event == "thermostatOperatingState")||(event == "thermostatOperatingState.cooling")||(event == "thermostatOperatingState.fan only")||(event == "thermostatOperatingState.heating")||(event == "thermostatOperatingState.idle")
-                  ||(event == "thermostatOperatingState.pending cool")||(event == "thermostatOperatingState.pending heat")||(event == "thermostatOperatingState.vent economizer")) {
-               objectList.add(obj)
-               eventList.add("thermostatOperatingState")
-               functionList.add(FunctionToCall)
-       } else if ((event == "switch")||(event == "switch.on")||(event == "switch.off")) {
-               objectList.add(obj)
-               eventList.add("switch")
-               functionList.add(FunctionToCall)
-       } else if ((event == "button")||(event == "button.pushed")||(event == "button.held")) {
-               objectList.add(obj)
-               eventList.add("button")
-               functionList.add(FunctionToCall)
-       } else if ((event == "acceleration")||(event == "acceleration.active")||(event == "acceleration.inactive")) {
-               objectList.add(obj)
-               eventList.add("acceleration")
-               functionList.add(FunctionToCall)
-       } else if ((event == "sleeping")||(event == "sleeping.sleeping")||(event == "sleeping.not sleeping")) {
-               objectList.add(obj)
-               eventList.add("sleeping")
-               functionList.add(FunctionToCall)
-       } else if ((event == "water")||(event == "water.dry")||(event == "water.wet")) {
-               objectList.add(obj)
-               eventList.add("water")
-               functionList.add(FunctionToCall)
-       } else {
-               objectList.add(obj)
-               eventList.add(event)
-               functionList.add(FunctionToCall)
-       }
+    if (event == "tamper.tampered") {
+       event = "contact"      //This really should be its own name
+    } else if ((event == "mode")||(event == "mode.away")||(event == "mode.home")||(event == "mode.night")) {
+       //This really should be fixed also...
+       event = "Location"
+    }       
+    
+    int dot = event.indexOf('.')
+    String name = ""
+    String value = ""
+    if (dot != -1) {
+      name = event.substring(0, dot)
+      value = event.substring(dot + 1)
+    } else {
+      name = event
+    }
+
+    objectList.add(obj)
+    eventList.add(name)
+    functionList.add(FunctionToCall)
+    valueList.add(value)
 }
 ////subscribe(obj, event, nameOfFunc)
 def subscribe(Object obj, String event, String FunctionToCall) {
-       if ((event == "alarm.both")||(event == "alarm.siren")||(event == "alarm.strobe")||(event == "alarm.off")||(event == "alarm")) {
-               objectList.add(obj)
-               eventList.add("alarm")
-               functionList.add(FunctionToCall)
-       } else if ((event == "contact.open")||(event == "contact.closed")||(event == "contact")||(event == "tamper.tampered")) {
-               objectList.add(obj)
-               eventList.add("contact")
-               functionList.add(FunctionToCall)
-       } else if ((event == "doorState.open")||(event == "doorState.closed")||(event == "doorState")) {
-               objectList.add(obj)
-               eventList.add("doorState")
-               functionList.add(FunctionToCall)
-       } else if ((event == "mode")||(event == "mode.away")||(event == "mode.home")||(event == "mode.night")) {
-               objectList.add(obj)
-               eventList.add("Location")
-               functionList.add(FunctionToCall)
-       } else if ((event == "lock.locked")||(event == "lock.unlocked")||(event == "lock")) {
-               objectList.add(obj)
-               eventList.add("lock")
-               functionList.add(FunctionToCall)
-       } else if ((event == "motion.active")||(event == "motion.inactive")||(event == "motion")) {
-               objectList.add(obj)
-               eventList.add("motion")
-               functionList.add(FunctionToCall)
-       } else if ((event == "status")||(event == "status.playing")||(event == "status.stopped")||(event == "status.paused")) {
-               objectList.add(obj)
-               eventList.add("status")
-               functionList.add(FunctionToCall)
-       } else if ((event == "mute")||(event == "mute.muted")||(event == "mute.unmuted")) {
-               objectList.add(obj)
-               eventList.add("mute")
-               functionList.add(FunctionToCall)
-       } else if ((event == "presence")||(event == "presence.present")||(event == "presence.not present")) {
-               objectList.add(obj)
-               eventList.add("presence")
-               functionList.add(FunctionToCall)
-       } else if ((event == "smoke")||(event == "smoke.detected")||(event == "smoke.clear")||(event == "smoke.tested")) {
-               objectList.add(obj)
-               eventList.add("smoke")
-               functionList.add(FunctionToCall)
-       } else if ((event == "carbonMonoxide")||(event == "carbonMonoxide.detected")||(event == "carbonMonoxide.clear")||(event == "carbonMonoxide.tested")) {
-               objectList.add(obj)
-               eventList.add("carbonMonoxide")
-               functionList.add(FunctionToCall)
-       } else if ((event == "thermostatMode")||(event == "thermostatMode.cool")||(event == "thermostatMode.auto")||(event == "thermostatMode.emergencyHeat")||(event == "thermostatMode.heat")||(event == "thermostatMode.off")) {
-               objectList.add(obj)
-               eventList.add("thermostatMode")
-               functionList.add(FunctionToCall)
-       } else if ((event == "thermostatFanMode")||(event == "thermostatFanMode.auto")||(event == "thermostatFanMode.fanCirculate")||(event == "thermostatFanMode.circulate")||(event == "thermostatFanMode.fanOn")||(event == "thermostatFanMode.on")
-                  ||(event == "fanMode")||(event == "fanMode.auto")||(event == "fanMode.fanCirculate")||(event == "fanMode.circulate")||(event == "fanMode.fanOn")||(event == "fanMode.on")) {
-               objectList.add(obj)
-               eventList.add("thermostatFanMode")
-               functionList.add(FunctionToCall)
-       } else if ((event == "thermostatOperatingState")||(event == "thermostatOperatingState.cooling")||(event == "thermostatOperatingState.fan only")||(event == "thermostatOperatingState.heating")||(event == "thermostatOperatingState.idle")
-                  ||(event == "thermostatOperatingState.pending cool")||(event == "thermostatOperatingState.pending heat")||(event == "thermostatOperatingState.vent economizer")) {
-               objectList.add(obj)
-               eventList.add("thermostatOperatingState")
-               functionList.add(FunctionToCall)
-       } else if ((event == "switch")||(event == "switch.on")||(event == "switch.off")) {
-               objectList.add(obj)
-               eventList.add("switch")
-               functionList.add(FunctionToCall)
-       } else if ((event == "button")||(event == "button.pushed")||(event == "button.held")) {
-               objectList.add(obj)
-               eventList.add("button")
-               functionList.add(FunctionToCall)
-       } else if ((event == "acceleration")||(event == "acceleration.active")||(event == "acceleration.inactive")) {
-               objectList.add(obj)
-               eventList.add("acceleration")
-               functionList.add(FunctionToCall)
-       } else if ((event == "sleeping")||(event == "sleeping.sleeping")||(event == "sleeping.not sleeping")) {
-               objectList.add(obj)
-               eventList.add("sleeping")
-               functionList.add(FunctionToCall)
-       } else if ((event == "water")||(event == "water.dry")||(event == "water.wet")) {
-               objectList.add(obj)
-               eventList.add("water")
-               functionList.add(FunctionToCall)
-       } else {
-               objectList.add(obj)
-               eventList.add(event)
-               functionList.add(FunctionToCall)
-       }
+    if (event == "tamper.tampered") {
+       event = "contact"      //This really should be its own name
+    } else if ((event == "mode")||(event == "mode.away")||(event == "mode.home")||(event == "mode.night")) {
+       event = "Location"
+    }       
+
+    int dot = event.indexOf('.')
+    String name = ""
+    String value = ""
+    if (dot != -1) {
+      name = event.substring(0, dot)
+      value = event.substring(dot + 1)
+    } else {
+      name = event
+    }
+
+    objectList.add(obj)
+    eventList.add(name)
+    functionList.add(FunctionToCall)
+    valueList.add(value)
 }
+
 ////subscribe(obj, event, func, data)
 def subscribe(Object obj, String event, Closure FunctionToCall, LinkedHashMap metaData) {
        subscribe(obj, event, FunctionToCall)