#21 Add PowerOFF when print is finished
This commit is contained in:
parent
df2ee686ec
commit
a3e770158c
@ -3,7 +3,8 @@
|
||||
<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/static/js/mystromswitch.js" beforeDir="false" afterPath="$PROJECT_DIR$/octoprint_mystromswitch/static/js/mystromswitch.js" 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/templates/mystromswitch_settings.jinja2" beforeDir="false" afterPath="$PROJECT_DIR$/octoprint_mystromswitch/templates/mystromswitch_settings.jinja2" afterDir="false" />
|
||||
</list>
|
||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
@ -48,13 +49,6 @@
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1574193087583</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00030" summary="#8 Relais ein / ausschalten von Ocotprint aus - url korrigiert">
|
||||
<created>1574606712347</created>
|
||||
<option name="number" value="00030" />
|
||||
<option name="presentableId" value="LOCAL-00030" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1574606712347</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00031" summary="#8 Relais ein / ausschalten von Ocotprint aus - Toggle Button enable / disable in Einstellunge - Databinding von Button">
|
||||
<created>1574607577396</created>
|
||||
<option name="number" value="00031" />
|
||||
@ -391,7 +385,14 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593348977898</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="79" />
|
||||
<task id="LOCAL-00079" summary="#21 Add PowerOFF when print is finished">
|
||||
<created>1593350619006</created>
|
||||
<option name="number" value="00079" />
|
||||
<option name="presentableId" value="LOCAL-00079" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1593350619006</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="80" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="UnknownFeatures">
|
||||
|
@ -30,7 +30,9 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
self.shutdownAfterPrintFinished = False
|
||||
self.powerOffAfterPrintFinished = False
|
||||
|
||||
self._timer = None
|
||||
self._status_timer = None
|
||||
self._abort_timer = None
|
||||
self._wait_for_timelapse_timer = None
|
||||
|
||||
self.energy = 0
|
||||
self.lastTimeStamp = 0
|
||||
@ -79,15 +81,57 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
icon="power-off"),
|
||||
dict(type="settings", custom_bindings=False)]
|
||||
|
||||
def _shutdown_timer_start(self):
|
||||
if self._abort_timer is not None:
|
||||
return
|
||||
|
||||
if self._wait_for_timelapse_timer is not None:
|
||||
self._wait_for_timelapse_timer.cancel()
|
||||
|
||||
self._logger.info("Starting abort shutdown timer.")
|
||||
|
||||
self._timeout_value = self.shutdownDelay
|
||||
self._abort_timer = RepeatedTimer(1, self._shutdown_timer_task)
|
||||
self._abort_timer.start()
|
||||
|
||||
def _shutdown_timer_task(self):
|
||||
if self._timeout_value is None:
|
||||
return
|
||||
|
||||
self._timeout_value -= 1
|
||||
if self._timeout_value <= 0:
|
||||
if self._wait_for_timelapse_timer is not None:
|
||||
self._wait_for_timelapse_timer.cancel()
|
||||
self._wait_for_timelapse_timer = None
|
||||
if self._abort_timer is not None:
|
||||
self._abort_timer.cancel()
|
||||
self._abort_timer = None
|
||||
if self.shutdownAfterPrintFinished:
|
||||
self._shutdown_system()
|
||||
elif self.powerOffAfterPrintFinished:
|
||||
self._setRelaisState(False)
|
||||
|
||||
def _status_timer_start(self):
|
||||
if self._timer is not None:
|
||||
self._timer.cancel()
|
||||
if self._status_timer is not None:
|
||||
self._status_timer.cancel()
|
||||
self._logger.info("Canceling Timer")
|
||||
|
||||
if self.intervall >= 1 and self.ip is not None:
|
||||
self._logger.info("Starting timer")
|
||||
self._timer = RepeatedTimer(self.intervall, self._status_timer_task)
|
||||
self._timer.start()
|
||||
self._status_timer = RepeatedTimer(self.intervall, self._status_timer_task)
|
||||
self._status_timer.start()
|
||||
|
||||
def _shutdown_system(self):
|
||||
self._powerCycleRelais(False, self.powerOffDelay)
|
||||
if self.shutdownAfterPrintFinished:
|
||||
shutdown_command = self._settings.global_get(["server", "commands", "systemShutdownCommand"])
|
||||
self._logger.info("Shutting down system with command: {command}".format(command=shutdown_command))
|
||||
try:
|
||||
import sarge
|
||||
p = sarge.run(shutdown_command, async=True)
|
||||
except Exception as e:
|
||||
self._logger.exception("Error when shutting down: {error}".format(error=e))
|
||||
return
|
||||
|
||||
def _status_timer_task(self):
|
||||
if self.ip is not None:
|
||||
@ -199,7 +243,7 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
self.shutdownAfterPrintFinished = True
|
||||
elif command == "disableShutdownAfterFinish":
|
||||
self._logger.info("disableShutdownAfterFinish")
|
||||
self.disableShutdownAfterFinish = False
|
||||
self.shutdownAfterPrintFinished = False
|
||||
elif command == "enablePowerOffAfterFinish":
|
||||
self._logger.info("enablePowerOffAfterFinish")
|
||||
self.powerOffAfterPrintFinished = True
|
||||
@ -207,7 +251,6 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
self._logger.info("disablePowerOffAfterFinish")
|
||||
self.powerOffAfterPrintFinished = False
|
||||
|
||||
|
||||
def get_api_commands(self):
|
||||
return dict(
|
||||
enableRelais=[],
|
||||
@ -275,13 +318,6 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
|
||||
def on_event(self, event, payload):
|
||||
|
||||
if event == Events.CLIENT_OPENED:
|
||||
#self._plugin_manager.send_plugin_message(self._identifier,
|
||||
# dict(automaticShutdownEnabled=self.shutdownAfterPrintFinished))
|
||||
#self._plugin_manager.send_plugin_message(self._identifier,
|
||||
# dict(automaticPowerOffEnabled=self.powerOffAfterPrintFinished))
|
||||
return
|
||||
|
||||
if not self.shutdownAfterPrintFinished and not self.powerOffAfterPrintFinished:
|
||||
return
|
||||
|
||||
@ -302,7 +338,7 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
||||
if (timelapse_type is not None and timelapse_type != "off"):
|
||||
self._wait_for_timelapse_start()
|
||||
else:
|
||||
self._timer_start()
|
||||
self._shutdown_timer_start()
|
||||
return
|
||||
|
||||
def get_update_information(self):
|
||||
|
@ -68,7 +68,7 @@
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="checked: settings.plugins.mystromswitch.showShutdownOctopiOption">Show option to automatic shutdown Octoprint after Print is finished
|
||||
</label>
|
||||
<span class="help-block"><small>{{ _('This setting shows the option to shut Octoprint down and switch your mySwitch off after your Print is finished.') }}</small></span>
|
||||
<span class="help-block"><small>{{ _('This setting shows the option to shut Octoprint down and switch your mySwitch off after your Print is finished. Use the "Delay after print is finished" option to determine after how many seconds Octoprint will be shutted down. After this use "Turn Relais Off Delay" to determine after how many seconds the Relas will be switched off') }}</small></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -77,11 +77,11 @@
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="checked: settings.plugins.mystromswitch.showPowerOffPrintFinishOption">Show option to turn off Relais after Print is finished
|
||||
</label>
|
||||
<span class="help-block"><small>{{ _('This setting shows the option to switch your mySwitch off after your Print is finished') }}</small></span>
|
||||
<span class="help-block"><small>{{ _('This setting shows the option to only switch your mySwitch off after your Print is finished. Use the "Delay after print is finished" Option to determine after how many seconds the Relais will switch off') }}</small></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<div class="control-group">
|
||||
<label class="control-label">{{ _('Delay after print is finished') }}</label>
|
||||
<div class="controls">
|
||||
<div class="input-append">
|
||||
|
Loading…
Reference in New Issue
Block a user