Infrastruction modification
[smartthings-infrastructure.git] / Location / LocationVar.groovy
index 3f5e46e25017e1e92d3841c1b9723cb8c9bdc163..9257012226d114f1efc8602371bf46f7b877eb4c 100755 (executable)
@@ -1,66 +1,79 @@
 //Create a class for location variable
 package Location
+import SmartThing.SmartThing
 
-class LocationVar {
-       private int contactBookEnabled
-    private def modes
-       private def timeZone
-       private def hubs
-    private String mode
-       private String locationMode
-       private String name
-    private List contacts
-    private List phoneNumbers
-       private String temperatureScale 
-       def sendEvent
+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
        
-       private Phrase helloHome
-
        LocationVar(Closure sendEvent, boolean init) {
-       
-                       if (init) {
-                               this.hubs = [[id:0, localIP:"128.195.204.105"]]
-                               this.modes = [[name: "home"],[name: "away"],[name: "night"]]
-                               this.mode = "away"
-                               this.locationMode = "away"
-                               this.helloHome = new Phrase()
-                               this.contactBookEnabled = 1
-                               this.contacts = ['AJ']
-                               this.phoneNumbers = [9495379373]
-                               this.sendEvent = sendEvent
-                               this.timeZone = TimeZone.getTimeZone("America/New_York")
-                               this.name = "hub0"
-                               this.temperatureScale = "F"
-                       } else {
-                               this.hubs = [[id:0, localIP:"128.195.204.105"]]
-                               this.modes = [[name: "home"],[name: "away"],[name: "night"]]
-                               this.mode = "home"
-                               this.locationMode = "home"
-                               this.helloHome = new Phrase()
-                               this.contactBookEnabled = 1
-                               this.contacts = ['AJ']
-                               this.phoneNumbers = [9495379373]
-                               this.sendEvent = sendEvent
-                               this.timeZone = TimeZone.getTimeZone("America/New_York")
-                               this.name = "hub0"
-                               this.temperatureScale = "F"
+                       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")
                        
-                       }
-       }
 
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (this.mode != eventDataMap['value']) {
-                       def sentMode = eventDataMap['value']
-                       println("The location is changed to $sentMode!")
-                       this.mode = sentMode
-                       this.locationMode = sentMode
-                       sendEvent(eventDataMap)
-               }
-       }
+                       if (init)
+                               mode.append("away")     
+                       else
+                               mode.append("home")
 
+                       deviceValuesMap.put("mode", mode)
+                       deviceValuesMap.put("Location", mode)
+                       deviceValuesMap.put("sunset", sunset)
+                       deviceValuesMap.put("sunrise", sunrise)
+       }
+
+       // Methods to return values
        def currentValue(String deviceFeature) {
                if (deviceFeature == "sunsetTime" || deviceFeature == "sunset")
                        return System.currentTimeMillis()
        }
+
+       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()
+       }
 }