mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-16 21:03:28 +00:00
Merge pull request #525 from Yaima/master
Better exception handling for Ecobee
This commit is contained in:
@@ -257,21 +257,16 @@ def getEcobeeThermostats() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.debug "http status: ${resp.status}"
|
log.debug "http status: ${resp.status}"
|
||||||
//refresh the auth token
|
|
||||||
if (resp.data.status.code == 14) {
|
|
||||||
log.debug "Storing the failed action to try later"
|
|
||||||
atomicState.action = "getEcobeeThermostats"
|
|
||||||
log.debug "Refreshing your auth_token!"
|
|
||||||
refreshAuthToken()
|
|
||||||
} else {
|
|
||||||
log.error "Authentication error, invalid authentication method, lack of credentials, etc."
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch (groovyx.net.http.HttpResponseException e) {
|
||||||
log.debug "___exception getEcobeeThermostats(): " + e
|
log.trace "Exception polling children: " + e.response.data.status
|
||||||
refreshAuthToken()
|
if (e.response.data.status.code == 14) {
|
||||||
}
|
atomicState.action = "getEcobeeThermostats"
|
||||||
|
log.debug "Refreshing your auth_token!"
|
||||||
|
refreshAuthToken()
|
||||||
|
}
|
||||||
|
}
|
||||||
atomicState.thermostats = stats
|
atomicState.thermostats = stats
|
||||||
return stats
|
return stats
|
||||||
}
|
}
|
||||||
@@ -450,23 +445,15 @@ def pollChildren(child = null) {
|
|||||||
}
|
}
|
||||||
result = true
|
result = true
|
||||||
log.debug "updated ${atomicState.thermostats?.size()} stats: ${atomicState.thermostats}"
|
log.debug "updated ${atomicState.thermostats?.size()} stats: ${atomicState.thermostats}"
|
||||||
} else {
|
|
||||||
log.error "polling children & got http status ${resp.status}"
|
|
||||||
|
|
||||||
//refresh the auth token
|
|
||||||
if (resp.data.status.code == 14) {
|
|
||||||
atomicState.action = "pollChildren"
|
|
||||||
log.debug "Refreshing your auth_token!"
|
|
||||||
refreshAuthToken()
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
log.error "Authentication error, invalid authentication method, lack of credentials, etc."
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch (groovyx.net.http.HttpResponseException e) {
|
||||||
log.debug "___exception polling children: " + e
|
log.trace "Exception polling children: " + e.response.data.status
|
||||||
refreshAuthToken()
|
if (e.response.data.status.code == 14) {
|
||||||
|
atomicState.action = "pollChildren"
|
||||||
|
log.debug "Refreshing your auth_token!"
|
||||||
|
refreshAuthToken()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@@ -642,16 +629,14 @@ private refreshAuthToken() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
atomicState.action = ""
|
atomicState.action = ""
|
||||||
} else {
|
|
||||||
log.debug "refresh failed ${resp.status} : ${resp.status.code}"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (groovyx.net.http.HttpResponseException e) {
|
} catch (groovyx.net.http.HttpResponseException e) {
|
||||||
log.error "refreshAuthToken() >> Error: e.statusCode ${e.statusCode}"
|
log.error "refreshAuthToken() >> Error: e.statusCode ${e.statusCode}"
|
||||||
def reAttemptPeriod = 300 // in sec
|
def reAttemptPeriod = 300 // in sec
|
||||||
if (e.statusCode != 401) { //this issue might comes from exceed 20sec app execution, connectivity issue etc.
|
if (e.statusCode != 401) { // this issue might comes from exceed 20sec app execution, connectivity issue etc.
|
||||||
runIn(reAttemptPeriod, "refreshAuthToken")
|
runIn(reAttemptPeriod, "refreshAuthToken")
|
||||||
} else if (e.statusCode == 401) { //refresh token is expired
|
} else if (e.statusCode == 401) { // unauthorized
|
||||||
atomicState.reAttempt = atomicState.reAttempt + 1
|
atomicState.reAttempt = atomicState.reAttempt + 1
|
||||||
log.warn "reAttempt refreshAuthToken to try = ${atomicState.reAttempt}"
|
log.warn "reAttempt refreshAuthToken to try = ${atomicState.reAttempt}"
|
||||||
if (atomicState.reAttempt <= 3) {
|
if (atomicState.reAttempt <= 3) {
|
||||||
@@ -724,29 +709,21 @@ def sendJson(child = null, String jsonBody) {
|
|||||||
log.debug "Error return code = ${resp.data.status.code}"
|
log.debug "Error return code = ${resp.data.status.code}"
|
||||||
debugEvent("Error return code = ${resp.data.status.code}")
|
debugEvent("Error return code = ${resp.data.status.code}")
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
log.error "sent Json & got http status ${resp.status} - ${resp.status.code}"
|
|
||||||
debugEvent ("sent Json & got http status ${resp.status} - ${resp.status.code}")
|
|
||||||
|
|
||||||
//refresh the auth token
|
|
||||||
if (resp.status.code == 14) {
|
|
||||||
log.debug "Refreshing your auth_token!"
|
|
||||||
debugEvent ("Refreshing OAUTH Token")
|
|
||||||
refreshAuthToken()
|
|
||||||
return false
|
|
||||||
} else {
|
|
||||||
debugEvent ("Authentication error, invalid authentication method, lack of credentials, etc.")
|
|
||||||
log.error "Authentication error, invalid authentication method, lack of credentials, etc."
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch (groovyx.net.http.HttpResponseException e) {
|
||||||
log.debug "Exception Sending Json: " + e
|
log.trace "Exception Sending Json: " + e.response.data.status
|
||||||
debugEvent ("Exception Sending JSON: " + e)
|
debugEvent ("sent Json & got http status ${e.statusCode} - ${e.response.data.status.code}")
|
||||||
refreshAuthToken()
|
if (e.response.data.status.code == 14) {
|
||||||
return false
|
atomicState.action = "pollChildren"
|
||||||
}
|
log.debug "Refreshing your auth_token!"
|
||||||
|
refreshAuthToken()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
debugEvent("Authentication error, invalid authentication method, lack of credentials, etc.")
|
||||||
|
log.error "Authentication error, invalid authentication method, lack of credentials, etc."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (returnStatus == 0)
|
if (returnStatus == 0)
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user