From 3173f4e5e65cd1ed268dc575e38f9c0e0ee68374 Mon Sep 17 00:00:00 2001 From: max <51723915+mxxmxxm2@users.noreply.github.com> Date: Sun, 31 May 2026 13:35:16 +0200 Subject: [PATCH 1/6] Enhance upload_file to log total uploaded bytes Added a callback to track total uploaded bytes during file upload. --- bambulabs_api/ftp_client.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/bambulabs_api/ftp_client.py b/bambulabs_api/ftp_client.py index a05a7e3..4c7ce21 100644 --- a/bambulabs_api/ftp_client.py +++ b/bambulabs_api/ftp_client.py @@ -102,8 +102,19 @@ def wrapper(self: 'PrinterFTPClient', *args, **kwargs) -> Any: @connect_and_run def upload_file(self, file: BinaryIO, file_path: str) -> str: - return self.ftps.storbinary(f'STOR {file_path}', file, blocksize=32768, - callback=lambda x: logger.debug(f"Uploaded {x} bytes")) # noqa # pylint: disable=logging-fstring-interpolation + total_bytes = 0 + def upload_callback(data: bytes): + nonlocal total_bytes + total_bytes += len(data) + logging.info(f"Total uploaded {total_bytes} bytes") + logging.debug(f"Uploaded {data} bytes") + + return self.ftps.storbinary( + f'STOR {file_path}', + file, + blocksize=32768, + callback=upload_callback + ) @connect_and_run def list_directory(self, path: str | None = None) -> tuple[str, list[str]]: From 83d9c25b70b59a5d1b67c0279b15b38c8f44c9d9 Mon Sep 17 00:00:00 2001 From: max <51723915+mxxmxxm2@users.noreply.github.com> Date: Sun, 31 May 2026 14:00:15 +0200 Subject: [PATCH 2/6] Fix nozzle temperature handling in mqtt_client.py Updated temperature threshold and argument descriptions for nozzle temperature setting. --- bambulabs_api/mqtt_client.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/bambulabs_api/mqtt_client.py b/bambulabs_api/mqtt_client.py index d2b06bf..df30937 100644 --- a/bambulabs_api/mqtt_client.py +++ b/bambulabs_api/mqtt_client.py @@ -853,14 +853,12 @@ def set_nozzle_temperature( """ Set the nozzle temperature. Note P1 firmware version above 01.06 does not support M104. M109 is used instead (set and wait for temperature). - To prevent long wait times, if temperature is set to below 40 deg cel, + To prevent long wait times, if temperature is set to below 60 deg cel, no temperature is set, override flag is provided to circumvent this. Args: - temperature (int): The temperature to set the bed to + temperature (int): The temperature to set the nozzle to override (bool): Whether to override guards. Default to False - Args: - temperature (int): temperature to set the nozzle to Returns: bool: success of setting the nozzle temperature @@ -870,8 +868,8 @@ def set_nozzle_temperature( else: if temperature < 60 and not override: logger.warning( - "Attempting to set low bed temperature not recommended. " - "Set override flag to true to if you're sure you want to " + "Attempting to set low nozzle temperature not recommended. " + "Set override flag to true if you're sure you want to " f"run M109 S{temperature};" ) return False From 0c96905d25649202456f901248d03a005d1bdd27 Mon Sep 17 00:00:00 2001 From: max Date: Sun, 31 May 2026 19:00:34 +0200 Subject: [PATCH 3/6] addapt to new logger code --- bambulabs_api/ftp_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bambulabs_api/ftp_client.py b/bambulabs_api/ftp_client.py index 4c7ce21..495c45f 100644 --- a/bambulabs_api/ftp_client.py +++ b/bambulabs_api/ftp_client.py @@ -106,8 +106,8 @@ def upload_file(self, file: BinaryIO, file_path: str) -> str: def upload_callback(data: bytes): nonlocal total_bytes total_bytes += len(data) - logging.info(f"Total uploaded {total_bytes} bytes") - logging.debug(f"Uploaded {data} bytes") + logger.info(f"Total uploaded {total_bytes} bytes") + logger.debug(f"Uploaded {data} bytes") return self.ftps.storbinary( f'STOR {file_path}', From f2cca32cda4ff727b7cba389cb52c6497742d6d0 Mon Sep 17 00:00:00 2001 From: max Date: Mon, 1 Jun 2026 15:37:24 +0200 Subject: [PATCH 4/6] intruduced bed_leveling as contolled parametr --- bambulabs_api/client.py | 6 ++++-- bambulabs_api/mqtt_client.py | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bambulabs_api/client.py b/bambulabs_api/client.py index 39f776a..9d286a2 100644 --- a/bambulabs_api/client.py +++ b/bambulabs_api/client.py @@ -352,7 +352,8 @@ def start_print(self, filename: str, ams_mapping: list[int] = [0], skip_objects: list[int] | None = None, flow_calibration: bool = True, - ) -> bool: + bed_leveling: bool = True, + ) -> bool: """ Start printing a file. @@ -383,7 +384,8 @@ def start_print(self, filename: str, use_ams, ams_mapping, skip_objects, - flow_calibration) + flow_calibration, + bed_leveling) def stop_print(self) -> bool: """ diff --git a/bambulabs_api/mqtt_client.py b/bambulabs_api/mqtt_client.py index df30937..a60790d 100644 --- a/bambulabs_api/mqtt_client.py +++ b/bambulabs_api/mqtt_client.py @@ -470,7 +470,8 @@ def start_print_3mf(self, filename: str, ams_mapping: list[int] = [0], skip_objects: list[int] | None = None, flow_calibration: bool = True, - ) -> bool: + bed_leveling: bool = True, + ) -> bool: """ Start the print @@ -500,7 +501,7 @@ def start_print_3mf(self, filename: str, "command": "project_file", "param": plate_location, "file": filename, - "bed_leveling": True, + "bed_leveling": bool(bed_leveling), "bed_type": "textured_plate", "flow_cali": bool(flow_calibration), "vibration_cali": True, From 64f8caf41e0ad87cc101bda51de7d45538086891 Mon Sep 17 00:00:00 2001 From: max Date: Mon, 1 Jun 2026 15:37:49 +0200 Subject: [PATCH 5/6] if not specified, plate_number defaulting to 1 --- bambulabs_api/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bambulabs_api/client.py b/bambulabs_api/client.py index 9d286a2..d104a6d 100644 --- a/bambulabs_api/client.py +++ b/bambulabs_api/client.py @@ -347,7 +347,7 @@ def upload_file(self, file: BinaryIO, filename: str = "ftp_upload.gcode") -> str return "No file uploaded." def start_print(self, filename: str, - plate_number: int | str, + plate_number: int | str = 1, use_ams: bool = True, ams_mapping: list[int] = [0], skip_objects: list[int] | None = None, From ae31ac3ab41c4ec1444ceac2dfe8c1e3c79f171e Mon Sep 17 00:00:00 2001 From: max Date: Mon, 1 Jun 2026 15:39:21 +0200 Subject: [PATCH 6/6] corrected docstring and also simplified Ternary Operator: Swapped the logic to "enable" if enable else "disable" to make it easier to read --- bambulabs_api/mqtt_client.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bambulabs_api/mqtt_client.py b/bambulabs_api/mqtt_client.py index a60790d..d6b2db3 100644 --- a/bambulabs_api/mqtt_client.py +++ b/bambulabs_api/mqtt_client.py @@ -516,20 +516,19 @@ def start_print_3mf(self, filename: str, def set_onboard_printer_timelapse(self, enable: bool = True): """ - Enable/disable the printer's onboard timelapse/video - functionality. + Enable/disable the printer's onboard timelapse/video functionality. Args: - enable (bool): object list to skip objects. + enable (bool): True to enable recording, False to disable it. Defaults to True. Returns: - bool: if publish command is successful. + bool: True if the publish command is successful, False otherwise. """ return self.__publish_command({ "camera": { "command": "ipcam_record_set", - "control": "disable" if not enable else "enable" + "control": "enable" if enable else "disable" } })