9257012226d114f1efc8602371bf46f7b877eb4c
[smartthings-infrastructure.git] / Location / LocationVar.groovy
1 //Create a class for location variable
2 package Location
3 import SmartThing.SmartThing
4
5 public class LocationVar extends SmartThing {
6         // Features with numberical values
7         MutableInteger contactBookEnabled = new MutableInteger()
8         // Features with string values
9         StringBuilder mode = new StringBuilder()
10         StringBuilder locationMode = mode
11         StringBuilder name = new StringBuilder()
12         StringBuilder temperatureScale = new StringBuilder()
13         // Maps from features to values
14         HashMap<String, StringBuilder> deviceValuesMap = new HashMap<String, StringBuilder>()
15         // Other variables
16         Phrase helloHome
17         TimeZone timeZone
18         def modes
19         def hubs
20         List contacts
21         List phoneNumbers
22         
23         LocationVar(Closure sendEvent, boolean init) {
24                         deviceValuesMap = deviceValueSmartThing
25                         sendEventSmartThings = sendEvent
26
27                         // Initialization
28                         StringBuilder sunset = new StringBuilder("sunset")
29                         StringBuilder sunsetTime = sunset
30                         StringBuilder sunrise = new StringBuilder("sunrise")
31                         StringBuilder sunriseTime = sunrise
32                         hubs = [[id:0, localIP:"128.195.204.105"]]
33                         modes = [[name: "home"],[name: "away"],[name: "night"]]
34                         helloHome = new Phrase()
35                         contactBookEnabled.setValue(1)
36                         contacts = ['AJ']
37                         phoneNumbers = [9495379373]
38                         name.append("hub0")
39                         temperatureScale.append("F")
40                         timeZone = TimeZone.getTimeZone("America/New_York")
41                         
42
43                         if (init)
44                                 mode.append("away")     
45                         else
46                                 mode.append("home")
47
48                         deviceValuesMap.put("mode", mode)
49                         deviceValuesMap.put("Location", mode)
50                         deviceValuesMap.put("sunset", sunset)
51                         deviceValuesMap.put("sunrise", sunrise)
52         }
53
54         // Methods to return values
55         def currentValue(String deviceFeature) {
56                 if (deviceFeature == "sunsetTime" || deviceFeature == "sunset")
57                         return System.currentTimeMillis()
58         }
59
60         def getMode() {
61                 return mode.toString()
62         }
63
64         def getLocationMode() {
65                 return locationMode.toString()
66         }
67
68         def getName() {
69                 return name.toString()
70         }
71
72         def getTemperatureScale() {
73                 return temperatureScale.toString()
74         }
75
76         def getContactBookEnabled() {
77                 return contactBookEnabled.getValue()
78         }
79 }