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 <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2021-11-07 10:01:31 -05:00 committed by Eric Callahan
parent 484c4aea59
commit 739af51904
1 changed files with 16 additions and 0 deletions

View File

@ -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