mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-09 13:21:53 +00:00
Merge pull request #1942 from dkirker/DVCSMP-2598
DVCSMP-2598 Fix Wattvision throwing HttpResponseException
This commit is contained in:
@@ -136,10 +136,20 @@ def getDataForChild(child, startDate, endDate) {
|
|||||||
|
|
||||||
def wattvisionURL = wattvisionURL(child.deviceNetworkId, startDate, endDate)
|
def wattvisionURL = wattvisionURL(child.deviceNetworkId, startDate, endDate)
|
||||||
if (wattvisionURL) {
|
if (wattvisionURL) {
|
||||||
httpGet(uri: wattvisionURL) { response ->
|
try {
|
||||||
def json = new org.json.JSONObject(response.data.toString())
|
httpGet(uri: wattvisionURL) { response ->
|
||||||
child.addWattvisionData(json)
|
def json = new org.json.JSONObject(response.data.toString())
|
||||||
return "success"
|
child.addWattvisionData(json)
|
||||||
|
return "success"
|
||||||
|
}
|
||||||
|
} catch (groovyx.net.http.HttpResponseException httpE) {
|
||||||
|
log.error "Wattvision getDataForChild HttpResponseException: ${httpE} -> ${httpE.response.data}"
|
||||||
|
//log.debug "wattvisionURL = ${wattvisionURL}"
|
||||||
|
return "fail"
|
||||||
|
} catch (e) {
|
||||||
|
log.error "Wattvision getDataForChild General Exception: ${e}"
|
||||||
|
//log.debug "wattvisionURL = ${wattvisionURL}"
|
||||||
|
return "fail"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,9 +174,14 @@ def wattvisionURL(senorId, startDate, endDate) {
|
|||||||
if (diff > 259200000) { // 3 days in milliseconds
|
if (diff > 259200000) { // 3 days in milliseconds
|
||||||
// Wattvision only allows pulling 3 hours of data at a time
|
// Wattvision only allows pulling 3 hours of data at a time
|
||||||
startDate = new Date(hours: endDate.hours - 3)
|
startDate = new Date(hours: endDate.hours - 3)
|
||||||
|
} else if (diff < 10000) { // 10 seconds in milliseconds
|
||||||
|
// Wattvision throws errors when the difference between start_time and end_time is 5 seconds or less
|
||||||
|
// So we are going to make sure that we have a few more seconds of breathing room
|
||||||
|
use (groovy.time.TimeCategory) {
|
||||||
|
startDate = endDate - 10.seconds
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def params = [
|
def params = [
|
||||||
"sensor_id" : senorId,
|
"sensor_id" : senorId,
|
||||||
"api_id" : wattvisionApiAccess.id,
|
"api_id" : wattvisionApiAccess.id,
|
||||||
@@ -480,4 +495,3 @@ def connectionSuccessful(deviceName, iconSrc) {
|
|||||||
|
|
||||||
render contentType: 'text/html', data: html
|
render contentType: 'text/html', data: html
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user