diff --git a/prusa/connect/printer/__init__.py b/prusa/connect/printer/__init__.py index bb5b1c5..29247d5 100644 --- a/prusa/connect/printer/__init__.py +++ b/prusa/connect/printer/__init__.py @@ -145,6 +145,8 @@ def __init__(self, self.set_printer_ready) self.set_handler(const.Command.CANCEL_PRINTER_READY, self.cancel_printer_ready) + self.set_handler(const.Command.DIALOG_ACTION, + self.dialog_action) self.fs = Filesystem(sep=os.sep, event_cb=self.event_cb) self.inotify_handler = InotifyHandler(self.fs) @@ -503,6 +505,14 @@ def cancel_printer_ready(self, caller: Command) -> Dict[str, Any]: return {'source': const.Source.CONNECT} raise ValueError("Can't cancel, printer isn't ready") + def dialog_action(self, caller: Command) -> Dict[str, Any]: + """Process dialog action""" + # pylint: disable=unused-argument + if not caller.kwargs: + raise ValueError( + f"{const.Command.DIALOG_ACTION} requires kwargs") + return {'source': const.Source.CONNECT} + def get_file_info(self, caller: Command) -> Dict[str, Any]: """Returns file info for a given file, if it exists.""" # pylint: disable=unused-argument diff --git a/prusa/connect/printer/const.py b/prusa/connect/printer/const.py index b16ee8e..045f9ef 100644 --- a/prusa/connect/printer/const.py +++ b/prusa/connect/printer/const.py @@ -148,6 +148,7 @@ class Command(Enum): LOAD_FILAMENT = "LOAD_FILAMENT" UNLOAD_FILAMENT = "UNLOAD_FILAMENT" SLOT_ACTION = "SLOT_ACTION" + DIALOG_ACTION = "DIALOG_ACTION" class TransferType(Enum): diff --git a/prusa/connect/printer/models.py b/prusa/connect/printer/models.py index e1b9d9c..55a1224 100644 --- a/prusa/connect/printer/models.py +++ b/prusa/connect/printer/models.py @@ -126,6 +126,7 @@ def __init__(self, transfer_id: Optional[int] = None, reason: Optional[str] = None, state: Optional[const.State] = None, + dialog_id: Optional[int] = None, **kwargs): super().__init__(timestamp=timestamp) self.event = event @@ -135,6 +136,7 @@ def __init__(self, self.transfer_id = transfer_id self.reason = reason self.state = state + self.dialog_id = dialog_id self.data = kwargs def to_payload(self): @@ -144,7 +146,11 @@ def to_payload(self): "source": self.source.value, "data": filter_null(self.data), } - for attr in ('command_id', 'job_id', 'transfer_id', 'reason'): + for attr in ('command_id', + 'job_id', + 'transfer_id', + 'reason', + 'dialog_id'): value = getattr(self, attr) if value: data[attr] = value