Skip to content

Instantly share code, notes, and snippets.

@rappleg
Created March 12, 2014 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rappleg/9516532 to your computer and use it in GitHub Desktop.
Save rappleg/9516532 to your computer and use it in GitHub Desktop.
/**
* Page Navigation
*
* Author: steve
* Date: 2013-08-23
*/
preferences {
page(name:"A", title:"A", content:"A", params:["foo":1])
page(name:"B", title:"B", content:"B", params:["foo":1])
page(name:"C", title:"C", content:"C", params:["foo":1])
page(name:"D", title:"D", content:"D", params:["foo":1])
page(name:"E", title:"E", content:"E", params:["foo":1])
}
def A(params) {
log.debug "params: ${params}"
log.debug "state: ${state}"
int foo = params.foo ?: 0
params.foo = foo + 1
int a = state.a ? state.a as int : 0
a++
state.a = a
dynamicPage(name:"A", title:"A", nextPage:"B", params:params) {
section ("This is A")
section ("Next: B")
section ("Previous: null")
section ("params.foo = ${params.foo}")
section ("state.a = ${a}")
}
}
def B(params) {
log.debug "params: ${params}"
log.debug "state: ${state}"
int foo = params.foo ?: 0
params.foo = foo + 1
int b = state.b ? state.b as int : 0
state.b = b + 1
dynamicPage(name:"B", title:"B", nextPage:"C", params:params){
section ("This is B")
section ("Next: C")
section ("Previous: null")
section ("params.foo = ${params.foo}")
section ("state.b = ${state.b}")
}
}
def C(params) {
log.debug "params: ${params}"
log.debug "state: ${state}"
int foo = params.foo ?: 0
params.foo = foo + 1
int c = state.c ? state.c as int : 0
state.c = c + 1
dynamicPage(name:"C", title:"C", nextPage:"D", previousPage:"E", params:params){
section ("This is C")
section ("Next: D")
section ("Previous: E")
section ("params.foo = ${params.foo}")
section ("state.c = ${state.c}")
}
}
def D(params) {
log.debug "params: ${params}"
log.debug "state: ${state}"
int foo = params.foo ?: 0
params.foo = foo + 1
int d = state.d ? state.d as int : 0
d++
state.d = d
def installable = d > 5
dynamicPage(name:"D", title:"D", previousPage:"B", params:params, install:installable){
section ("This is D")
section ("Next: null")
section ("Previous: B")
section ("params.foo = ${params.foo}")
section ("state.d = ${state.d}")
}
}
def E(params) {
log.debug "params: ${params}"
log.debug "state: ${state}"
int foo = params.foo ?: 0
params.foo = foo + 1
int e = state.e ? state.e as int : 0
e++
state.e = e
dynamicPage(name:"E", title:"E", previousPage:"B", nextPage:"D"){
section ("This is E")
section ("Next: D")
section ("Previous: C")
section ("params.foo = ${params.foo}")
section ("state.e = ${state.e}")
}
}
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.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment