#21 Add PowerOFF when print is finished
This commit is contained in:
parent
8ea9f65048
commit
ebb6391bda
@ -48,13 +48,6 @@
|
|||||||
<option name="presentableId" value="Default" />
|
<option name="presentableId" value="Default" />
|
||||||
<updated>1574193087583</updated>
|
<updated>1574193087583</updated>
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00032" summary="#8 Relais ein / ausschalten von Ocotprint aus">
|
|
||||||
<created>1574607723126</created>
|
|
||||||
<option name="number" value="00032" />
|
|
||||||
<option name="presentableId" value="LOCAL-00032" />
|
|
||||||
<option name="project" value="LOCAL" />
|
|
||||||
<updated>1574607723126</updated>
|
|
||||||
</task>
|
|
||||||
<task id="LOCAL-00033" summary="#8 Relais ein / ausschalten von Ocotprint aus">
|
<task id="LOCAL-00033" summary="#8 Relais ein / ausschalten von Ocotprint aus">
|
||||||
<created>1574608168544</created>
|
<created>1574608168544</created>
|
||||||
<option name="number" value="00033" />
|
<option name="number" value="00033" />
|
||||||
@ -391,7 +384,14 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1593352569980</updated>
|
<updated>1593352569980</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="81" />
|
<task id="LOCAL-00081" summary="#21 Add PowerOFF when print is finished">
|
||||||
|
<created>1593352709926</created>
|
||||||
|
<option name="number" value="00081" />
|
||||||
|
<option name="presentableId" value="LOCAL-00081" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1593352709926</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="82" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="UnknownFeatures">
|
<component name="UnknownFeatures">
|
||||||
|
@ -84,6 +84,7 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
def _shutdown_timer_start(self):
|
def _shutdown_timer_start(self):
|
||||||
if self._abort_timer is not None:
|
if self._abort_timer is not None:
|
||||||
return
|
return
|
||||||
|
self._logger.info("_shutdown_timer_start")
|
||||||
|
|
||||||
if self._wait_for_timelapse_timer is not None:
|
if self._wait_for_timelapse_timer is not None:
|
||||||
self._wait_for_timelapse_timer.cancel()
|
self._wait_for_timelapse_timer.cancel()
|
||||||
@ -97,6 +98,7 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
def _wait_for_timelapse_start(self):
|
def _wait_for_timelapse_start(self):
|
||||||
if self._wait_for_timelapse_timer is not None:
|
if self._wait_for_timelapse_timer is not None:
|
||||||
return
|
return
|
||||||
|
self._logger.info("_wait_for_timelapse_start()")
|
||||||
|
|
||||||
self._wait_for_timelapse_timer = RepeatedTimer(5, self._wait_for_timelapse)
|
self._wait_for_timelapse_timer = RepeatedTimer(5, self._wait_for_timelapse)
|
||||||
self._wait_for_timelapse_timer.start()
|
self._wait_for_timelapse_timer.start()
|
||||||
@ -124,6 +126,7 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
if self.shutdownAfterPrintFinished:
|
if self.shutdownAfterPrintFinished:
|
||||||
self._shutdown_system()
|
self._shutdown_system()
|
||||||
elif self.powerOffAfterPrintFinished:
|
elif self.powerOffAfterPrintFinished:
|
||||||
|
self._logger.info("only Shutdown Relais")
|
||||||
self._setRelaisState(False)
|
self._setRelaisState(False)
|
||||||
|
|
||||||
def _status_timer_start(self):
|
def _status_timer_start(self):
|
||||||
@ -137,8 +140,8 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
self._status_timer.start()
|
self._status_timer.start()
|
||||||
|
|
||||||
def _shutdown_system(self):
|
def _shutdown_system(self):
|
||||||
|
self._logger.info("Shutdown Relais and System")
|
||||||
self._powerCycleRelais(False, self.powerOffDelay)
|
self._powerCycleRelais(False, self.powerOffDelay)
|
||||||
if self.shutdownAfterPrintFinished:
|
|
||||||
shutdown_command = self._settings.global_get(["server", "commands", "systemShutdownCommand"])
|
shutdown_command = self._settings.global_get(["server", "commands", "systemShutdownCommand"])
|
||||||
self._logger.info("Shutting down system with command: {command}".format(command=shutdown_command))
|
self._logger.info("Shutting down system with command: {command}".format(command=shutdown_command))
|
||||||
try:
|
try:
|
||||||
@ -148,7 +151,8 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
self._logger.exception("Error when shutting down: {error}".format(error=e))
|
self._logger.exception("Error when shutting down: {error}".format(error=e))
|
||||||
return
|
return
|
||||||
|
|
||||||
def _status_timer_task(self):
|
|
||||||
|
def _status_timer_task(self):
|
||||||
if self.ip is not None:
|
if self.ip is not None:
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
@ -184,7 +188,8 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
"v": self.powerOffAfterPrintFinished}
|
"v": self.powerOffAfterPrintFinished}
|
||||||
self._plugin_manager.send_plugin_message(self._identifier, data)
|
self._plugin_manager.send_plugin_message(self._identifier, data)
|
||||||
|
|
||||||
def _setRelaisState(self, newState):
|
|
||||||
|
def _setRelaisState(self, newState):
|
||||||
nbRetry = 0
|
nbRetry = 0
|
||||||
value = '0'
|
value = '0'
|
||||||
if newState:
|
if newState:
|
||||||
@ -202,10 +207,11 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
self._logger.info("Error during set Relais state")
|
self._logger.info("Error during set Relais state")
|
||||||
nbRetry = nbRetry + 1
|
nbRetry = nbRetry + 1
|
||||||
|
|
||||||
# Sets the switch to a specific inverse newState,
|
|
||||||
# waits for a specified amount of time (max 3h),
|
# Sets the switch to a specific inverse newState,
|
||||||
# then sets the the switch to the newState.
|
# waits for a specified amount of time (max 3h),
|
||||||
def _powerCycleRelais(self, newState, time):
|
# then sets the the switch to the newState.
|
||||||
|
def _powerCycleRelais(self, newState, time):
|
||||||
nbRetry = 0
|
nbRetry = 0
|
||||||
value = 'on'
|
value = 'on'
|
||||||
if newState:
|
if newState:
|
||||||
@ -229,7 +235,8 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
self._logger.exception(exp)
|
self._logger.exception(exp)
|
||||||
nbRetry = nbRetry + 1
|
nbRetry = nbRetry + 1
|
||||||
|
|
||||||
def _toggleRelay(self):
|
|
||||||
|
def _toggleRelay(self):
|
||||||
nbRetry = 0
|
nbRetry = 0
|
||||||
while nbRetry < 3:
|
while nbRetry < 3:
|
||||||
try:
|
try:
|
||||||
@ -243,7 +250,8 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
self._logger.info("Error during toggle Relais state")
|
self._logger.info("Error during toggle Relais state")
|
||||||
nbRetry = nbRetry + 1
|
nbRetry = nbRetry + 1
|
||||||
|
|
||||||
def on_api_command(self, command, data):
|
|
||||||
|
def on_api_command(self, command, data):
|
||||||
if command == "enableRelais":
|
if command == "enableRelais":
|
||||||
self._logger.info("enableRelais")
|
self._logger.info("enableRelais")
|
||||||
self._setRelaisState(True)
|
self._setRelaisState(True)
|
||||||
@ -266,7 +274,8 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
self._logger.info("disablePowerOffAfterFinish")
|
self._logger.info("disablePowerOffAfterFinish")
|
||||||
self.powerOffAfterPrintFinished = False
|
self.powerOffAfterPrintFinished = False
|
||||||
|
|
||||||
def get_api_commands(self):
|
|
||||||
|
def get_api_commands(self):
|
||||||
return dict(
|
return dict(
|
||||||
enableRelais=[],
|
enableRelais=[],
|
||||||
disableRelais=[],
|
disableRelais=[],
|
||||||
@ -277,12 +286,14 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
enablePowerOffAfterFinish=[]
|
enablePowerOffAfterFinish=[]
|
||||||
)
|
)
|
||||||
|
|
||||||
def on_after_startup(self):
|
|
||||||
|
def on_after_startup(self):
|
||||||
if self.powerOnOnStart:
|
if self.powerOnOnStart:
|
||||||
self._logger.info("Turn on Relais on Start")
|
self._logger.info("Turn on Relais on Start")
|
||||||
self._setRelaisState(True)
|
self._setRelaisState(True)
|
||||||
|
|
||||||
def on_shutdown(self):
|
|
||||||
|
def on_shutdown(self):
|
||||||
self._logger.info("on_shutdown_event")
|
self._logger.info("on_shutdown_event")
|
||||||
if self.powerOffOnShutdown:
|
if self.powerOffOnShutdown:
|
||||||
if self.powerOffDelay <= 0:
|
if self.powerOffDelay <= 0:
|
||||||
@ -292,7 +303,8 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
self._logger.info("Turn off Relais on Shutdown Delayed")
|
self._logger.info("Turn off Relais on Shutdown Delayed")
|
||||||
self._powerCycleRelais(False, self.powerOffDelay)
|
self._powerCycleRelais(False, self.powerOffDelay)
|
||||||
|
|
||||||
def on_settings_migrate(self, target, current):
|
|
||||||
|
def on_settings_migrate(self, target, current):
|
||||||
if target > current:
|
if target > current:
|
||||||
if current <= 1:
|
if current <= 1:
|
||||||
self.onOffButtonEnabled = False
|
self.onOffButtonEnabled = False
|
||||||
@ -305,10 +317,12 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
self.showPowerOffPrintFinishOption = False
|
self.showPowerOffPrintFinishOption = False
|
||||||
self.shutdownDelay = 60
|
self.shutdownDelay = 60
|
||||||
|
|
||||||
def get_settings_version(self):
|
|
||||||
|
def get_settings_version(self):
|
||||||
return 4
|
return 4
|
||||||
|
|
||||||
def get_settings_defaults(self):
|
|
||||||
|
def get_settings_defaults(self):
|
||||||
return dict(
|
return dict(
|
||||||
ip=None,
|
ip=None,
|
||||||
intervall=1,
|
intervall=1,
|
||||||
@ -321,18 +335,20 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
shutdownDelay=60
|
shutdownDelay=60
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_settings_restricted_paths(self):
|
|
||||||
|
def get_settings_restricted_paths(self):
|
||||||
return dict(admin=[
|
return dict(admin=[
|
||||||
['ip']
|
['ip']
|
||||||
])
|
])
|
||||||
|
|
||||||
def on_settings_save(self, data):
|
|
||||||
|
def on_settings_save(self, data):
|
||||||
self._logger.info("on_settings_save")
|
self._logger.info("on_settings_save")
|
||||||
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
|
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
|
||||||
self.initialize()
|
self.initialize()
|
||||||
|
|
||||||
def on_event(self, event, payload):
|
|
||||||
|
|
||||||
|
def on_event(self, event, payload):
|
||||||
if not self.shutdownAfterPrintFinished and not self.powerOffAfterPrintFinished:
|
if not self.shutdownAfterPrintFinished and not self.powerOffAfterPrintFinished:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -356,7 +372,8 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
self._shutdown_timer_start()
|
self._shutdown_timer_start()
|
||||||
return
|
return
|
||||||
|
|
||||||
def get_update_information(self):
|
|
||||||
|
def get_update_information(self):
|
||||||
return dict(
|
return dict(
|
||||||
mystromswitch=dict(
|
mystromswitch=dict(
|
||||||
displayName="OctoPrint-MyStromSwitch",
|
displayName="OctoPrint-MyStromSwitch",
|
||||||
|
Loading…
Reference in New Issue
Block a user