2 * Example of passing params via href element to a dynamic page
4 * Copyright 2015 SmartThings
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 * in compliance with the License. You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
12 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
13 * for the specific language governing permissions and limitations under the License.
17 name: "href params example",
18 namespace: "smartthings",
19 author: "SmartThings",
20 description: "passing params via href element to a dynamic page",
22 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
23 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
24 iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
27 // ========================================================
29 // ========================================================
32 page(name: "firstPage")
33 page(name: "secondPage")
34 page(name: "thirdPage")
41 thisIs: "totally working",
42 install: checkSomeCustomLogic(),
46 dynamicPage(name: "firstPage", uninstall: true) {
48 * The href element accepts a key of `params` and expects a `Map` as the value.
49 * Anything passed in `params` will be sent along with the request but will not be persisted in any way.
50 * The params will be used going to the next page but will not be available when backing out of that page.
51 * This, combined with the fact that pages refresh when navigating back to them, means that your params will not be
52 * available if your user hits the back button.
59 description: "includes params: ${hrefParams}",
66 def secondPage(params) {
68 * firstPage included `params` in the href element that navigated to here.
69 * You must specify some variable name in the method declaration. (I used 'params' here, but it can be any variable name you want).
70 * If you do not specify a variable name, there is no way to get the params that you specified in your `href` element.
73 log.debug "params: ${params}"
75 dynamicPage(name: "secondPage", uninstall: true, install: params?.install) {
76 if (params.nextPage) {
80 page: params.nextPage,
81 description: hrefState() ? "You've already been to the third page": "go checkout the third page",
87 paragraph "There were no params included when fetching this page."
95 state.reachedThirdPage = true
97 dynamicPage(name: "thirdPage") {
99 image "https://placekitten.com/g/600/500"
104 // ========================================================
106 // ========================================================
109 def checkSomeCustomLogic() {
116 * `state: "complete"` makes the right side of the href green.
117 * It's a great way to show the user that they've already set up some stuff on that page.
118 * In other words, it's a great way to show state ;)
119 * If you're using hrefs, it's a good idea to set `state` when appropriate.
121 state.reachedThirdPage ? "complete": ""
124 // ========================================================
126 // ========================================================
130 log.debug "Installed with settings: ${settings}"
135 log.debug "Updated with settings: ${settings}"
141 // TODO: subscribe to attributes, devices, locations, etc.
144 // TODO: implement event handlers