Skip to content

Commit 19070bf

Browse files
committed
v2.1.8 Better exception handling in api()
1 parent 13b0a53 commit 19070bf

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

ecobee.devicetype.groovy

+12-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* My Ecobee Device
33
* Copyright 2014 Yves Racine
44
* linkedIn profile: ca.linkedin.com/pub/yves-racine-m-sc-a/0/406/4b/
5-
* Version 2.1.7
5+
* Version 2.1.8
66
* Code: https://github.com/yracine/device-type.myecobee
77
* Refer to readme file for installation instructions.
88
*
@@ -1134,12 +1134,12 @@ private void api(method, args, success = {}) {
11341134
}
11351135
if (!refresh_tokens()) {
11361136
login()
1137-
if (state.exceptionCount >= MAX_EXCEPTION_COUNT) {
1138-
log.error ("api>error: Unauthorized exception, not able to renew the refresh token, need to re-authenticate with ecobee, run MyEcobeeInit....")
1139-
sendEvent (name: "verboseTrace",
1140-
value: "api>error: Unauthorized exception, not able to renew the refresh token, need to re-authenticate with ecobee, run MyEcobeeInit....")
1141-
return
1137+
def exceptionCheck=device.currentValue("verboseTrace")
1138+
if (exceptionCheck.contains("exception")) {
1139+
log.error ("api>$exceptionCheck, not able to renew the refresh token, need to re-authenticate with ecobee, run MyEcobeeInit....")
1140+
sendEvent (name: "verboseTrace", value:"api>$exceptionCheck, not able to renew the refresh token, need to re-authenticate with ecobee, run MyEcobeeInit....")
11421141
}
1142+
11431143
} else {
11441144

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

1151-
log.error ("api>error: found a high number of exceptions since last refresh_tokens() call, probably need to re-authenticate with ecobee, run MyEcobeeInit....")
1151+
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....")
11521152
sendEvent (name: "verboseTrace",
1153-
value: "api>error: found a high number of exceptions since last refresh_tokens() call, probably need to re-authenticate with ecobee, run MyEcobeeInit....")
1153+
value: "api>error: found a high number of exceptions (${state.exceptionCount}) since last refresh_tokens, probably need to re-authenticate with ecobee, run MyEcobeeInit....")
11541154
state.exceptionCount=0
11551155
}
11561156
def args_encoded = java.net.URLEncoder.encode(args.toString(), "UTF-8")
@@ -2996,10 +2996,8 @@ def getModelNumber() {
29962996
return ((data.thermostatList[0].identifier)? data.thermostatList[0].modelNumber: "")
29972997
}
29982998

2999-
private def refresh_tokens()
3000-
throws javax.net.ssl.SSLHandshakeException,groovyx.net.http.HttpResponseException,IOException,
3001-
java.net.UnknownHostException,java.net.NoRouteToHostException {
3002-
2999+
private def refresh_tokens() {
3000+
30033001
if (!isTokenExpired()) {
30043002

30053003
if (settings.trace) {
@@ -3039,12 +3037,12 @@ private def refresh_tokens()
30393037
httpPostJson(method, successRefreshTokens)
30403038
} catch (java.net.UnknownHostException e) {
30413039
log.error "refresh_tokens> Unknown host - check the URL " + method.uri
3042-
sendEvent name: "verboseTrace", value: "refresh_tokens> Unknown host ${method.uri}"
3040+
sendEvent name: "verboseTrace", value: "refresh_tokens> exception $e, Unknown host ${method.uri}"
30433041
state.exceptionCount = state.exceptionCount +1
30443042
return false
30453043
} catch (java.net.NoRouteToHostException e) {
30463044
log.error "refresh_tokens> No route to host - check the URL " + method.uri
3047-
sendEvent name: "verboseTrace", value: "refresh_tokens> No route to host ${method.uri}"
3045+
sendEvent name: "verboseTrace", value: "refresh_tokens> exception $e, no route to host ${method.uri}"
30483046
state.exceptionCount = state.exceptionCount +1
30493047
return false
30503048
} catch (e) {

0 commit comments

Comments
 (0)