diff --git a/README.md b/README.md index 42212cf8..3430e422 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,9 @@ Each relay has the following settings *(in order of appearance)*: |-------------------------|------------------------------------------------------------------| | Active | Activates the relay control and indication on the navigation bar | | Label | The relay description to show on tooltip and in dialogs | -| This is printer relay | Closes the printer connection when turning this relay `OFF` | | Icon `ON` / `OFF` | An image or emoji to indicate the relay state (supports HTML) | +| This is printer relay | Closes the printer connection when turning this relay `OFF` | +| AutoConnect delay | Printer relay feature adjustment when turning it `ON` | | GPIO Number | The [GPIO pin on the Raspberry Pi](https://pinout.xyz/) | | Inverted output | For normally closed relay: the relay is `ON` without power | | Confirm turning `OFF` | Enables a confirmation dialog when turning the relay `OFF` | diff --git a/img/settings.png b/img/settings.png index 1d0074ed..128739ad 100644 Binary files a/img/settings.png and b/img/settings.png differ diff --git a/octoprint_octorelay/__init__.py b/octoprint_octorelay/__init__.py index cb4580cb..5788f8b5 100755 --- a/octoprint_octorelay/__init__.py +++ b/octoprint_octorelay/__init__.py @@ -8,7 +8,7 @@ import octoprint.plugin from octoprint.events import Events -from octoprint.util import RepeatedTimer +from octoprint.util import RepeatedTimer, ResettableTimer from octoprint.access.permissions import Permissions from .const import ( @@ -172,12 +172,10 @@ def on_event(self, event, payload): elif hasattr(Events, "CONNECTIONS_AUTOREFRESHED"): # Requires OctoPrint 1.9+ if event == Events.CONNECTIONS_AUTOREFRESHED: if payload is not None and "ports" in payload and len(payload["ports"]) > 0: - self._logger.debug("Connecting to the printer") - self._printer.connect() - #elif event == Events.PRINT_CANCELLING: - # self.print_stopped() - #elif event == Events.PRINT_CANCELLED: - # self.print_stopped() + delay = int(self._settings.get(["common", "delay"], merged=True) or 0) # expensive + self._logger.debug(f"AutoConnecting to the printer in {delay}s") + method = self._printer.connect + (method if delay == 0 else ResettableTimer(delay, method).start)() def handle_plugin_event(self, event, scope = None): if scope is None: diff --git a/octoprint_octorelay/const.py b/octoprint_octorelay/const.py index b6633a52..7a918ce3 100644 --- a/octoprint_octorelay/const.py +++ b/octoprint_octorelay/const.py @@ -34,7 +34,8 @@ def get_default_settings(): return { "common": { - "printer": "r2" + "printer": "r2", + "auto_connect_delay": 0 }, "r1": { "active": False, diff --git a/octoprint_octorelay/templates/octorelay_settings.jinja2 b/octoprint_octorelay/templates/octorelay_settings.jinja2 index 68e58c78..2b6d751c 100755 --- a/octoprint_octorelay/templates/octorelay_settings.jinja2 +++ b/octoprint_octorelay/templates/octorelay_settings.jinja2 @@ -61,6 +61,25 @@ + {% for state in ["on", "off"] %} +