Skip to content

Instantly share code, notes, and snippets.

@rappleg
Created February 14, 2014 21:49
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/9010044 to your computer and use it in GitHub Desktop.
Save rappleg/9010044 to your computer and use it in GitHub Desktop.
/**
* ParentChildParent
*
* Author: scott
* Date: 2014-02-14
*/
preferences {
section("Title") {
// TODO: put inputs here
}
}
mappings {
path("/show") {
action: [
GET: "show"
]
}
path("/add") {
action: [
GET: "add"
]
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
def one = addChildDevice("rappleg", "ParentChildChild", uuid(), null, ["label":"one"])
def two = addChildDevice("rappleg", "ParentChildChild", uuid(), null, ["label":"two"])
initialize()
log.debug "0: ${getServerUrl()}/api/smartapps/installations/${app.id}/show?access_token=${state.accessToken}"
log.debug "1: ${getServerUrl()}/api/devices/${one.device.id}/show?access_token=${one.data.accessToken}"
log.debug "2: ${getServerUrl()}/api/devices/${two.device.id}/show?access_token=${two.data.accessToken}"
}
def uuid()
{
return UUID.randomUUID().toString()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize() {
if(!state.accessToken)
{
log.debug "about to create access token"
createAccessToken()
}
}
def show() {
def count = atomicState.data?.count
return [count: count]
}
def add() {
increment()
return show()
}
def increment()
{
def old = atomicState.data?.count ?: 0
log.debug "old: $old"
atomicState.data = [count: old + 1]
}
def getServerUrl() { return "http://localhost:8080/" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment