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