Adjusting setLocationMode for global-variable conflict detection.
[smartthings-infrastructure.git] / Extractor / Extractor.groovy
index 16038e3b078f450b6f02b7e9b7d182de96ad8751..4607b7c89cd7916f2848fcbd776cd788fa792cec 100644 (file)
@@ -81,7 +81,7 @@ import Momentary.Momentaries
 import Timer.SimulatedTimer
 
 //GlobalVariables
-@Field def location = new LocationVar()
+@Field def location = new LocationVar({}, true)
 //Settings variable defined to settings on purpose
 @Field def settings = [app: "app"]
 //Global variable for state[mode]
@@ -402,6 +402,8 @@ def input(LinkedHashMap metaData, String name, String type, Closure Input) {
        find(Input)
 }
 
+@Field chooseMode = 0
+
 //input linkedHashMap
 def input(LinkedHashMap metaData) {
        if (metaData.containsKey('title')) {
@@ -1639,7 +1641,13 @@ def input(LinkedHashMap metaData) {
                case "mode":
                        //def randomVariable = Math.abs(new Random().nextInt() % 3)
                        def modes = ["away", "home", "night"]
-                       def userInput = modes[1]
+                       // Always assign a different mode to each app
+                       //def userInput = modes[1]
+                       def userInput = modes[chooseMode]
+                       if (chooseMode < 3)
+                               chooseMode++;
+                       else
+                               chooseMode = chooseMode%3
 
                        if (modeVariables == 0) {
                                mode0 = metaData['name']
@@ -2105,7 +2113,7 @@ def preferences(Closure inputData) {
                GlobalVariablesBothApps.write("")
                GlobalVariablesBothApps.append("//Creating Global variables for both apps\n")
                GlobalVariablesBothApps.append("@Field def sendEvent = {eventDataMap -> eventHandler(eventDataMap)}\n")
-               GlobalVariablesBothApps.append("@Field def locationObject = new LocationVar(sendEvent)\n")
+               GlobalVariablesBothApps.append("@Field def locationObject = new LocationVar(sendEvent, init)\n")
                GlobalVariablesBothApps.append("@Field def appObject = new Touched(sendEvent, 0)\n")
                
                globalObjects.withReader { reader ->