@@ -104,6 +104,8 @@ def __init__(self):
104
104
self .power_off_queue = []
105
105
self ._gcode_queued = False
106
106
self .active_timers = {"on" : {}, "off" : {}}
107
+ self .total_correction = 0
108
+ self .last_row = [0 ,0 ,0 ,0 ,0 ,0 ,0 ]
107
109
108
110
##~~ StartupPlugin mixin
109
111
@@ -151,7 +153,7 @@ def on_startup(self, host, port):
151
153
cursor .execute ('''VACUUM''' )
152
154
153
155
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
155
157
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
156
158
self .last_row_entered = True
157
159
self .total_correction = self .last_row [6 ] - self .last_row [5 ] #grandtotal - total
@@ -559,7 +561,7 @@ def check_status(self, plugip):
559
561
t = emeter_data ["get_realtime" ]["total_wh" ] / 1000.0
560
562
emeter_data ["get_realtime" ]["total_wh" ] += self .total_correction * 1000.0 #Add back total correction factor, so becomes grandtotal
561
563
elif "total" in emeter_data ["get_realtime" ]:
562
- t = emeter_data ["get_realtime" ]["total" ]
564
+ t = emeter_data ["get_realtime" ]["total" ]
563
565
emeter_data ["get_realtime" ]["total" ] += self .total_correction #Add back total correction factor, so becomes grandtotal
564
566
else :
565
567
t = ""
@@ -1303,5 +1305,5 @@ def __plugin_load__():
1303
1305
"octoprint.comm.protocol.temperatures.received" : __plugin_implementation__ .monitor_temperatures ,
1304
1306
"octoprint.access.permissions" : __plugin_implementation__ .get_additional_permissions ,
1305
1307
"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
1307
1309
}
0 commit comments