mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-08 05:31:56 +00:00
DVCSMP-2076 - Async Update (#1279)
This commit is contained in:
@@ -4,6 +4,9 @@
|
|||||||
* Author: Juan Risso
|
* Author: Juan Risso
|
||||||
* Date: 2013-12-19
|
* Date: 2013-12-19
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
include 'asynchttp_v1'
|
||||||
|
|
||||||
definition(
|
definition(
|
||||||
name: "Jawbone UP (Connect)",
|
name: "Jawbone UP (Connect)",
|
||||||
namespace: "juano2310",
|
namespace: "juano2310",
|
||||||
@@ -303,7 +306,8 @@ def setup() {
|
|||||||
def childDevice = addChildDevice('juano2310', "Jawbone User", "${app.id}.${member.xid}",null,[name:"Jawbone UP - " + member.first, completedSetup: true])
|
def childDevice = addChildDevice('juano2310', "Jawbone User", "${app.id}.${member.xid}",null,[name:"Jawbone UP - " + member.first, completedSetup: true])
|
||||||
if (childDevice) {
|
if (childDevice) {
|
||||||
log.debug "Child Device Successfully Created"
|
log.debug "Child Device Successfully Created"
|
||||||
generateInitialEvent (member, childDevice)
|
childDevice?.generateSleepingEvent(false)
|
||||||
|
pollChild(childDevice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -349,67 +353,67 @@ def uninstalled() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def pollChild(childDevice) {
|
def pollChild(childDevice) {
|
||||||
def member = state.member
|
def childMap = [ value: "$childDevice.device.deviceNetworkId}"]
|
||||||
generatePollingEvents (member, childDevice)
|
|
||||||
|
def params = [
|
||||||
|
uri: 'https://jawbone.com',
|
||||||
|
path: '/nudge/api/users/@me/goals',
|
||||||
|
headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ],
|
||||||
|
contentType: 'application/json'
|
||||||
|
]
|
||||||
|
|
||||||
|
asynchttp_v1.get('responseGoals', params, childMap)
|
||||||
|
|
||||||
|
def params2 = [
|
||||||
|
uri: 'https://jawbone.com',
|
||||||
|
path: '/nudge/api/users/@me/moves',
|
||||||
|
headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ],
|
||||||
|
contentType: 'application/json'
|
||||||
|
]
|
||||||
|
|
||||||
|
asynchttp_v1.get('responseMoves', params2, childMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
def generatePollingEvents (member, childDevice) {
|
def responseGoals(response, dni) {
|
||||||
// lets figure out if the member is currently "home" (At the place)
|
if (response.hasError()) {
|
||||||
def urlgoals = "https://jawbone.com/nudge/api/users/@me/goals"
|
log.error "response has error: $response.errorMessage"
|
||||||
def urlmoves = "https://jawbone.com/nudge/api/users/@me/moves"
|
} else {
|
||||||
def urlsleeps = "https://jawbone.com/nudge/api/users/@me/sleeps"
|
def goals
|
||||||
def goals = null
|
try {
|
||||||
def moves = null
|
// json response already parsed into JSONElement object
|
||||||
def sleeps = null
|
goals = response.json.data
|
||||||
httpGet(uri: urlgoals, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
|
} catch (e) {
|
||||||
goals = response.data.data
|
log.error "error parsing json from response: $e"
|
||||||
}
|
}
|
||||||
httpGet(uri: urlmoves, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
|
if (goals) {
|
||||||
moves = response.data.data.items[0]
|
def childDevice = getChildDevice(dni.value)
|
||||||
}
|
log.debug "Goal = ${goals.move_steps} Steps"
|
||||||
|
childDevice?.sendEvent(name:"goal", value: goals.move_steps)
|
||||||
try { // we are going to just ignore any errors
|
} else {
|
||||||
log.debug "Member = ${member.first}"
|
log.debug "did not get json results from response body: $response.data"
|
||||||
log.debug "Moves Goal = ${goals.move_steps} Steps"
|
}
|
||||||
log.debug "Moves = ${moves.details.steps} Steps"
|
}
|
||||||
|
|
||||||
childDevice?.sendEvent(name:"steps", value: moves.details.steps)
|
|
||||||
childDevice?.sendEvent(name:"goal", value: goals.move_steps)
|
|
||||||
//setColor(moves.details.steps,goals.move_steps,childDevice)
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
// eat it
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def generateInitialEvent (member, childDevice) {
|
def responseMoves(response, dni) {
|
||||||
// lets figure out if the member is currently "home" (At the place)
|
if (response.hasError()) {
|
||||||
def urlgoals = "https://jawbone.com/nudge/api/users/@me/goals"
|
log.error "response has error: $response.errorMessage"
|
||||||
def urlmoves = "https://jawbone.com/nudge/api/users/@me/moves"
|
} else {
|
||||||
def urlsleeps = "https://jawbone.com/nudge/api/users/@me/sleeps"
|
def moves
|
||||||
def goals = null
|
try {
|
||||||
def moves = null
|
// json response already parsed into JSONElement object
|
||||||
def sleeps = null
|
moves = response.json.data.items[0]
|
||||||
httpGet(uri: urlgoals, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
|
} catch (e) {
|
||||||
goals = response.data.data
|
log.error "error parsing json from response: $e"
|
||||||
}
|
}
|
||||||
httpGet(uri: urlmoves, headers: ["Authorization": "Bearer ${state.JawboneAccessToken}" ]) {response ->
|
if (moves) {
|
||||||
moves = response.data.data.items[0]
|
def childDevice = getChildDevice(dni.value)
|
||||||
}
|
log.debug "Moves = ${moves.details.steps} Steps"
|
||||||
|
childDevice?.sendEvent(name:"steps", value: moves.details.steps)
|
||||||
try { // we are going to just ignore any errors
|
} else {
|
||||||
log.debug "Member = ${member.first}"
|
log.debug "did not get json results from response body: $response.data"
|
||||||
log.debug "Moves Goal = ${goals.move_steps} Steps"
|
}
|
||||||
log.debug "Moves = ${moves.details.steps} Steps"
|
}
|
||||||
log.debug "Sleeping state = false"
|
|
||||||
childDevice?.generateSleepingEvent(false)
|
|
||||||
childDevice?.sendEvent(name:"steps", value: moves.details.steps)
|
|
||||||
childDevice?.sendEvent(name:"goal", value: goals.move_steps)
|
|
||||||
//setColor(moves.details.steps,goals.move_steps,childDevice)
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
// eat it
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def setColor (steps,goal,childDevice) {
|
def setColor (steps,goal,childDevice) {
|
||||||
@@ -433,7 +437,7 @@ def hookEventHandler() {
|
|||||||
// 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]
|
||||||
def json_action = json.events.action[0]
|
def json_action = json.events.action[0]
|
||||||
|
|
||||||
//log.debug json
|
//log.debug json
|
||||||
log.debug "Userid = ${userId}"
|
log.debug "Userid = ${userId}"
|
||||||
|
|||||||
Reference in New Issue
Block a user