A little modification for location.mode.
[smartthings-infrastructure.git] / Location / LocationVar.groovy
old mode 100644 (file)
new mode 100755 (executable)
index 3f28a0b..88f34d6
@@ -7,6 +7,7 @@ class LocationVar {
        private def timeZone
        private def hubs
        private String mode
+       private String locationMode
        private String name
        private List contacts
        private List phoneNumbers
@@ -15,26 +16,58 @@ class LocationVar {
        
        private Phrase helloHome
 
-       LocationVar(Closure sendEvent) {
-               this.hubs = [[id:0, localIP:"128.195.204.105"]]
-               this.modes = [[name: "home"],[name: "away"],[name: "night"]]
-               this.mode = "home"
-               this.helloHome = new Phrase()
-               this.contactBookEnabled = 1
-               this.contacts = ['AJ']
-               this.phoneNumbers = [9495379373]
-               this.sendEvent = sendEvent
-               this.timeZone = TimeZone.getTimeZone("America/New_York")
-               this.name = "hub0"
-               this.temperatureScale = "F"
+       LocationVar(Closure sendEvent, boolean init) {
+       
+                       if (init) {
+                               this.hubs = [[id:0, localIP:"128.195.204.105"]]
+                               this.modes = [[name: "home"],[name: "away"],[name: "night"]]
+                               this.mode = "away"
+                               this.locationMode = "away"
+                               this.helloHome = new Phrase()
+                               this.contactBookEnabled = 1
+                               this.contacts = ['AJ']
+                               this.phoneNumbers = [9495379373]
+                               this.sendEvent = sendEvent
+                               this.timeZone = TimeZone.getTimeZone("America/New_York")
+                               this.name = "hub0"
+                               this.temperatureScale = "F"
+                       } else {
+                               this.hubs = [[id:0, localIP:"128.195.204.105"]]
+                               this.modes = [[name: "home"],[name: "away"],[name: "night"]]
+                               this.mode = "home"
+                               this.locationMode = "home"
+                               this.helloHome = new Phrase()
+                               this.contactBookEnabled = 1
+                               this.contacts = ['AJ']
+                               this.phoneNumbers = [9495379373]
+                               this.sendEvent = sendEvent
+                               this.timeZone = TimeZone.getTimeZone("America/New_York")
+                               this.name = "hub0"
+                               this.temperatureScale = "F"
+                       
+                       }
        }
 
        //By Model Checker
        def setValue(LinkedHashMap eventDataMap) {
-               def sentMode = eventDataMap['value']
-               println("The location is changed to $sentMode!")
-               this.mode = sentMode
-               sendEvent(eventDataMap)
+               if (this.mode != eventDataMap['value']) {
+                       def sentMode = eventDataMap['value']
+                       println("The location is changed to $sentMode!")
+                       if (sentMode == "home") {
+                               this.mode = "home"
+                               this.locationMode = "home"
+                       } else if (sentMode == "away") {
+                               this.mode = "away"
+                               this.locationMode = "away"
+                       } else if (sentMode == "night") {
+                               this.mode = "night"
+                               this.locationMode = "night"
+                       } else {
+                               this.mode = sentMode
+                               this.locationMode = sentMode
+                       }
+                       sendEvent(eventDataMap)
+               }
        }
 
        def currentValue(String deviceFeature) {