diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3cec675..38a8b3e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,7 +3,8 @@ - + + @@ -48,90 +49,6 @@ 1574193087583 - - 1574609901438 - - - - 1574609901438 - - - 1574610253466 - - - - 1574610253466 - - - 1574707150761 - - - - 1574707150761 - - - 1574707411686 - - - - 1574707411686 - - - 1574707826329 - - - - 1574707826329 - - - 1574708023156 - - - - 1574708023156 - - - 1574708245896 - - - - 1574708245896 - - - 1574708497039 - - - - 1574708497039 - - - 1574710870028 - - - - 1574710870028 - - - 1574712024409 - - - - 1574712024409 - - - 1574712205852 - - - - 1574712205852 - - - 1574873790898 - - - - 1574873790898 - 1574873809876 @@ -391,7 +308,91 @@ 1593354891881 - + + 1593356663020 + + + + 1593356663020 + + + 1593627018087 + + + + 1593627018088 + + + 1593627195608 + + + + 1593627195608 + + + 1593628251128 + + + + 1593628251128 + + + 1593628347105 + + + + 1593628347105 + + + 1593628617461 + + + + 1593628617461 + + + 1593629014910 + + + + 1593629014910 + + + 1593629188987 + + + + 1593629188987 + + + 1593629352018 + + + + 1593629352018 + + + 1593629491361 + + + + 1593629491361 + + + 1593629609079 + + + + 1593629609079 + + + 1593630096392 + + + + 1593630096392 + + diff --git a/octoprint_mystromswitch/__init__.py b/octoprint_mystromswitch/__init__.py index cd45b0e..656dcc9 100644 --- a/octoprint_mystromswitch/__init__.py +++ b/octoprint_mystromswitch/__init__.py @@ -27,8 +27,13 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, self.showShutdownOctopiOption = False self.showPowerOffPrintFinishOption = False 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._abort_timer = None @@ -69,6 +74,19 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, self.shutdownDelay = self._settings.get_int(["shutdownDelay"]) self._logger.debug("shutdownDelay: %s" % self.shutdownDelay) + self.rememberShutdown = self._settings.get_boolean(["rememberShutdown"]) + self._logger.info("rememberShutdown: %s" % self.rememberShutdown) + + self.lastPowerOff = self._settings.get_boolean(["lastPowerOff"]) + self._logger.info("lastPowerOff: %s" % self.lastPowerOff) + + self.lastShutdown = self._settings.get_boolean(["lastShutdown"]) + self._logger.info("lastShutdown: %s" % self.lastShutdown) + + if self.rememberShutdown: + self.powerOffAfterPrintFinished = self.lastPowerOff + self.shutdownAfterPrintFinished = self.lastShutdown + self._status_timer_start() def get_assets(self): @@ -123,9 +141,9 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, if self._abort_timer is not None: self._abort_timer.cancel() self._abort_timer = None - if self.shutdownAfterPrintFinished: + if self.shutdownAfterPrintFinished and self.showShutdownOctopiOption: self._shutdown_system() - elif self.powerOffAfterPrintFinished: + elif self.powerOffAfterPrintFinished and self.showPowerOffPrintFinishOption: self._logger.info("only Shutdown Relais") self._setRelaisState(False) @@ -151,7 +169,6 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, self._logger.exception("Error when shutting down: {error}".format(error=e)) return - def _status_timer_task(self): if self.ip is not None: try: @@ -185,10 +202,9 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, self._logger.info("Ip is None") data = {"relay": True, "energy": 0, "onOffButtonEnabled": False, "showShutdownOctopiOption": False, "showPowerOffPrintFinishOption": False, "automaticShutdownEnabled": self.shutdownAfterPrintFinished, - "v": self.powerOffAfterPrintFinished} + "automaticPowerOffEnabled": self.powerOffAfterPrintFinished} self._plugin_manager.send_plugin_message(self._identifier, data) - def _setRelaisState(self, newState): nbRetry = 0 value = '0' @@ -207,7 +223,6 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, self._logger.info("Error during set Relais state") nbRetry = nbRetry + 1 - # Sets the switch to a specific inverse newState, # waits for a specified amount of time (max 3h), # then sets the the switch to the newState. @@ -235,7 +250,6 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, self._logger.exception(exp) nbRetry = nbRetry + 1 - def _toggleRelay(self): nbRetry = 0 while nbRetry < 3: @@ -250,7 +264,6 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, self._logger.info("Error during toggle Relais state") nbRetry = nbRetry + 1 - def on_api_command(self, command, data): if command == "enableRelais": self._logger.info("enableRelais") @@ -264,16 +277,31 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, elif command == "enableShutdownAfterFinish": self._logger.info("enableShutdownAfterFinish") self.shutdownAfterPrintFinished = True + if self.rememberShutdown: + self.lastShutdown = self.shutdownAfterPrintFinished + self._settings.set_boolean(["lastShutdown"], self.lastShutdown) + self._settings.save() elif command == "disableShutdownAfterFinish": self._logger.info("disableShutdownAfterFinish") self.shutdownAfterPrintFinished = False + if self.rememberShutdown: + self.lastShutdown = self.shutdownAfterPrintFinished + self._settings.set_boolean(["lastShutdown"], self.lastShutdown) + self._settings.save() elif command == "enablePowerOffAfterFinish": self._logger.info("enablePowerOffAfterFinish") self.powerOffAfterPrintFinished = True + if self.rememberShutdown: + self.lastPowerOff = self.powerOffAfterPrintFinished + self._settings.set_boolean(["lastPowerOff"], self.lastPowerOff) + self._settings.save() elif command == "disablePowerOffAfterFinish": self._logger.info("disablePowerOffAfterFinish") self.powerOffAfterPrintFinished = False - + if self.rememberShutdown: + self.lastPowerOff = self.powerOffAfterPrintFinished + self._settings.set_boolean(["lastPowerOff"], self.lastPowerOff) + self._settings.save() def get_api_commands(self): return dict( @@ -286,13 +314,11 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, enablePowerOffAfterFinish=[] ) - def on_after_startup(self): if self.powerOnOnStart: self._logger.info("Turn on Relais on Start") self._setRelaisState(True) - def on_shutdown(self): self._logger.info("on_shutdown_event") if self.powerOffOnShutdown: @@ -303,7 +329,6 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, self._logger.info("Turn off Relais on Shutdown Delayed") self._powerCycleRelais(False, self.powerOffDelay) - def on_settings_migrate(self, target, current): if target > current: if current <= 1: @@ -316,11 +341,13 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, self.showShutdownOctopiOption = False self.showPowerOffPrintFinishOption = False self.shutdownDelay = 60 - + if current <= 4: + self.lastShutdown = False + self.lastPowerOff = False + self.rememberShutdown = False def get_settings_version(self): - return 4 - + return 5 def get_settings_defaults(self): return dict( @@ -332,22 +359,22 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, powerOffDelay=0, showShutdownOctopiOption=False, showPowerOffPrintFinishOption=False, - shutdownDelay=60 + shutdownDelay=60, + lastShutdown=False, + lastPowerOff=False, + rememberShutdown=False ) - def get_settings_restricted_paths(self): return dict(admin=[ ['ip'] ]) - def on_settings_save(self, data): self._logger.info("on_settings_save") octoprint.plugin.SettingsPlugin.on_settings_save(self, data) self.initialize() - def on_event(self, event, payload): if not self.shutdownAfterPrintFinished and not self.powerOffAfterPrintFinished: return @@ -372,7 +399,6 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, self._shutdown_timer_start() return - def get_update_information(self): return dict( mystromswitch=dict( diff --git a/octoprint_mystromswitch/templates/mystromswitch_settings.jinja2 b/octoprint_mystromswitch/templates/mystromswitch_settings.jinja2 index 7a48b03..f78142f 100644 --- a/octoprint_mystromswitch/templates/mystromswitch_settings.jinja2 +++ b/octoprint_mystromswitch/templates/mystromswitch_settings.jinja2 @@ -63,6 +63,15 @@ Automatic Power Off Features + + + + remember Shutdown + + {{ _('Remember state of the checkboxes after reboot') }} + + + diff --git a/setup.py b/setup.py index f868b03..6b7970b 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_package = "octoprint_mystromswitch" plugin_name = "OctoPrint-MyStromSwitch" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "1.0.3" +plugin_version = "1.0.4" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module