Removing getXXX methods + properties. Adding getProperty feature to SmartThing(s)
[smartthings-infrastructure.git] / Location / LocationVar.groovy
index 88f34d6a4c0578be1766c8994900fbe2d30d9069..6a8e6d3065d6535e60b39f7402ec9f27977cf187 100755 (executable)
@@ -1,77 +1,51 @@
 //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 {
+       // id, label, and display name of the device
+       String id
+       String label
+       String displayName
+       // Maps from features to values
+       HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
+       HashMap<String, Integer> deviceIntValuesMap = new HashMap<String, Integer>()
+       // 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"
-                       
-                       }
-       }
+                       deviceValueSmartThing = deviceValuesMap
+                       deviceIntValueSmartThing = deviceIntValuesMap
+                       idSmartThing = id
+                       labelSmartThing = label
+                       displayNameSmartThing = displayName
+                       sendEventSmartThings = sendEvent
 
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (this.mode != eventDataMap['value']) {
-                       def sentMode = eventDataMap['value']
-                       println("The location is changed to $sentMode!")
-                       if (sentMode == "home") {
-                               this.mode = "home"
-                               this.locationMode = "home"
-                       } else if (sentMode == "away") {
-                               this.mode = "away"
-                               this.locationMode = "away"
-                       } else if (sentMode == "night") {
-                               this.mode = "night"
-                               this.locationMode = "night"
-                       } else {
-                               this.mode = sentMode
-                               this.locationMode = sentMode
-                       }
-                       sendEvent(eventDataMap)
-               }
-       }
+                       // Initialization
+                       helloHome = new Phrase()
+                       contacts = ['AJ']
+                       phoneNumbers = [9495379373]
+                       modes = [[name: "home"],[name: "away"],[name: "night"]]
+                       timeZone = TimeZone.getTimeZone("America/New_York")
+                       hubs = [[id:0, localIP:"128.195.204.105"]]
 
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "sunsetTime" || deviceFeature == "sunset")
-                       return System.currentTimeMillis()
-       }
+                       if (init)
+                               mode.append("away")     
+                       else
+                               mode.append("home")
+
+                       deviceValuesMap.put("mode", mode)
+                       deviceValuesMap.put("name", "hub0")
+                       deviceValuesMap.put("temperatureScale", "F")
+                       deviceValuesMap.put("sunset", "sunset")
+                       deviceValuesMap.put("sunrise", "sunrise")
+                       deviceValuesMap.put("sunsetTime", "sunsetTime")
+                       deviceValuesMap.put("sunriseTime", "sunriseTime")
+                       deviceIntValuesMap.put("contactBookEnabled", 1)
+       }
 }