Changing remote branch to PLRG Git server.
[smartapps.git] / third-party / Switches.groovy
index 3f8ea924b26b2991cb47bb07bae475f96983ec23..52549f2b284629208ae4f7aad8e6b4eca1189c59 100755 (executable)
@@ -21,6 +21,20 @@ definition(
     iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
     iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
 
+preferences {
+  page(name: "selectSwitches")
+}
+
+def selectSwitches() {
+    dynamicPage(name: "selectSwitches", title: "Switches", install: true) {
+        section("Select switches named after Hello Home phrases") {
+            input "switches", "capability.switch", title: "Switches", multiple: true
+        }
+        section("Change to this mode") {
+                   input "newMode", "mode", title: "Mode?"
+           }
+    }
+}
 
 def installed() {
     initialize()
@@ -37,24 +51,14 @@ def initialize() {
 
 def switchHandler(evt) {
   def s = switches.find{ evt.deviceId == it.id }
-  def phrase = location.helloHome.getPhrases().find { it.label == s.displayName }
+  //def phrase = location.helloHome.getPhrases().find { it.label == s.displayName }
+  def phrase
   if (phrase) {
     location.helloHome.execute(phrase.label)
   }
-  def mode = location.modes.find { it.name == s.displayName }
-  if (mode) {
-    setLocationMode(mode)
+  // This looks like a bug because device's displayName has nothing to do with modes
+  //def mode = location.modes.find { it.name == s.displayName }
+  if (newMode) {
+    setLocationMode(newMode)
   }
 }
-
-preferences {
-  page(name: selectSwitches)
-}
-
-def selectSwitches() {
-    dynamicPage(name: "selectSwitches", title: "Switches", install: true) {
-        section("Select switches named after Hello Home phrases") {
-            input "switches", "capability.switch", title: "Switches", multiple: true
-        }
-    }
-}