Skip to content

Commit 0baf96c

Browse files
committed
adjust for no data and add some init variables, #363
1 parent e334a46 commit 0baf96c

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

octoprint_tplinksmartplug/__init__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -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
}

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
plugin_name = "OctoPrint-TPLinkSmartplug"
1515

1616
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
17-
plugin_version = "1.0.4rc5"
17+
plugin_version = "1.0.4rc6"
1818

1919
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
2020
# module

0 commit comments

Comments
 (0)