Skip to content

Commit 651dbfb

Browse files
committed
fix last db write lookup broken by recent comm PR
1 parent c2ba68c commit 651dbfb

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/vuegraf/vuegraf.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def dumpPoints(label, usageDataPoints):
141141
else:
142142
debug(f' {pprint.pformat(point)}')
143143

144-
def getLastDBTimeStamp(chanName, pointType, fooStartTime, fooStopTime, fooHistoryFlag):
144+
def getLastDBTimeStamp(deviceName, chanName, pointType, fooStartTime, fooStopTime, fooHistoryFlag):
145145
timeStr = ''
146146
# Get timestamp of last record in database
147147
# Influx v2
@@ -153,14 +153,15 @@ def getLastDBTimeStamp(chanName, pointType, fooStartTime, fooStopTime, fooHistor
153153
' r._measurement == "energy_usage" and ' +
154154
' r.' + tagName + ' == "' + pointType + '" and ' +
155155
' r._field == "usage" and ' +
156+
' r.station_name == "' + deviceName + '" and ' +
156157
' r.device_name == "' + chanName + '")' +
157158
'|> last()')
158159

159160
if len(result) > 0 and len(result[0].records) > 0:
160161
lastRecord = result[0].records[0]
161162
timeStr = lastRecord['_time'].isoformat()
162163
else: # Influx v1
163-
result = influx.query('select last(usage), time from energy_usage where (device_name = \'' + chanName + '\' AND ' + tagName + ' = \'' + pointType + '\')')
164+
result = influx.query('select last(usage), time from energy_usage where (station_name = \'' + station_name + '\' AND device_name = \'' + chanName + '\' AND ' + tagName + ' = \'' + pointType + '\')')
164165
if len(result) > 0:
165166
timeStr = next(result.get_points())['time']
166167

@@ -231,7 +232,7 @@ def extractDataPoints(device, usageDataPoints, pointType=None, historyStartTime=
231232
kwhUsage = chan.usage
232233
if kwhUsage is not None:
233234
if pointType is None:
234-
minuteHistoryStartTime, stopTimeMin, minuteHistoryEnabled = getLastDBTimeStamp(chanName, tagValue_minute, stopTime, stopTime, False)
235+
minuteHistoryStartTime, stopTimeMin, minuteHistoryEnabled = getLastDBTimeStamp(deviceName, chanName, tagValue_minute, stopTime, stopTime, False)
235236
if not minuteHistoryEnabled or chanNum in excludedDetailChannelNumbers:
236237
watts = float(minutesInAnHour * wattsInAKw) * kwhUsage
237238
timestamp = stopTime.replace(second=0)
@@ -277,7 +278,7 @@ def extractDataPoints(device, usageDataPoints, pointType=None, historyStartTime=
277278

278279
if collectDetails and detailedSecondsEnabled and historyStartTime is None:
279280
# Collect seconds (once per hour, never during history collection)
280-
secHistoryStartTime, stopTimeSec, secondHistoryEnabled = getLastDBTimeStamp(chanName, tagValue_second, detailedStartTime, stopTime, detailedSecondsEnabled)
281+
secHistoryStartTime, stopTimeSec, secondHistoryEnabled = getLastDBTimeStamp(deviceName, chanName, tagValue_second, detailedStartTime, stopTime, detailedSecondsEnabled)
281282
verbose('Get second details; device="{}"; start="{}"; stop="{}"'.format(chanName, secHistoryStartTime, stopTimeSec))
282283
usage, usage_start_time = account['vue'].get_chart_usage(chan, secHistoryStartTime, stopTimeSec, scale=Scale.SECOND.value, unit=Unit.KWH.value)
283284
usage_start_time = usage_start_time.replace(microsecond=0)

0 commit comments

Comments
 (0)