Merge pull request #1942 from dkirker/DVCSMP-2598

DVCSMP-2598 Fix Wattvision throwing HttpResponseException
This commit is contained in:
Vinay Rao
2017-04-25 11:33:00 -07:00
committed by GitHub

View File

@@ -136,11 +136,21 @@ def getDataForChild(child, startDate, endDate) {
def wattvisionURL = wattvisionURL(child.deviceNetworkId, startDate, endDate) def wattvisionURL = wattvisionURL(child.deviceNetworkId, startDate, endDate)
if (wattvisionURL) { if (wattvisionURL) {
try {
httpGet(uri: wattvisionURL) { response -> httpGet(uri: wattvisionURL) { response ->
def json = new org.json.JSONObject(response.data.toString()) def json = new org.json.JSONObject(response.data.toString())
child.addWattvisionData(json) child.addWattvisionData(json)
return "success" 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,8 +174,13 @@ 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,
@@ -480,4 +495,3 @@ def connectionSuccessful(deviceName, iconSrc) {
render contentType: 'text/html', data: html render contentType: 'text/html', data: html
} }