Add changes in events
[smartthings-infrastructure.git] / Location / LocationVar.groovy
old mode 100644 (file)
new mode 100755 (executable)
index 43c88cd..e7328c5
@@ -1,21 +1,75 @@
 //Create a class for location variable
 package Location
+import SmartThing.SmartThing
 
-class LocationVar {
-       private int contactBookEnabled
-       private def modes
-       private String mode
-       private List contacts
-       private List phoneNumbers
-    
-       private Phrase helloHome
-
-       LocationVar() {
-               this.modes = [[name: "home"],[name: "away"],[name: "night"]]
-               this.mode = "home"
-               this.helloHome = new Phrase()
-               this.contactBookEnabled = 1
-               this.contacts = ['AJ']
-               this.phoneNumbers = [9495379373]
+//Importing mutable integer class
+import MutableInteger.MutableInteger
+
+public class LocationVar extends SmartThing {
+       // Features with numberical values
+       MutableInteger contactBookEnabled = new MutableInteger()
+       // Features with string values
+       StringBuilder mode = new StringBuilder()
+       StringBuilder locationMode = mode
+       StringBuilder name = new StringBuilder()
+       StringBuilder temperatureScale = new StringBuilder()
+       // Maps from features to values
+       HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
+       // Other variables
+       Phrase helloHome
+       TimeZone timeZone
+       def modes
+       def hubs
+       List contacts
+       List phoneNumbers
+       
+       LocationVar(Closure sendEvent, boolean init) {
+                       deviceValuesMap = deviceValueSmartThing
+                       sendEventSmartThings = sendEvent
+
+                       // Initialization
+                       StringBuilder sunset = new StringBuilder("sunset")
+                       StringBuilder sunsetTime = sunset
+                       StringBuilder sunrise = new StringBuilder("sunrise")
+                       StringBuilder sunriseTime = sunrise
+                       hubs = [[id:0, localIP:"128.195.204.105"]]
+                       modes = [[name: "home"],[name: "away"],[name: "night"]]
+                       helloHome = new Phrase()
+                       contactBookEnabled.setValue(1)
+                       contacts = ['AJ']
+                       phoneNumbers = [9495379373]
+                       name.append("hub0")
+                       temperatureScale.append("F")
+                       timeZone = TimeZone.getTimeZone("America/New_York")
+                       
+
+                       if (init)
+                               mode.append("away")     
+                       else
+                               mode.append("home")
+
+                       deviceValuesMap.put("mode", mode)
+                       deviceValuesMap.put("Location", mode)
        }
+
+       // Methods to return values
+       def getMode() {
+               return mode.toString()
+       }
+
+       def getLocationMode() {
+               return locationMode.toString()
+       }
+
+       def getName() {
+               return name.toString()
+       }
+
+       def getTemperatureScale() {
+               return temperatureScale.toString()
+       }
+
+       def getContactBookEnabled() {
+               return contactBookEnabled.getValue()
+       }
 }