From c624769e9df80984be8e6e2d50ff5f8b764793f7 Mon Sep 17 00:00:00 2001 From: David Zingg Date: Sun, 28 Jun 2020 14:36:14 +0200 Subject: [PATCH] #21 Add PowerOFF when print is finished --- .idea/workspace.xml | 19 +++++++++++-------- octoprint_mystromswitch/__init__.py | 16 ++++++++-------- .../static/js/mystromswitch.js | 4 ++++ .../templates/mystromswitch_sidebar.jinja2 | 4 ++-- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 0fc312f..bdfa84f 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,10 @@ + + + diff --git a/octoprint_mystromswitch/__init__.py b/octoprint_mystromswitch/__init__.py index 235bd43..627d336 100644 --- a/octoprint_mystromswitch/__init__.py +++ b/octoprint_mystromswitch/__init__.py @@ -5,8 +5,8 @@ import octoprint.plugin import requests import ssl import time -from octoprint.util import RepeatedTimer from octoprint.events import eventManager, Events +from octoprint.util import RepeatedTimer class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, @@ -110,6 +110,8 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, data["onOffButtonEnabled"] = self.onOffButtonEnabled data["showShutdownOctopiOption"] = self.showShutdownOctopiOption data["showPowerOffPrintFinishOption"] = self.showPowerOffPrintFinishOption + data["automaticShutdownEnabled"] = self.shutdownAfterPrintFinished + data["automaticPowerOffEnabled"] = self.powerOffAfterPrintFinished self._plugin_manager.send_plugin_message(self._identifier, data) return except (requests.exceptions.ConnectionError, ValueError) as e: @@ -119,7 +121,8 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, else: self._logger.info("Ip is None") data = {"relay": True, "energy": 0, "onOffButtonEnabled": False, "showShutdownOctopiOption": False, - "showPowerOffPrintFinishOption": False} + "showPowerOffPrintFinishOption": False, "automaticShutdownEnabled": self.shutdownAfterPrintFinished, + "v": self.powerOffAfterPrintFinished} self._plugin_manager.send_plugin_message(self._identifier, data) def _setRelaisState(self, newState): @@ -203,10 +206,7 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, elif command == "disablePowerOffAfterFinish": self._logger.info("disablePowerOffAfterFinish") self.powerOffAfterPrintFinished = False - self._plugin_manager.send_plugin_message(self._identifier, - dict(showShutdownOctopiOption=self.shutdownAfterPrintFinished)) - self._plugin_manager.send_plugin_message(self._identifier, - dict(showPowerOffPrintFinishOption=self.powerOffAfterPrintFinished)) + def get_api_commands(self): return dict( @@ -277,9 +277,9 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, if event == Events.CLIENT_OPENED: self._plugin_manager.send_plugin_message(self._identifier, - dict(showShutdownOctopiOption=self.shutdownAfterPrintFinished)) + dict(automaticShutdownEnabled=self.shutdownAfterPrintFinished)) self._plugin_manager.send_plugin_message(self._identifier, - dict(showPowerOffPrintFinishOption=self.powerOffAfterPrintFinished)) + dict(automaticPowerOffEnabled=self.powerOffAfterPrintFinished)) return if not self.shutdownAfterPrintFinished and not self.powerOffAfterPrintFinished: diff --git a/octoprint_mystromswitch/static/js/mystromswitch.js b/octoprint_mystromswitch/static/js/mystromswitch.js index e512045..dd1e4ef 100644 --- a/octoprint_mystromswitch/static/js/mystromswitch.js +++ b/octoprint_mystromswitch/static/js/mystromswitch.js @@ -9,6 +9,8 @@ $(function() { self.onOffButtonEnabled = ko.observable(); self.showShutdownOctopiOption = ko.observable(); self.showPowerOffPrintFinishOption = ko.observable(); + self.automaticPowerOffEnabled = ko.observable(); + self.automaticShutdownEnabled = ko.observable(); self.mystromswitchPowerValue = document.getElementById("mystromswitchPowerValue") self.mystromswitchEnergyValue = document.getElementById("mystromswitchEnergyValue") @@ -81,6 +83,8 @@ $(function() { self.mystromswitchPowerValue.innerHTML = "myStrom switch not reachable" self.mystromswitchEnergyValue.innerHTML = "Check url in Plugin Settings" } + self.automaticShutdownEnabled = data.automaticShutdownEnabled; + self.automaticPowerOffEnabled = data.automaticPowerOffEnabled; } } diff --git a/octoprint_mystromswitch/templates/mystromswitch_sidebar.jinja2 b/octoprint_mystromswitch/templates/mystromswitch_sidebar.jinja2 index b68baa6..5cd5aa7 100644 --- a/octoprint_mystromswitch/templates/mystromswitch_sidebar.jinja2 +++ b/octoprint_mystromswitch/templates/mystromswitch_sidebar.jinja2 @@ -3,12 +3,12 @@