A little modification for location.mode.
[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                         if (sentMode == "home") {
57                                 this.mode = "home"
58                                 this.locationMode = "home"
59                         } else if (sentMode == "away") {
60                                 this.mode = "away"
61                                 this.locationMode = "away"
62                         } else if (sentMode == "night") {
63                                 this.mode = "night"
64                                 this.locationMode = "night"
65                         } else {
66                                 this.mode = sentMode
67                                 this.locationMode = sentMode
68                         }
69                         sendEvent(eventDataMap)
70                 }
71         }
72
73         def currentValue(String deviceFeature) {
74                 if (deviceFeature == "sunsetTime" || deviceFeature == "sunset")
75                         return System.currentTimeMillis()
76         }
77 }