3f5e46e25017e1e92d3841c1b9723cb8c9bdc163
[smartthings-infrastructure.git] / Location / LocationVar.groovy
1 //Create a class for location variable
2 package Location
3
4 class LocationVar {
5         private int contactBookEnabled
6     private def modes
7         private def timeZone
8         private def hubs
9     private String mode
10         private String locationMode
11         private String name
12     private List contacts
13     private List phoneNumbers
14         private String temperatureScale 
15         def sendEvent
16         
17         private Phrase helloHome
18
19         LocationVar(Closure sendEvent, boolean init) {
20         
21                         if (init) {
22                                 this.hubs = [[id:0, localIP:"128.195.204.105"]]
23                                 this.modes = [[name: "home"],[name: "away"],[name: "night"]]
24                                 this.mode = "away"
25                                 this.locationMode = "away"
26                                 this.helloHome = new Phrase()
27                                 this.contactBookEnabled = 1
28                                 this.contacts = ['AJ']
29                                 this.phoneNumbers = [9495379373]
30                                 this.sendEvent = sendEvent
31                                 this.timeZone = TimeZone.getTimeZone("America/New_York")
32                                 this.name = "hub0"
33                                 this.temperatureScale = "F"
34                         } else {
35                                 this.hubs = [[id:0, localIP:"128.195.204.105"]]
36                                 this.modes = [[name: "home"],[name: "away"],[name: "night"]]
37                                 this.mode = "home"
38                                 this.locationMode = "home"
39                                 this.helloHome = new Phrase()
40                                 this.contactBookEnabled = 1
41                                 this.contacts = ['AJ']
42                                 this.phoneNumbers = [9495379373]
43                                 this.sendEvent = sendEvent
44                                 this.timeZone = TimeZone.getTimeZone("America/New_York")
45                                 this.name = "hub0"
46                                 this.temperatureScale = "F"
47                         
48                         }
49         }
50
51         //By Model Checker
52         def setValue(LinkedHashMap eventDataMap) {
53                 if (this.mode != eventDataMap['value']) {
54                         def sentMode = eventDataMap['value']
55                         println("The location is changed to $sentMode!")
56                         this.mode = sentMode
57                         this.locationMode = sentMode
58                         sendEvent(eventDataMap)
59                 }
60         }
61
62         def currentValue(String deviceFeature) {
63                 if (deviceFeature == "sunsetTime" || deviceFeature == "sunset")
64                         return System.currentTimeMillis()
65         }
66 }