Last active
December 29, 2015 17:42
-
-
Save jimmyjames/59dca7f47e674805206d to your computer and use it in GitHub Desktop.
testing dynamic inputs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* dynamic pages | |
* | |
* Copyright 2015 james anderson | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
* in compliance with the License. You may obtain a copy of the License at: | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed | |
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License | |
* for the specific language governing permissions and limitations under the License. | |
* | |
*/ | |
definition( | |
name: "dynamic pages", | |
namespace: "jimmyjames", | |
author: "james anderson", | |
description: "test", | |
category: "My Apps", | |
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png", | |
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:"testPage", title:"Test Page", uninstall:true, nextPage: "testPage2") | |
page(name:"testPage2", title: "Test Page 2", uninstall: true, install: true) | |
} | |
def testPage() { | |
dynamicPage(name:"testPage") { | |
section("test") { | |
1.upto(3) {n -> | |
log.trace "n: $n" | |
// works: | |
input "test$n", "capability.switch", title: "test $n", description: "test $n", required: false | |
// doesn't work (inputs not saved): | |
//input name: "test$n", type: "capability.switch", title: "test $n", description: "test $n", required: false | |
} | |
} | |
} | |
} | |
def testPage2() { | |
dynamicPage(name:"testPage2") { | |
section("test2") { | |
1.upto(3) {n -> | |
log.trace "n: $n" | |
def defaultValue = settings."test$n" ? settings."test$n".id : "" | |
// works: | |
input "another test$n", "capability.switch", title: "another test $n", defaultValue: defaultValue, description: "another test $n", required: false | |
// doesn't work (inputs not saved): | |
//input name: "another test$n", type: "capability.switch", title: "another test $n", defaultValue: defaultValue, description: "another test $n", required: false | |
} | |
} | |
} | |
} | |
def installed() { | |
log.debug "Installed with settings: ${settings}" | |
initialize() | |
} | |
def updated() { | |
log.debug "Updated with settings: ${settings}" | |
unsubscribe() | |
initialize() | |
} | |
def initialize() { | |
// TODO: subscribe to attributes, devices, locations, etc. | |
} | |
// TODO: implement event handlers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment