Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure
[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 name
11         private List contacts
12         private List phoneNumbers
13         private String temperatureScale 
14         def sendEvent
15         
16         private Phrase helloHome
17
18         LocationVar(Closure sendEvent, boolean init) {
19         
20                         if (init) {
21                                 this.hubs = [[id:0, localIP:"128.195.204.105"]]
22                                 this.modes = [[name: "home"],[name: "away"],[name: "night"]]
23                                 this.mode = "away"
24                                 this.helloHome = new Phrase()
25                                 this.contactBookEnabled = 1
26                                 this.contacts = ['AJ']
27                                 this.phoneNumbers = [9495379373]
28                                 this.sendEvent = sendEvent
29                                 this.timeZone = TimeZone.getTimeZone("America/New_York")
30                                 this.name = "hub0"
31                                 this.temperatureScale = "F"
32                         } else {
33                                 this.hubs = [[id:0, localIP:"128.195.204.105"]]
34                                 this.modes = [[name: "home"],[name: "away"],[name: "night"]]
35                                 this.mode = "home"
36                                 this.helloHome = new Phrase()
37                                 this.contactBookEnabled = 1
38                                 this.contacts = ['AJ']
39                                 this.phoneNumbers = [9495379373]
40                                 this.sendEvent = sendEvent
41                                 this.timeZone = TimeZone.getTimeZone("America/New_York")
42                                 this.name = "hub0"
43                                 this.temperatureScale = "F"
44                         
45                         }
46         }
47
48         //By Model Checker
49         def setValue(LinkedHashMap eventDataMap) {
50                 def sentMode = eventDataMap['value']
51                 println("The location is changed to $sentMode!")
52                 this.mode = sentMode
53                 sendEvent(eventDataMap)
54         }
55
56         def currentValue(String deviceFeature) {
57                 if (deviceFeature == "sunsetTime" || deviceFeature == "sunset")
58                         return System.currentTimeMillis()
59         }
60 }