Skip to content

Commit

Permalink
WIP: add dialog_id
Browse files Browse the repository at this point in the history
  • Loading branch information
filipkotoucek committed Apr 21, 2024
1 parent b885d97 commit 7c2a4a2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions prusa/connect/printer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -503,6 +505,12 @@ 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
#TODO: check if all nessecary arguments are present
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
Expand Down
1 change: 1 addition & 0 deletions prusa/connect/printer/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 7 additions & 1 deletion prusa/connect/printer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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
Expand Down

0 comments on commit 7c2a4a2

Please sign in to comment.