From 739af51904b0e185bfc982563b20dc2ecb0e7098 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Sun, 7 Nov 2021 10:01:31 -0500 Subject: [PATCH] power: add "on_when_upload_queued" option When this option is set to "True", the device will power on after the file manager queues an upload for printing. Signed-off-by: Eric Callahan --- moonraker/components/power.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/moonraker/components/power.py b/moonraker/components/power.py index 7ab8fa8..715fb75 100644 --- a/moonraker/components/power.py +++ b/moonraker/components/power.py @@ -116,6 +116,8 @@ class PrinterPower: "set_device_power", self.set_device_power) self.server.register_event_handler( "server:klippy_shutdown", self._handle_klippy_shutdown) + self.server.register_event_handler( + "file_manager:upload_queued", self._handle_upload_queued) self.server.register_notification("power:power_changed") async def _check_klippy_printing(self) -> bool: @@ -162,6 +164,16 @@ class PrinterPower: " klippy shutdown") await self._process_request(dev, "off") + async def _handle_upload_queued(self, filename: str) -> None: + for name, dev in self.devices.items(): + if dev.has_on_when_queued(): + if dev.get_state() == "on": + # device already on + continue + logging.debug( + f"File '{filename}' queued, powering on device [{name}]") + await self._process_request(dev, "on") + async def _handle_list_devices(self, web_request: WebRequest ) -> Dict[str, Any]: @@ -290,6 +302,7 @@ class PowerDevice: raise config.error("Option 'restart_delay' must be above 0.0") self.bound_service: Optional[str] = config.get('bound_service', None) self.need_scheduled_restart = False + self.on_when_queued = config.getboolean('on_when_upload_queued', False) def _is_bound_to_klipper(self): return ( @@ -339,6 +352,9 @@ class PowerDevice: def has_off_when_shutdown(self) -> bool: return self.off_when_shutdown + def has_on_when_queued(self) -> bool: + return self.on_when_queued + def initialize(self) -> Optional[Coroutine]: if self.bound_service is None: return None