Fixing bugs in infrastructure
[smartthings-infrastructure.git] / Location / LocationVar.groovy
old mode 100644 (file)
new mode 100755 (executable)
index b2016e8..403055d
@@ -1,31 +1,52 @@
 //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
-       def sendEvent
-    
-       private Phrase helloHome
+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
+       
+       LocationVar(Closure sendEvent, boolean init) {
+                       deviceValueSmartThing = deviceValuesMap
+                       deviceIntValueSmartThing = deviceIntValuesMap
+                       idSmartThing = id
+                       labelSmartThing = label
+                       displayNameSmartThing = displayName
+                       sendEventSmartThings = sendEvent
 
-       LocationVar(Closure sendEvent) {
-               this.modes = [[name: "home"],[name: "away"],[name: "night"]]
-               this.mode = "home"
-               this.helloHome = new Phrase()
-               this.contactBookEnabled = 1
-               this.contacts = ['AJ']
-               this.phoneNumbers = [9495379373]
-               this.sendEvent = sendEvent
-       }
+                       // Initialization
+                       String mode
+                       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"]]
+
+                       if (init)
+                               mode = "away"   
+                       else
+                               mode = "home"
 
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               def sentMode = eventDataMap['value']
-               println("The location is changed to $sentMode!")
-               this.mode = sentMode
-               sendEvent(eventDataMap)
-       }
+                       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)
+       }
 }