mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-08 05:31:56 +00:00
Plant link Exceptions
Adding try/catch blocks to reduce HTTP exceptions due to rate limits or unauthorized errors.
This commit is contained in:
@@ -137,6 +137,7 @@ def dock_sensor(device_serial, expected_plant_name) {
|
||||
contentType: "application/json",
|
||||
]
|
||||
log.debug "Creating new plant on myplantlink.com - ${expected_plant_name}"
|
||||
try {
|
||||
httpPost(docking_params) { docking_response ->
|
||||
if (parse_api_response(docking_response, "Docking a link")) {
|
||||
if (docking_response.data.plants.size() == 0) {
|
||||
@@ -145,6 +146,7 @@ def dock_sensor(device_serial, expected_plant_name) {
|
||||
plant_post_body_map['links_key'] = [docking_response.data.key]
|
||||
def plant_post_body_json_builder = new JsonBuilder(plant_post_body_map)
|
||||
plant_post_params["body"] = plant_post_body_json_builder.toString()
|
||||
try {
|
||||
httpPost(plant_post_params) { plant_post_response ->
|
||||
if(parse_api_response(plant_post_response, 'creating plant')){
|
||||
def attached_map = atomicState.attached_sensors
|
||||
@@ -152,6 +154,9 @@ def dock_sensor(device_serial, expected_plant_name) {
|
||||
atomicState.attached_sensors = attached_map
|
||||
}
|
||||
}
|
||||
} catch (Exception f) {
|
||||
log.debug "call failed $f"
|
||||
}
|
||||
} else {
|
||||
def plant = docking_response.data.plants[0]
|
||||
def attached_map = atomicState.attached_sensors
|
||||
@@ -161,6 +166,9 @@ def dock_sensor(device_serial, expected_plant_name) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.debug "call failed $e"
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -178,9 +186,13 @@ def checkAndUpdatePlantIfNeeded(plant, expected_plant_name){
|
||||
]
|
||||
def plant_put_body_json_builder = new JsonBuilder(plant_put_body_map)
|
||||
plant_put_params["body"] = plant_put_body_json_builder.toString()
|
||||
try {
|
||||
httpPut(plant_put_params) { plant_put_response ->
|
||||
parse_api_response(plant_put_response, 'updating plant name')
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.debug "call failed $e"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,6 +210,7 @@ def moistureHandler(event){
|
||||
contentType: "application/json",
|
||||
body: event.value
|
||||
]
|
||||
try {
|
||||
httpPost(measurement_post_params) { measurement_post_response ->
|
||||
if (parse_api_response(measurement_post_response, 'creating moisture measurement') &&
|
||||
measurement_post_response.data.size() >0){
|
||||
@@ -218,6 +231,9 @@ def moistureHandler(event){
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.debug "call failed $e"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,9 +251,13 @@ def batteryHandler(event){
|
||||
contentType: "application/json",
|
||||
body: event.value
|
||||
]
|
||||
try {
|
||||
httpPost(measurement_post_params) { measurement_post_response ->
|
||||
parse_api_response(measurement_post_response, 'creating battery measurement')
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.debug "call failed $e"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,9 +295,13 @@ def swapToken(){
|
||||
]
|
||||
|
||||
def jsonMap
|
||||
try {
|
||||
httpPost(postParams) { resp ->
|
||||
jsonMap = resp.data
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.debug "call failed $e"
|
||||
}
|
||||
|
||||
atomicState.refreshToken = jsonMap.refresh_token
|
||||
atomicState.authToken = jsonMap.access_token
|
||||
|
||||
Reference in New Issue
Block a user