@@ -104,6 +104,8 @@ def __init__(self):
104104 self .power_off_queue = []
105105 self ._gcode_queued = False
106106 self .active_timers = {"on" : {}, "off" : {}}
107+ self .total_correction = 0
108+ self .last_row = [0 ,0 ,0 ,0 ,0 ,0 ,0 ]
107109
108110 ##~~ StartupPlugin mixin
109111
@@ -151,7 +153,7 @@ def on_startup(self, host, port):
151153 cursor .execute ('''VACUUM''' )
152154
153155 self .last_row = list (cursor .execute ('''SELECT id, timestamp, voltage, current, power, total, grandtotal
154- FROM energy_data ORDER BY ROWID DESC LIMIT 1''' ).fetchone ()) or [0 ,0 ,0 ,0 ,0 ,0 ,0 ] #Round to remove floating point imprecision
156+ FROM energy_data ORDER BY ROWID DESC LIMIT 1''' ).fetchone () or [0 ,0 ,0 ,0 ,0 ,0 ,0 ]) #Round to remove floating point imprecision
155157 self .last_row = self .last_row [:2 ] + [round (x ,6 ) for x in self .last_row [2 :]] #Round to correct floating point imprecision in sqlite
156158 self .last_row_entered = True
157159 self .total_correction = self .last_row [6 ] - self .last_row [5 ] #grandtotal - total
@@ -559,7 +561,7 @@ def check_status(self, plugip):
559561 t = emeter_data ["get_realtime" ]["total_wh" ] / 1000.0
560562 emeter_data ["get_realtime" ]["total_wh" ] += self .total_correction * 1000.0 #Add back total correction factor, so becomes grandtotal
561563 elif "total" in emeter_data ["get_realtime" ]:
562- t = emeter_data ["get_realtime" ]["total" ]
564+ t = emeter_data ["get_realtime" ]["total" ]
563565 emeter_data ["get_realtime" ]["total" ] += self .total_correction #Add back total correction factor, so becomes grandtotal
564566 else :
565567 t = ""
@@ -1303,5 +1305,5 @@ def __plugin_load__():
13031305 "octoprint.comm.protocol.temperatures.received" : __plugin_implementation__ .monitor_temperatures ,
13041306 "octoprint.access.permissions" : __plugin_implementation__ .get_additional_permissions ,
13051307 "octoprint.plugin.softwareupdate.check_config" : __plugin_implementation__ .get_update_information ,
1306- "octoprint.printer.handle_connect" : __plugin_implementation__ .on_connect
1308+ "octoprint.printer.handle_connect" : __plugin_implementation__ .on_connect
13071309 }
0 commit comments