#21 Add PowerOFF when print is finished
This commit is contained in:
		
							
								
								
									
										19
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										19
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							@@ -2,7 +2,10 @@
 | 
			
		||||
<project version="4">
 | 
			
		||||
  <component name="ChangeListManager">
 | 
			
		||||
    <list default="true" id="7e2e0eec-b22e-4d48-8f24-196d1ed9b51a" name="Default Changelist" comment="">
 | 
			
		||||
      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
 | 
			
		||||
      <change beforePath="$PROJECT_DIR$/octoprint_mystromswitch/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/octoprint_mystromswitch/__init__.py" afterDir="false" />
 | 
			
		||||
      <change beforePath="$PROJECT_DIR$/octoprint_mystromswitch/static/js/mystromswitch.js" beforeDir="false" afterPath="$PROJECT_DIR$/octoprint_mystromswitch/static/js/mystromswitch.js" afterDir="false" />
 | 
			
		||||
      <change beforePath="$PROJECT_DIR$/octoprint_mystromswitch/templates/mystromswitch_sidebar.jinja2" beforeDir="false" afterPath="$PROJECT_DIR$/octoprint_mystromswitch/templates/mystromswitch_sidebar.jinja2" afterDir="false" />
 | 
			
		||||
    </list>
 | 
			
		||||
    <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
 | 
			
		||||
    <option name="SHOW_DIALOG" value="false" />
 | 
			
		||||
@@ -47,13 +50,6 @@
 | 
			
		||||
      <option name="presentableId" value="Default" />
 | 
			
		||||
      <updated>1574193087583</updated>
 | 
			
		||||
    </task>
 | 
			
		||||
    <task id="LOCAL-00023" summary="#6 UI Updates senden und anzeigen">
 | 
			
		||||
      <created>1574284365024</created>
 | 
			
		||||
      <option name="number" value="00023" />
 | 
			
		||||
      <option name="presentableId" value="LOCAL-00023" />
 | 
			
		||||
      <option name="project" value="LOCAL" />
 | 
			
		||||
      <updated>1574284365024</updated>
 | 
			
		||||
    </task>
 | 
			
		||||
    <task id="LOCAL-00024" summary="#6 UI Updates senden und anzeigen">
 | 
			
		||||
      <created>1574284478325</created>
 | 
			
		||||
      <option name="number" value="00024" />
 | 
			
		||||
@@ -390,7 +386,14 @@
 | 
			
		||||
      <option name="project" value="LOCAL" />
 | 
			
		||||
      <updated>1593346998123</updated>
 | 
			
		||||
    </task>
 | 
			
		||||
    <option name="localTasksCounter" value="72" />
 | 
			
		||||
    <task id="LOCAL-00072" summary="#21 Add PowerOFF when print is finished">
 | 
			
		||||
      <created>1593347175159</created>
 | 
			
		||||
      <option name="number" value="00072" />
 | 
			
		||||
      <option name="presentableId" value="LOCAL-00072" />
 | 
			
		||||
      <option name="project" value="LOCAL" />
 | 
			
		||||
      <updated>1593347175159</updated>
 | 
			
		||||
    </task>
 | 
			
		||||
    <option name="localTasksCounter" value="73" />
 | 
			
		||||
    <servers />
 | 
			
		||||
  </component>
 | 
			
		||||
  <component name="UnknownFeatures">
 | 
			
		||||
 
 | 
			
		||||
@@ -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:
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -3,12 +3,12 @@
 | 
			
		||||
    <label class="control-label" id="mystromswitchEnergyValue">Energy 0.0Wh</label>
 | 
			
		||||
    <button class="btn btn-primary" data-bind="click: onToggleRelayEvent, visible : onOffButtonEnabled">{{ _('Toggle Relais') }}</button>
 | 
			
		||||
    <label class="checkbox">
 | 
			
		||||
		<input type="checkbox" data-bind="enable: loginState.isUser(), change: onAutomaticShutdownEnabledChanged, visible :showShutdownOctopiOption">
 | 
			
		||||
		<input type="checkbox" data-bind="enable: loginState.isUser(), change: automaticShutdownEnabled, visible :showShutdownOctopiOption">
 | 
			
		||||
		{{ _('Shutdown Octoprint after print finishes') }}
 | 
			
		||||
	</label>
 | 
			
		||||
 | 
			
		||||
	<label class="checkbox">
 | 
			
		||||
		<input type="checkbox" data-bind="enable: loginState.isUser(), change: onAutomaticPowerOffEnabledChanged", visible: showPowerOffPrintFinishOption>
 | 
			
		||||
		<input type="checkbox" data-bind="enable: loginState.isUser(), change: automaticPowerOffEnabled", visible: showPowerOffPrintFinishOption>
 | 
			
		||||
		{{ _('Power Off Relais after print finishes') }}
 | 
			
		||||
	</label>
 | 
			
		||||
</div>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user