@@ -141,7 +141,7 @@ def dumpPoints(label, usageDataPoints):
141
141
else :
142
142
debug (f' { pprint .pformat (point )} ' )
143
143
144
- def getLastDBTimeStamp (chanName , pointType , fooStartTime , fooStopTime , fooHistoryFlag ):
144
+ def getLastDBTimeStamp (deviceName , chanName , pointType , fooStartTime , fooStopTime , fooHistoryFlag ):
145
145
timeStr = ''
146
146
# Get timestamp of last record in database
147
147
# Influx v2
@@ -153,14 +153,15 @@ def getLastDBTimeStamp(chanName, pointType, fooStartTime, fooStopTime, fooHistor
153
153
' r._measurement == "energy_usage" and ' +
154
154
' r.' + tagName + ' == "' + pointType + '" and ' +
155
155
' r._field == "usage" and ' +
156
+ ' r.station_name == "' + deviceName + '" and ' +
156
157
' r.device_name == "' + chanName + '")' +
157
158
'|> last()' )
158
159
159
160
if len (result ) > 0 and len (result [0 ].records ) > 0 :
160
161
lastRecord = result [0 ].records [0 ]
161
162
timeStr = lastRecord ['_time' ].isoformat ()
162
163
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 + '\' )' )
164
165
if len (result ) > 0 :
165
166
timeStr = next (result .get_points ())['time' ]
166
167
@@ -231,7 +232,7 @@ def extractDataPoints(device, usageDataPoints, pointType=None, historyStartTime=
231
232
kwhUsage = chan .usage
232
233
if kwhUsage is not None :
233
234
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 )
235
236
if not minuteHistoryEnabled or chanNum in excludedDetailChannelNumbers :
236
237
watts = float (minutesInAnHour * wattsInAKw ) * kwhUsage
237
238
timestamp = stopTime .replace (second = 0 )
@@ -277,7 +278,7 @@ def extractDataPoints(device, usageDataPoints, pointType=None, historyStartTime=
277
278
278
279
if collectDetails and detailedSecondsEnabled and historyStartTime is None :
279
280
# 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 )
281
282
verbose ('Get second details; device="{}"; start="{}"; stop="{}"' .format (chanName , secHistoryStartTime , stopTimeSec ))
282
283
usage , usage_start_time = account ['vue' ].get_chart_usage (chan , secHistoryStartTime , stopTimeSec , scale = Scale .SECOND .value , unit = Unit .KWH .value )
283
284
usage_start_time = usage_start_time .replace (microsecond = 0 )
0 commit comments