Skip to content

Commit

Permalink
Changes to minimise code and removing uneccicary popups
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingTheUnknown committed Mar 20, 2021
1 parent b5ef782 commit ec8fee1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 38 deletions.
57 changes: 28 additions & 29 deletions octoprint_TpLinkAutoShutdown/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,37 @@ def on_after_startup(self):
else:
self._logger.info("+++++++++++ Aborted on Startup connection +++++++++++")


def plugHandler(self):
# If the plug being used is a smartPlug
if self._settings.get(["type"]) == "smartPlug":
self._logger.info(
f"The print has completed. Auto-shutdown is set to {str(self._settings.get(['smartPlug', 'auto']))}")
if self._settings.get(["smartPlug", "auto"]) and not self._settings.get(["smartPlug", "movieDone"]):
self._logger.info("Printer is being shutdown")
self.conn.shutdown()
# If the plug being used is a smartStrip
# Children are zero indexed, contrary to documentation
elif self._settings.get(["type"]) == "smartStrip":
# check the setting Preferences of each socket
if self._settings.get(["smartStrip", "deviceOne", "auto"]) and not self._settings.get(
["smartStrip", "deviceOne", "movieDone"]):
self._logger.info("Socket one is being shutdown")
self.conn.shutdown(0)
if self._settings.get(["smartStrip", "deviceTwo", "auto"]) and not self._settings.get(
["smartStrip", "deviceTwo", "movieDone"]):
self._logger.info("Socket two is being shutdown")
self.conn.shutdown(1)
if self._settings.get(["smartStrip", "deviceThree", "auto"]) and not self._settings.get(
["smartStrip", "deviceThree", "movieDone"]):
self._logger.info("Socket three is being shutdown")
self.conn.shutdown(2)

# Triggered through system events within the octoprint server
# noinspection PyArgumentList
def on_event(self, event, payload):
if event == "PrintDone":
# If the plug being used is a smartPlug
if self._settings.get(["type"]) == "smartPlug":
self._logger.info(f"The print has completed. Auto-shutdown is set to {str(self._settings.get(['smartPlug', 'auto']))}")
if self._settings.get(["smartPlug", "auto"]) and not self._settings.get(["smartPlug", "movieDone"]):
self._logger.info("Printer is being shutdown")
self.conn.shutdown()
# If the plug being used is a smartStrip
# Children are zero indexed, contrary to documentation
elif self._settings.get(["type"]) == "smartStrip":
# check the setting Preferences of each socket
if self._settings.get(["smartStrip", "deviceOne", "auto"]) and not self._settings.get(["smartStrip", "deviceOne", "movieDone"]):
self._logger.info("Socket one is being shutdown")
self.conn.shutdown(0)
if self._settings.get(["smartStrip", "deviceTwo", "auto"]) and not self._settings.get(["smartStrip", "deviceTwo", "movieDone"]):
self._logger.info("Socket two is being shutdown")
self.conn.shutdown(1)
if self._settings.get(["smartStrip", "deviceThree", "auto"]) and not self._settings.get(["smartStrip", "deviceThree", "movieDone"]):
self._logger.info("Socket three is being shutdown")
self.conn.shutdown(2)
self.plugHandler()
elif event == "PrintStarted":
if self._settings.get(["type"]) == "smartPlug":
self._logger.info(str(self._settings.get(["smartPlug", "auto"])))
Expand All @@ -66,16 +74,7 @@ def on_event(self, event, payload):
self.conn = wallStrip(self._settings.get(["url"]))
self.conn.update()
elif event == "MovieDone":
if self._settings.get(["type"]) == "smartPlug":
if self._settings.get(["smartPlug", "movieDone"]) and self._settings.get(["smartPlug", "auto"]):
self.conn.shutdown()
elif self._settings.get(["type"]) == "smartStrip":
if self._settings.get(["smartStrip", "deviceOne", "movieDone"]) and self._settings.get(["smartStrip", "deviceOne", "auto"]):
self.conn.shutdown(0)
if self._settings.get(["smartStrip", "deviceTwo", "movieDone"]) and self._settings.get(["smartStrip", "deviceTwo", "auto"]):
self.conn.shutdown(1)
if self._settings.get(["smartStrip", "deviceThree", "movieDone"]) and self._settings.get(["smartStrip", "deviceThree", "auto"]):
self.conn.shutdown(2)
self.plugHandler()
elif event == "PrintPaused":
self._logger.info("Print paused")

Expand Down
12 changes: 4 additions & 8 deletions octoprint_TpLinkAutoShutdown/static/js/navbarControll.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@

document.getElementById("turnOff").onclick = function turnOffPrinter() {
var conf = confirm("Are you sure?");
var conf = confirm("Are you sure you wish to turn OFF your smart plug?");

if (conf == true) {
OctoPrint.simpleApiCommand("TpLinkAutoShutdown", "turnOff", {"value" : "False"})
.done(function(responce) {
alert(responce.res);
});
.done(function(responce) {});
}else{
console.log("Operation cancelled");
alert("Operation cancelled");
}
}

document.getElementById("turnOn").onclick = function turnOnPrinter() {
var conf = confirm("are you sure?");
var conf = confirm("Are you sure you wish to turn ON your smart plug?");

if (conf == true) {
OctoPrint.simpleApiCommand("TpLinkAutoShutdown", "turnOn", {"value" : "False"})
.done(function(responce) {
alert(responce.res);
});
.done(function(responce) {});
}else{
console.log("The operation has been cancelled");
}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module

plugin_version = "1.0.3"
plugin_version = "1.0.4"


# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
Expand Down

0 comments on commit ec8fee1

Please sign in to comment.