#21 Add PowerOFF when print is finished
This commit is contained in:
parent
4e8620c8ab
commit
85e18076a0
@ -3,7 +3,7 @@
|
|||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="7e2e0eec-b22e-4d48-8f24-196d1ed9b51a" name="Default Changelist" comment="">
|
<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$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" 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" />
|
<change beforePath="$PROJECT_DIR$/octoprint_mystromswitch/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/octoprint_mystromswitch/__init__.py" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
@ -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-00036" summary="#8 Relais ein / ausschalten von Ocotprint aus">
|
|
||||||
<created>1574609901438</created>
|
|
||||||
<option name="number" value="00036" />
|
|
||||||
<option name="presentableId" value="LOCAL-00036" />
|
|
||||||
<option name="project" value="LOCAL" />
|
|
||||||
<updated>1574609901438</updated>
|
|
||||||
</task>
|
|
||||||
<task id="LOCAL-00037" summary="#8 Relais ein / ausschalten von Ocotprint aus">
|
<task id="LOCAL-00037" summary="#8 Relais ein / ausschalten von Ocotprint aus">
|
||||||
<created>1574610253466</created>
|
<created>1574610253466</created>
|
||||||
<option name="number" value="00037" />
|
<option name="number" value="00037" />
|
||||||
@ -391,7 +384,14 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1593354891881</updated>
|
<updated>1593354891881</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="85" />
|
<task id="LOCAL-00085" summary="#21 Add PowerOFF when print is finished">
|
||||||
|
<created>1593356663020</created>
|
||||||
|
<option name="number" value="00085" />
|
||||||
|
<option name="presentableId" value="LOCAL-00085" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1593356663020</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="86" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="UnknownFeatures">
|
<component name="UnknownFeatures">
|
||||||
|
@ -27,8 +27,13 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
self.showShutdownOctopiOption = False
|
self.showShutdownOctopiOption = False
|
||||||
self.showPowerOffPrintFinishOption = False
|
self.showPowerOffPrintFinishOption = False
|
||||||
self.shutdownDelay = 60
|
self.shutdownDelay = 60
|
||||||
self.shutdownAfterPrintFinished = False
|
|
||||||
self.powerOffAfterPrintFinished = False
|
self.rememberShutdown = False
|
||||||
|
self.lastPowerOff = False
|
||||||
|
self.lastShutdown = False
|
||||||
|
|
||||||
|
self.shutdownAfterPrintFinished = self.lastShutdown if self.rememberShutdown else False
|
||||||
|
self.powerOffAfterPrintFinished = self.lastPowerOff if self.rememberShutdown else False
|
||||||
|
|
||||||
self._status_timer = None
|
self._status_timer = None
|
||||||
self._abort_timer = None
|
self._abort_timer = None
|
||||||
@ -69,6 +74,19 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
self.shutdownDelay = self._settings.get_int(["shutdownDelay"])
|
self.shutdownDelay = self._settings.get_int(["shutdownDelay"])
|
||||||
self._logger.debug("shutdownDelay: %s" % self.shutdownDelay)
|
self._logger.debug("shutdownDelay: %s" % self.shutdownDelay)
|
||||||
|
|
||||||
|
self.rememberShutdown = self._settings.get_boolean(["rememberShutdown"])
|
||||||
|
self._logger.debug("rememberShutdown: %s" % self.rememberShutdown)
|
||||||
|
|
||||||
|
self.lastPowerOff = self._settings.get_int(["lastPowerOff"])
|
||||||
|
self._logger.debug("lastPowerOff: %s" % self.lastPowerOff)
|
||||||
|
|
||||||
|
self.lastShutdown = self._settings.get_int(["lastShutdown"])
|
||||||
|
self._logger.debug("lastShutdown: %s" % self.lastShutdown)
|
||||||
|
|
||||||
|
if self.rememberShutdown:
|
||||||
|
self.powerOffAfterPrintFinished = self.lastPowerOff
|
||||||
|
self.shutdownAfterPrintFinished = self.lastShutdown
|
||||||
|
|
||||||
self._status_timer_start()
|
self._status_timer_start()
|
||||||
|
|
||||||
def get_assets(self):
|
def get_assets(self):
|
||||||
@ -123,9 +141,9 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
if self._abort_timer is not None:
|
if self._abort_timer is not None:
|
||||||
self._abort_timer.cancel()
|
self._abort_timer.cancel()
|
||||||
self._abort_timer = None
|
self._abort_timer = None
|
||||||
if self.shutdownAfterPrintFinished:
|
if self.shutdownAfterPrintFinished and self.showShutdownOctopiOption:
|
||||||
self._shutdown_system()
|
self._shutdown_system()
|
||||||
elif self.powerOffAfterPrintFinished:
|
elif self.powerOffAfterPrintFinished and self.showPowerOffPrintFinishOption:
|
||||||
self._logger.info("only Shutdown Relais")
|
self._logger.info("only Shutdown Relais")
|
||||||
self._setRelaisState(False)
|
self._setRelaisState(False)
|
||||||
|
|
||||||
@ -151,7 +169,6 @@ 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:
|
||||||
@ -188,7 +205,6 @@ 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'
|
||||||
@ -207,7 +223,6 @@ 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,
|
# Sets the switch to a specific inverse newState,
|
||||||
# waits for a specified amount of time (max 3h),
|
# waits for a specified amount of time (max 3h),
|
||||||
# then sets the the switch to the newState.
|
# then sets the the switch to the newState.
|
||||||
@ -235,7 +250,6 @@ 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:
|
||||||
@ -250,7 +264,6 @@ 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")
|
||||||
@ -264,16 +277,23 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
elif command == "enableShutdownAfterFinish":
|
elif command == "enableShutdownAfterFinish":
|
||||||
self._logger.info("enableShutdownAfterFinish")
|
self._logger.info("enableShutdownAfterFinish")
|
||||||
self.shutdownAfterPrintFinished = True
|
self.shutdownAfterPrintFinished = True
|
||||||
|
if self.rememberShutdown:
|
||||||
|
self.lastShutdown = self.shutdownAfterPrintFinished
|
||||||
elif command == "disableShutdownAfterFinish":
|
elif command == "disableShutdownAfterFinish":
|
||||||
self._logger.info("disableShutdownAfterFinish")
|
self._logger.info("disableShutdownAfterFinish")
|
||||||
self.shutdownAfterPrintFinished = False
|
self.shutdownAfterPrintFinished = False
|
||||||
|
if self.rememberShutdown:
|
||||||
|
self.lastShutdown = self.shutdownAfterPrintFinished
|
||||||
elif command == "enablePowerOffAfterFinish":
|
elif command == "enablePowerOffAfterFinish":
|
||||||
self._logger.info("enablePowerOffAfterFinish")
|
self._logger.info("enablePowerOffAfterFinish")
|
||||||
self.powerOffAfterPrintFinished = True
|
self.powerOffAfterPrintFinished = True
|
||||||
|
if self.rememberShutdown:
|
||||||
|
self.lastPowerOff = self.powerOffAfterPrintFinished
|
||||||
elif command == "disablePowerOffAfterFinish":
|
elif command == "disablePowerOffAfterFinish":
|
||||||
self._logger.info("disablePowerOffAfterFinish")
|
self._logger.info("disablePowerOffAfterFinish")
|
||||||
self.powerOffAfterPrintFinished = False
|
self.powerOffAfterPrintFinished = False
|
||||||
|
if self.rememberShutdown:
|
||||||
|
self.lastPowerOff = self.powerOffAfterPrintFinished
|
||||||
|
|
||||||
def get_api_commands(self):
|
def get_api_commands(self):
|
||||||
return dict(
|
return dict(
|
||||||
@ -286,13 +306,11 @@ 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:
|
||||||
@ -303,7 +321,6 @@ 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:
|
||||||
@ -316,11 +333,13 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
self.showShutdownOctopiOption = False
|
self.showShutdownOctopiOption = False
|
||||||
self.showPowerOffPrintFinishOption = False
|
self.showPowerOffPrintFinishOption = False
|
||||||
self.shutdownDelay = 60
|
self.shutdownDelay = 60
|
||||||
|
if current <= 4:
|
||||||
|
self.lastShutdown = False
|
||||||
|
self.lastPowerOff = False
|
||||||
|
self.rememberShutdown = False
|
||||||
|
|
||||||
def get_settings_version(self):
|
def get_settings_version(self):
|
||||||
return 4
|
return 5
|
||||||
|
|
||||||
|
|
||||||
def get_settings_defaults(self):
|
def get_settings_defaults(self):
|
||||||
return dict(
|
return dict(
|
||||||
@ -332,22 +351,22 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
powerOffDelay=0,
|
powerOffDelay=0,
|
||||||
showShutdownOctopiOption=False,
|
showShutdownOctopiOption=False,
|
||||||
showPowerOffPrintFinishOption=False,
|
showPowerOffPrintFinishOption=False,
|
||||||
shutdownDelay=60
|
shutdownDelay=60,
|
||||||
|
lastShutdown=False,
|
||||||
|
lastPowerOff=False,
|
||||||
|
rememberShutdown=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
@ -372,7 +391,6 @@ 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(
|
||||||
|
Loading…
Reference in New Issue
Block a user