Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jertel committed May 21, 2020
1 parent b9f7478 commit a123296
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/vuegraf.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,25 @@ def lookupChannelName(account, chan):
usage = account['vue'].get_usage_over_time(chan, start, account['end'])
index = 0
for watts in usage:
dataPoint = {
"measurement": "energy_usage",
"tags": {
"account_name": account['name'],
"device_name": chanName,
},
"fields": {
"usage": watts,
},
"time": start + datetime.timedelta(seconds=index)
}
index = index + 1
usageDataPoints.append(dataPoint)
if watts is not None:
dataPoint = {
"measurement": "energy_usage",
"tags": {
"account_name": account['name'],
"device_name": chanName,
},
"fields": {
"usage": watts,
},
"time": start + datetime.timedelta(seconds=index)
}
index = index + 1
usageDataPoints.append(dataPoint)

info('Submitted datapoints to database; account="{}"; points={}'.format(account['name'], len(usageDataPoints)))
influx.write_points(usageDataPoints)
except:
error('Failed to record new usage data', sys.exc_info())
error('Failed to record new usage data: {}'.format(sys.exc_info()))

pauseEvent.wait(INTERVAL_SECS)

Expand Down

0 comments on commit a123296

Please sign in to comment.