Skip to content

Commit

Permalink
v2.1.8 Better exception handling in api()
Browse files Browse the repository at this point in the history
  • Loading branch information
yracine committed Jul 31, 2015
1 parent 13b0a53 commit 19070bf
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions ecobee.devicetype.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* My Ecobee Device
* Copyright 2014 Yves Racine
* linkedIn profile: ca.linkedin.com/pub/yves-racine-m-sc-a/0/406/4b/
* Version 2.1.7
* Version 2.1.8
* Code: https://github.com/yracine/device-type.myecobee
* Refer to readme file for installation instructions.
*
Expand Down Expand Up @@ -1134,12 +1134,12 @@ private void api(method, args, success = {}) {
}
if (!refresh_tokens()) {
login()
if (state.exceptionCount >= MAX_EXCEPTION_COUNT) {
log.error ("api>error: Unauthorized exception, not able to renew the refresh token, need to re-authenticate with ecobee, run MyEcobeeInit....")
sendEvent (name: "verboseTrace",
value: "api>error: Unauthorized exception, not able to renew the refresh token, need to re-authenticate with ecobee, run MyEcobeeInit....")
return
def exceptionCheck=device.currentValue("verboseTrace")
if (exceptionCheck.contains("exception")) {
log.error ("api>$exceptionCheck, not able to renew the refresh token, need to re-authenticate with ecobee, run MyEcobeeInit....")
sendEvent (name: "verboseTrace", value:"api>$exceptionCheck, not able to renew the refresh token, need to re-authenticate with ecobee, run MyEcobeeInit....")
}

} else {

/* Reset Exceptions counter as the refresh_tokens() call has been successful */
Expand All @@ -1148,9 +1148,9 @@ private void api(method, args, success = {}) {
}
if (state.exceptionCount >= MAX_EXCEPTION_COUNT) {

log.error ("api>error: found a high number of exceptions since last refresh_tokens() call, probably need to re-authenticate with ecobee, run MyEcobeeInit....")
log.error ("api>error: found a high number of exceptions (${state.exceptionCount}) since last refresh_tokens, probably need to re-authenticate with ecobee, run MyEcobeeInit....")
sendEvent (name: "verboseTrace",
value: "api>error: found a high number of exceptions since last refresh_tokens() call, probably need to re-authenticate with ecobee, run MyEcobeeInit....")
value: "api>error: found a high number of exceptions (${state.exceptionCount}) since last refresh_tokens, probably need to re-authenticate with ecobee, run MyEcobeeInit....")
state.exceptionCount=0
}
def args_encoded = java.net.URLEncoder.encode(args.toString(), "UTF-8")
Expand Down Expand Up @@ -2996,10 +2996,8 @@ def getModelNumber() {
return ((data.thermostatList[0].identifier)? data.thermostatList[0].modelNumber: "")
}

private def refresh_tokens()
throws javax.net.ssl.SSLHandshakeException,groovyx.net.http.HttpResponseException,IOException,
java.net.UnknownHostException,java.net.NoRouteToHostException {

private def refresh_tokens() {

if (!isTokenExpired()) {

if (settings.trace) {
Expand Down Expand Up @@ -3039,12 +3037,12 @@ private def refresh_tokens()
httpPostJson(method, successRefreshTokens)
} catch (java.net.UnknownHostException e) {
log.error "refresh_tokens> Unknown host - check the URL " + method.uri
sendEvent name: "verboseTrace", value: "refresh_tokens> Unknown host ${method.uri}"
sendEvent name: "verboseTrace", value: "refresh_tokens> exception $e, Unknown host ${method.uri}"
state.exceptionCount = state.exceptionCount +1
return false
} catch (java.net.NoRouteToHostException e) {
log.error "refresh_tokens> No route to host - check the URL " + method.uri
sendEvent name: "verboseTrace", value: "refresh_tokens> No route to host ${method.uri}"
sendEvent name: "verboseTrace", value: "refresh_tokens> exception $e, no route to host ${method.uri}"
state.exceptionCount = state.exceptionCount +1
return false
} catch (e) {
Expand Down

0 comments on commit 19070bf

Please sign in to comment.