MKTP-829 - Adding disclaimer

This commit is contained in:
juano2310
2016-09-06 14:01:20 -04:00
parent af2ea04442
commit fe2fbc3b97
3 changed files with 77 additions and 74 deletions

View File

@@ -28,7 +28,7 @@ mappings {
path("/receivedToken") { action: [ POST: "receivedToken", GET: "receivedToken"] } path("/receivedToken") { action: [ POST: "receivedToken", GET: "receivedToken"] }
path("/receiveToken") { action: [ POST: "receiveToken", GET: "receiveToken"] } path("/receiveToken") { action: [ POST: "receiveToken", GET: "receiveToken"] }
path("/hookCallback") { action: [ POST: "hookEventHandler", GET: "hookEventHandler"] } path("/hookCallback") { action: [ POST: "hookEventHandler", GET: "hookEventHandler"] }
path("/oauth/initialize") {action: [GET: "oauthInitUrl"]} path("/oauth/initialize") {action: [GET: "oauthInitUrl"]}
path("/oauth/callback") { action: [ GET: "callback" ] } path("/oauth/callback") { action: [ GET: "callback" ] }
} }
@@ -44,7 +44,7 @@ def callback() {
} else { } else {
log.warn "No authQueryString" log.warn "No authQueryString"
} }
if (state.JawboneAccessToken) { if (state.JawboneAccessToken) {
log.debug "Access token already exists" log.debug "Access token already exists"
setup() setup()
@@ -73,7 +73,7 @@ def callback() {
def authPage() { def authPage() {
log.debug "authPage" log.debug "authPage"
def description = null def description = null
if (state.JawboneAccessToken == null) { if (state.JawboneAccessToken == null) {
if (!state.accessToken) { if (!state.accessToken) {
log.debug "About to create access token" log.debug "About to create access token"
@@ -82,12 +82,13 @@ def authPage() {
description = "Click to enter Jawbone Credentials" description = "Click to enter Jawbone Credentials"
def redirectUrl = buildRedirectUrl def redirectUrl = buildRedirectUrl
log.debug "RedirectURL = ${redirectUrl}" log.debug "RedirectURL = ${redirectUrl}"
def donebutton= state.JawboneAccessToken != null def donebutton= state.JawboneAccessToken != null
return dynamicPage(name: "Credentials", title: "Jawbone UP", nextPage: null, uninstall: true, install: donebutton) { return dynamicPage(name: "Credentials", title: "Jawbone UP", nextPage: null, uninstall: true, install: donebutton) {
section { paragraph title: "Note:", "This device has not been officially tested and certified to “Work with SmartThings”. You can connect it to your SmartThings home but performance may vary and we will not be able to provide support or assistance." }
section { href url:redirectUrl, style:"embedded", required:true, title:"Jawbone UP", state: hast ,description:description } section { href url:redirectUrl, style:"embedded", required:true, title:"Jawbone UP", state: hast ,description:description }
} }
} else { } else {
description = "Jawbone Credentials Already Entered." description = "Jawbone Credentials Already Entered."
return dynamicPage(name: "Credentials", title: "Jawbone UP", uninstall: true, install:true) { return dynamicPage(name: "Credentials", title: "Jawbone UP", uninstall: true, install:true) {
section { href url: buildRedirectUrl("receivedToken"), style:"embedded", state: "complete", title:"Jawbone UP", description:description } section { href url: buildRedirectUrl("receivedToken"), style:"embedded", state: "complete", title:"Jawbone UP", description:description }
} }
@@ -107,7 +108,7 @@ def receiveToken(redirectUrl = null) {
def params = [ def params = [
uri: "https://jawbone.com/auth/oauth2/token?${toQueryString(oauthParams)}", uri: "https://jawbone.com/auth/oauth2/token?${toQueryString(oauthParams)}",
] ]
httpGet(params) { response -> httpGet(params) { response ->
log.debug "${response.data}" log.debug "${response.data}"
log.debug "Setting access token to ${response.data.access_token}, refresh token to ${response.data.refresh_token}" log.debug "Setting access token to ${response.data.access_token}, refresh token to ${response.data.refresh_token}"
state.JawboneAccessToken = response.data.access_token state.JawboneAccessToken = response.data.access_token
@@ -149,7 +150,7 @@ def connectionStatus(message, redirectUrl = null) {
<meta http-equiv="refresh" content="3; url=${redirectUrl}" /> <meta http-equiv="refresh" content="3; url=${redirectUrl}" />
""" """
} }
def html = """ def html = """
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@@ -229,12 +230,12 @@ def validateCurrentToken() {
log.debug "validateCurrentToken" log.debug "validateCurrentToken"
def url = "https://jawbone.com/nudge/api/v.1.1/users/@me/refreshToken" def url = "https://jawbone.com/nudge/api/v.1.1/users/@me/refreshToken"
def requestBody = "secret=${appSettings.clientSecret}" def requestBody = "secret=${appSettings.clientSecret}"
try { try {
httpPost(uri: url, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ], body: requestBody) {response -> httpPost(uri: url, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ], body: requestBody) {response ->
if (response.status == 200) { if (response.status == 200) {
log.debug "${response.data}" log.debug "${response.data}"
log.debug "Setting refresh token to ${response.data.data.refresh_token}" log.debug "Setting refresh token"
state.refreshToken = response.data.data.refresh_token state.refreshToken = response.data.data.refresh_token
} }
} }
@@ -258,7 +259,7 @@ def validateCurrentToken() {
state.remove("refreshToken") state.remove("refreshToken")
} }
} else { } else {
log.debug "Setting access token to ${data.access_token}, refresh token to ${data.refresh_token}" log.debug "Setting access token"
state.JawboneAccessToken = data.access_token state.JawboneAccessToken = data.access_token
state.refreshToken = data.refresh_token state.refreshToken = data.refresh_token
} }
@@ -271,10 +272,10 @@ def validateCurrentToken() {
} }
def initialize() { def initialize() {
log.debug "Callback URL - Webhook" log.debug "Callback URL - Webhook"
def localServerUrl = getApiServerUrl() def localServerUrl = getApiServerUrl()
def hookUrl = "${localServerUrl}/api/token/${state.accessToken}/smartapps/installations/${app.id}/hookCallback" def hookUrl = "${localServerUrl}/api/token/${state.accessToken}/smartapps/installations/${app.id}/hookCallback"
def webhook = "https://jawbone.com/nudge/api/v.1.1/users/@me/pubsub?webhook=$hookUrl" def webhook = "https://jawbone.com/nudge/api/v.1.1/users/@me/pubsub?webhook=$hookUrl"
httpPost(uri: webhook, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) httpPost(uri: webhook, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ])
} }
@@ -284,16 +285,16 @@ def setup() {
if (state.JawboneAccessToken) { if (state.JawboneAccessToken) {
def urlmember = "https://jawbone.com/nudge/api/users/@me/" def urlmember = "https://jawbone.com/nudge/api/users/@me/"
def member = null def member = null
httpGet(uri: urlmember, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response -> httpGet(uri: urlmember, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
member = response.data.data member = response.data.data
} }
if (member) { if (member) {
state.member = member state.member = member
def externalId = "${app.id}.${member.xid}" def externalId = "${app.id}.${member.xid}"
// find the appropriate child device based on my app id and the device network id // find the appropriate child device based on my app id and the device network id
def deviceWrapper = getChildDevice("${externalId}") def deviceWrapper = getChildDevice("${externalId}")
// invoke the generatePresenceEvent method on the child device // invoke the generatePresenceEvent method on the child device
@@ -312,7 +313,7 @@ def setup() {
} }
def installed() { def installed() {
if (!state.accessToken) { if (!state.accessToken) {
log.debug "About to create access token" log.debug "About to create access token"
createAccessToken() createAccessToken()
@@ -324,7 +325,7 @@ def installed() {
} }
def updated() { def updated() {
if (!state.accessToken) { if (!state.accessToken) {
log.debug "About to create access token" log.debug "About to create access token"
createAccessToken() createAccessToken()
@@ -348,29 +349,29 @@ def uninstalled() {
} }
def pollChild(childDevice) { def pollChild(childDevice) {
def member = state.member def member = state.member
generatePollingEvents (member, childDevice) generatePollingEvents (member, childDevice)
} }
def generatePollingEvents (member, childDevice) { def generatePollingEvents (member, childDevice) {
// lets figure out if the member is currently "home" (At the place) // lets figure out if the member is currently "home" (At the place)
def urlgoals = "https://jawbone.com/nudge/api/users/@me/goals" def urlgoals = "https://jawbone.com/nudge/api/users/@me/goals"
def urlmoves = "https://jawbone.com/nudge/api/users/@me/moves" def urlmoves = "https://jawbone.com/nudge/api/users/@me/moves"
def urlsleeps = "https://jawbone.com/nudge/api/users/@me/sleeps" def urlsleeps = "https://jawbone.com/nudge/api/users/@me/sleeps"
def goals = null def goals = null
def moves = null def moves = null
def sleeps = null def sleeps = null
httpGet(uri: urlgoals, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response -> httpGet(uri: urlgoals, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
goals = response.data.data goals = response.data.data
} }
httpGet(uri: urlmoves, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response -> httpGet(uri: urlmoves, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
moves = response.data.data.items[0] moves = response.data.data.items[0]
} }
try { // we are going to just ignore any errors try { // we are going to just ignore any errors
log.debug "Member = ${member.first}" log.debug "Member = ${member.first}"
log.debug "Moves Goal = ${goals.move_steps} Steps" log.debug "Moves Goal = ${goals.move_steps} Steps"
log.debug "Moves = ${moves.details.steps} Steps" log.debug "Moves = ${moves.details.steps} Steps"
childDevice?.sendEvent(name:"steps", value: moves.details.steps) childDevice?.sendEvent(name:"steps", value: moves.details.steps)
childDevice?.sendEvent(name:"goal", value: goals.move_steps) childDevice?.sendEvent(name:"goal", value: goals.move_steps)
@@ -378,29 +379,29 @@ def generatePollingEvents (member, childDevice) {
} }
catch (e) { catch (e) {
// eat it // eat it
} }
} }
def generateInitialEvent (member, childDevice) { def generateInitialEvent (member, childDevice) {
// lets figure out if the member is currently "home" (At the place) // lets figure out if the member is currently "home" (At the place)
def urlgoals = "https://jawbone.com/nudge/api/users/@me/goals" def urlgoals = "https://jawbone.com/nudge/api/users/@me/goals"
def urlmoves = "https://jawbone.com/nudge/api/users/@me/moves" def urlmoves = "https://jawbone.com/nudge/api/users/@me/moves"
def urlsleeps = "https://jawbone.com/nudge/api/users/@me/sleeps" def urlsleeps = "https://jawbone.com/nudge/api/users/@me/sleeps"
def goals = null def goals = null
def moves = null def moves = null
def sleeps = null def sleeps = null
httpGet(uri: urlgoals, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response -> httpGet(uri: urlgoals, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
goals = response.data.data goals = response.data.data
} }
httpGet(uri: urlmoves, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response -> httpGet(uri: urlmoves, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
moves = response.data.data.items[0] moves = response.data.data.items[0]
} }
try { // we are going to just ignore any errors try { // we are going to just ignore any errors
log.debug "Member = ${member.first}" log.debug "Member = ${member.first}"
log.debug "Moves Goal = ${goals.move_steps} Steps" log.debug "Moves Goal = ${goals.move_steps} Steps"
log.debug "Moves = ${moves.details.steps} Steps" log.debug "Moves = ${moves.details.steps} Steps"
log.debug "Sleeping state = false" log.debug "Sleeping state = false"
childDevice?.generateSleepingEvent(false) childDevice?.generateSleepingEvent(false)
childDevice?.sendEvent(name:"steps", value: moves.details.steps) childDevice?.sendEvent(name:"steps", value: moves.details.steps)
childDevice?.sendEvent(name:"goal", value: goals.move_steps) childDevice?.sendEvent(name:"goal", value: goals.move_steps)
@@ -408,27 +409,27 @@ def generateInitialEvent (member, childDevice) {
} }
catch (e) { catch (e) {
// eat it // eat it
} }
} }
def setColor (steps,goal,childDevice) { def setColor (steps,goal,childDevice) {
def result = steps * 100 / goal def result = steps * 100 / goal
if (result < 25) if (result < 25)
childDevice?.sendEvent(name:"steps", value: "steps", label: steps) childDevice?.sendEvent(name:"steps", value: "steps", label: steps)
else if ((result >= 25) && (result < 50)) else if ((result >= 25) && (result < 50))
childDevice?.sendEvent(name:"steps", value: "steps1", label: steps) childDevice?.sendEvent(name:"steps", value: "steps1", label: steps)
else if ((result >= 50) && (result < 75)) else if ((result >= 50) && (result < 75))
childDevice?.sendEvent(name:"steps", value: "steps1", label: steps) childDevice?.sendEvent(name:"steps", value: "steps1", label: steps)
else if (result >= 75) else if (result >= 75)
childDevice?.sendEvent(name:"steps", value: "stepsgoal", label: steps) childDevice?.sendEvent(name:"steps", value: "stepsgoal", label: steps)
} }
def hookEventHandler() { def hookEventHandler() {
// log.debug "In hookEventHandler method." // log.debug "In hookEventHandler method."
log.debug "request = ${request}" log.debug "request = ${request}"
def json = request.JSON def json = request.JSON
// get some stuff we need // get some stuff we need
def userId = json.events.user_xid[0] def userId = json.events.user_xid[0]
def json_type = json.events.type[0] def json_type = json.events.type[0]
@@ -437,39 +438,39 @@ def hookEventHandler() {
//log.debug json //log.debug json
log.debug "Userid = ${userId}" log.debug "Userid = ${userId}"
log.debug "Notification Type: " + json_type log.debug "Notification Type: " + json_type
log.debug "Notification Action: " + json_action log.debug "Notification Action: " + json_action
// find the appropriate child device based on my app id and the device network id // find the appropriate child device based on my app id and the device network id
def externalId = "${app.id}.${userId}" def externalId = "${app.id}.${userId}"
def childDevice = getChildDevice("${externalId}") def childDevice = getChildDevice("${externalId}")
if (childDevice) { if (childDevice) {
switch (json_action) { switch (json_action) {
case "enter_sleep_mode": case "enter_sleep_mode":
childDevice?.generateSleepingEvent(true) childDevice?.generateSleepingEvent(true)
break break
case "exit_sleep_mode": case "exit_sleep_mode":
childDevice?.generateSleepingEvent(false) childDevice?.generateSleepingEvent(false)
break break
case "creation": case "creation":
childDevice?.sendEvent(name:"steps", value: 0) childDevice?.sendEvent(name:"steps", value: 0)
break break
case "updation": case "updation":
def urlgoals = "https://jawbone.com/nudge/api/users/@me/goals" def urlgoals = "https://jawbone.com/nudge/api/users/@me/goals"
def urlmoves = "https://jawbone.com/nudge/api/users/@me/moves" def urlmoves = "https://jawbone.com/nudge/api/users/@me/moves"
def goals = null def goals = null
def moves = null def moves = null
httpGet(uri: urlgoals, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response -> httpGet(uri: urlgoals, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
goals = response.data.data goals = response.data.data
} }
httpGet(uri: urlmoves, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response -> httpGet(uri: urlmoves, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
moves = response.data.data.items[0] moves = response.data.data.items[0]
} }
log.debug "Goal = ${goals.move_steps} Steps" log.debug "Goal = ${goals.move_steps} Steps"
log.debug "Steps = ${moves.details.steps} Steps" log.debug "Steps = ${moves.details.steps} Steps"
childDevice?.sendEvent(name:"steps", value: moves.details.steps) childDevice?.sendEvent(name:"steps", value: moves.details.steps)
childDevice?.sendEvent(name:"goal", value: goals.move_steps) childDevice?.sendEvent(name:"goal", value: goals.move_steps)
//setColor(moves.details.steps,goals.move_steps,childDevice) //setColor(moves.details.steps,goals.move_steps,childDevice)
break break
case "deletion": case "deletion":
app.delete() app.delete()

View File

@@ -51,7 +51,7 @@ definition(
} }
preferences(oauthPage: "deviceAuthorization") { preferences(oauthPage: "deviceAuthorization") {
page(name: "Credentials", title: "Connect to your Logitech Harmony device", content: "authPage", install: false, nextPage: "deviceAuthorization") page(name: "Credentials", title: "Connect to your Logitech Harmony device", content: "authPage", install: false, nextPage: "deviceAuthorization")
page(name: "deviceAuthorization", title: "Logitech Harmony device authorization", install: true) { page(name: "deviceAuthorization", title: "Logitech Harmony device authorization", install: true) {
section("Allow Logitech Harmony to control these things...") { section("Allow Logitech Harmony to control these things...") {
input "switches", "capability.switch", title: "Which Switches?", multiple: true, required: false input "switches", "capability.switch", title: "Which Switches?", multiple: true, required: false
@@ -119,6 +119,7 @@ def authPage() {
discoverDevices() discoverDevices()
} }
return dynamicPage(name:"Credentials", title:"Discovery Started!", nextPage:"", refreshInterval:refreshInterval, install:true, uninstall: true) { return dynamicPage(name:"Credentials", title:"Discovery Started!", nextPage:"", refreshInterval:refreshInterval, install:true, uninstall: true) {
section { paragraph title: "Note:", "This device has not been officially tested and certified to “Work with SmartThings”. You can connect it to your SmartThings home but performance may vary and we will not be able to provide support or assistance." }
section("Please wait while we discover your Harmony Hubs and Activities. Discovery can take five minutes or more, so sit back and relax! Select your device below once discovered.") { section("Please wait while we discover your Harmony Hubs and Activities. Discovery can take five minutes or more, so sit back and relax! Select your device below once discovered.") {
input "selectedhubs", "enum", required:false, title:"Select Harmony Hubs (${numFoundHub} found)", multiple:true, options:huboptions input "selectedhubs", "enum", required:false, title:"Select Harmony Hubs (${numFoundHub} found)", multiple:true, options:huboptions
} }

View File

@@ -86,6 +86,7 @@ def firstPage()
def lightSwitchesDiscovered = lightSwitchesDiscovered() def lightSwitchesDiscovered = lightSwitchesDiscovered()
return dynamicPage(name:"firstPage", title:"Discovery Started!", nextPage:"", refreshInterval: refreshInterval, install:true, uninstall: true) { return dynamicPage(name:"firstPage", title:"Discovery Started!", nextPage:"", refreshInterval: refreshInterval, install:true, uninstall: true) {
section { paragraph title: "Note:", "This device has not been officially tested and certified to “Work with SmartThings”. You can connect it to your SmartThings home but performance may vary and we will not be able to provide support or assistance." }
section("Select a device...") { section("Select a device...") {
input "selectedSwitches", "enum", required:false, title:"Select Wemo Switches \n(${switchesDiscovered.size() ?: 0} found)", multiple:true, options:switchesDiscovered input "selectedSwitches", "enum", required:false, title:"Select Wemo Switches \n(${switchesDiscovered.size() ?: 0} found)", multiple:true, options:switchesDiscovered
input "selectedMotions", "enum", required:false, title:"Select Wemo Motions \n(${motionsDiscovered.size() ?: 0} found)", multiple:true, options:motionsDiscovered input "selectedMotions", "enum", required:false, title:"Select Wemo Motions \n(${motionsDiscovered.size() ?: 0} found)", multiple:true, options:motionsDiscovered
@@ -681,4 +682,4 @@ private Boolean hasAllHubsOver(String desiredFirmware) {
private List getRealHubFirmwareVersions() { private List getRealHubFirmwareVersions() {
return location.hubs*.firmwareVersionString.findAll { it } return location.hubs*.firmwareVersionString.findAll { it }
} }