From 972599b1b5325b555d942e41e754fd00c9d5950c Mon Sep 17 00:00:00 2001 From: vlaminck Date: Thu, 23 Jun 2016 12:19:54 -0500 Subject: [PATCH] Provide a way to remove unsupported devices from settings --- .../gentle-wake-up.src/gentle-wake-up.groovy | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/smartapps/smartthings/gentle-wake-up.src/gentle-wake-up.groovy b/smartapps/smartthings/gentle-wake-up.src/gentle-wake-up.groovy index f79a8fd..89dd9f6 100644 --- a/smartapps/smartthings/gentle-wake-up.src/gentle-wake-up.groovy +++ b/smartapps/smartthings/gentle-wake-up.src/gentle-wake-up.groovy @@ -39,6 +39,7 @@ preferences { page(name: "completionPage") page(name: "numbersPage") page(name: "controllerExplanationPage") + page(name: "unsupportedDevicesPage") } def rootPage() { @@ -47,6 +48,9 @@ def rootPage() { section("What to dim") { input(name: "dimmers", type: "capability.switchLevel", title: "Dimmers", description: null, multiple: true, required: true, submitOnChange: true) if (dimmers) { + if (dimmersContainUnsupportedDevices()) { + href(name: "toUnsupportedDevicesPage", page: "unsupportedDevicesPage", title: "Some of your selected dimmers don't seem to be supported", description: "Tap here to fix it", required: true) + } href(name: "toNumbersPage", page: "numbersPage", title: "Duration & Direction", description: numbersPageHrefDescription(), state: "complete") } } @@ -71,6 +75,31 @@ def rootPage() { } } +def unsupportedDevicesPage() { + + def unsupportedDimmers = dimmers.findAll { !hasSetLevelCommand(it) } + + dynamicPage(name: "unsupportedDevicesPage") { + if (unsupportedDimmers) { + section("These devices do not support the setLevel command") { + unsupportedDimmers.each { + paragraph deviceLabel(it) + } + } + section { + input(name: "dimmers", type: "capability.sensor", title: "Please remove the above devices from this list.", submitOnChange: true, multiple: true) + } + section { + paragraph "If you think there is a mistake here, please contact support." + } + } else { + section { + paragraph "You're all set. You can hit the back button, now. Thanks for cleaning up your settings :)" + } + } + } +} + def controllerExplanationPage() { dynamicPage(name: "controllerExplanationPage", title: "How To Control Gentle Wake Up") { @@ -819,6 +848,11 @@ private getRedHue(level) { if (level >= 96) return 17 } +private dimmersContainUnsupportedDevices() { + def found = dimmers.find { hasSetLevelCommand(it) == false } + return found != null +} + private hasSetLevelCommand(device) { return hasCommand(device, "setLevel") } @@ -1067,4 +1101,4 @@ def hasStartLevel() { def hasEndLevel() { return (endLevel != null && endLevel != "") -} +} \ No newline at end of file