From 686041f5c3de94e93b634aaf1b3f6752c72c98cc Mon Sep 17 00:00:00 2001 From: Idan Bush Date: Mon, 5 May 2025 14:29:25 +0300 Subject: [PATCH 1/7] Fix AMS iteration --- bambulabs_api/ams.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/bambulabs_api/ams.py b/bambulabs_api/ams.py index 2664b79..5daf2f6 100644 --- a/bambulabs_api/ams.py +++ b/bambulabs_api/ams.py @@ -1,6 +1,6 @@ __all__ = ["AMS", "AMSHub"] -from typing import Any +from typing import Any, Iterator from bambulabs_api.filament_info import FilamentTray @@ -21,6 +21,9 @@ def __getitem__(self, ind: int) -> "AMS": def __setitem__(self, ind: int, item: "AMS"): self.ams_hub[ind] = item + def __iter__(self) -> Iterator["AMS"]: + return iter(self.ams_hub.values()) + class AMS: """ @@ -28,11 +31,11 @@ class AMS: """ def __init__( - self, humidity: int, temperature: float, **kwargs: dict[str, Any] - ) -> None: + self, humidity: int, humidity_pct:int, temperature: float, **kwargs: dict[str, Any]) -> None: self.filament_trays: dict[int, FilamentTray] = {} self.humidity = humidity + self.humidity_pct = humidity_pct self.temperature = temperature if "tray" in kwargs: @@ -41,7 +44,7 @@ def __init__( def process_trays(self, trays: list[dict[str, Any]]): for t in trays: id = t.get("id") - tray_n: Any | None = t.get("n", None) + tray_n: Any | None = t.get("tray_info_idx", None) if id and tray_n is not None: id = int(id) self.filament_trays[id] = FilamentTray.from_dict(t) @@ -79,3 +82,8 @@ def __getitem__(self, index: int): def __setitem__(self, index: int, filament_tray: FilamentTray): self.filament_trays[index] = filament_tray + + def __iter__(self) -> Iterator[FilamentTray]: + """Iterate over the FilamentTray objects inside this AMS.""" + return iter(self.filament_trays.values()) + From 9c654998d381907836c947e1649ea5ab2f7dbbb0 Mon Sep 17 00:00:00 2001 From: Idan Bush Date: Mon, 5 May 2025 14:35:39 +0300 Subject: [PATCH 2/7] Add MQTT ready to client, fixed some typos --- bambulabs_api/client.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/bambulabs_api/client.py b/bambulabs_api/client.py index 0128dec..483dbb8 100644 --- a/bambulabs_api/client.py +++ b/bambulabs_api/client.py @@ -60,6 +60,17 @@ def mqtt_client_connected(self): """ return self.mqtt_client.is_connected() + def mqtt_client_ready(self): + """ + Get the mqtt client is ready to send commands. + + Returns + ------- + bool + Check if the mqtt client is ready. + """ + return self.mqtt_client.ready() + def current_layer_num(self): """ Get current layer number @@ -348,17 +359,17 @@ def start_print(self, filename: str, Parameters ---------- - filename : str + filename: str The name of the file to be printed. - plate_number : (int | str) + plate_number: (int | str) The plate number of the file to be printed (assuming the 3mf file is created with Bambustudio/Orcaslicer). Or the path as a string. - use_ams : bool, optional + use_ams: bool, optional Whether to use the AMS system, by default True. - ams_mapping : list[int], optional + ams_mapping: list[int], optional The mapping of the filament trays to the plate numbers, by default [0]. - skip_objects (list[int] | None, optional): List of gcode objects to + skip_objects: (list[int] | None, optional) List of gcode objects to skip. Defaults to None. Returns From 99e548bb787d77a3d68494bdfeaca0aa0dd94993 Mon Sep 17 00:00:00 2001 From: Idan Bush Date: Mon, 5 May 2025 14:50:07 +0300 Subject: [PATCH 3/7] Fix AMS iteration and add "humidity_raw", and add another method to get the ams_hub --- bambulabs_api/mqtt_client.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/bambulabs_api/mqtt_client.py b/bambulabs_api/mqtt_client.py index a1db737..a2f2f41 100644 --- a/bambulabs_api/mqtt_client.py +++ b/bambulabs_api/mqtt_client.py @@ -817,14 +817,14 @@ def get_access_code(self) -> str: def set_auto_step_recovery(self, auto_step_recovery: bool = True) -> bool: """ - Set whether or not to set auto step recovery + Set whether to set auto step recovery or not. Args: auto_step_recovery (bool): flag to set auto step recovery. Default True. Returns: - bool: success of the auto step recovery command command + bool: success of the auto step recovery command """ return self.__publish_command({"print": { "command": "gcode_line", "auto_recovery": auto_step_recovery @@ -1209,24 +1209,27 @@ def process_ams(self): for k, v in enumerate(ams_units): humidity = int(v.get("humidity", 0)) + humidity_pct = int(v.get("humidity_raw", 0)) temp = float(v.get("temp", 0.0)) id = int(v.get("id", k)) - ams = AMS(humidity=humidity, temperature=temp) + ams = AMS(humidity=humidity, humidity_pct=humidity_pct, temperature=temp) trays: list[dict[str, Any]] = v.get("tray", []) - - if trays: - for tray_id, tray in enumerate(trays): - tray_id = int(tray.get("id", tray_id)) - tray_n: Any | None = tray.get("n", None) - if tray_n: - ams.set_filament_tray( - tray_index=tray_id, - filament_tray=FilamentTray.from_dict(tray)) + ams.process_trays(trays) self.ams_hub[id] = ams + def get_ams_hub(self) -> AMSHub: + """ + Get the AMS hub + + Returns: + AMSHub: AMS hub + """ + self.process_ams() + return self.ams_hub + def vt_tray(self) -> FilamentTray: """ Get Filament Tray of the external spool. From b62c544be47bdfb5a04b60a52e633749b07df786 Mon Sep 17 00:00:00 2001 From: Idan Bush Date: Mon, 5 May 2025 14:55:56 +0300 Subject: [PATCH 4/7] Fix filament info after last firmwares --- bambulabs_api/filament_info.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/bambulabs_api/filament_info.py b/bambulabs_api/filament_info.py index 8435186..33cc42e 100644 --- a/bambulabs_api/filament_info.py +++ b/bambulabs_api/filament_info.py @@ -97,8 +97,7 @@ class FilamentTray: Attributes ---------- - k: The k value. - n: The n value. + id: The ID of the tray. tag_uid: The tag UID. tray_id_name: The tray ID name. tray_info_idx: The tray info index. @@ -107,8 +106,8 @@ class FilamentTray: tray_color: The filament color of the tray. tray_weight: The tray weight. tray_diameter: The tray diameter. - tray_temp: The tray temperature. - tray_time: The tray time. + drying_temp: The tray temperature. + drying_time: The tray time. bed_temp_type: The bed temperature type. bed_temp: The bed temperature. nozzle_temp_max: The maximum nozzle temperature for the filament. @@ -116,8 +115,7 @@ class FilamentTray: xcam_info: The XCam information. tray_uuid: The tray UUID. """ - k: float - n: int + id: int tag_uid: str tray_id_name: str tray_info_idx: str @@ -126,8 +124,8 @@ class FilamentTray: tray_color: str tray_weight: str tray_diameter: str - tray_temp: str - tray_time: str + drying_temp: str + drying_time: str bed_temp_type: str bed_temp: str nozzle_temp_max: int From bb07cb1f7af9f0fc3584c30ff4ea9cccb07119b5 Mon Sep 17 00:00:00 2001 From: Idan Bush Date: Mon, 5 May 2025 15:09:36 +0300 Subject: [PATCH 5/7] Fix chamber temp from last firmware update (probably bambu bug) --- bambulabs_api/mqtt_client.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bambulabs_api/mqtt_client.py b/bambulabs_api/mqtt_client.py index a2f2f41..f697d7d 100644 --- a/bambulabs_api/mqtt_client.py +++ b/bambulabs_api/mqtt_client.py @@ -1036,7 +1036,24 @@ def get_chamber_temperature(self) -> float: Returns: float: chamber temperature """ - return float(self.__get_print("chamber_temper", 0.0)) + primary = self.__get_print("chamber_temper", None) + try: + return float(primary) + except (TypeError, ValueError): + pass # fall back + + device = self.__get_print("device", {}) + if isinstance(device, dict): + ctc = device.get("ctc", {}) + if isinstance(ctc, dict): + info = ctc.get("info", {}) + if isinstance(info, dict): + try: + return float(info.get("temp", 0.0)) + except (TypeError, ValueError): + pass + + return 0.0 def current_layer_num(self) -> int: """ From 83e4a04999a53c33955cac60d72735f29ffbac64 Mon Sep 17 00:00:00 2001 From: Idan Bush Date: Mon, 5 May 2025 16:09:49 +0300 Subject: [PATCH 6/7] Fix lint errors --- bambulabs_api/ams.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bambulabs_api/ams.py b/bambulabs_api/ams.py index 5daf2f6..143cb82 100644 --- a/bambulabs_api/ams.py +++ b/bambulabs_api/ams.py @@ -5,6 +5,12 @@ class AMSHub: + """ + Represents the Bambulabs AMS (Automated Material System) system hub. + + Returns: + AMSHub: AMSHub object containing all AMS objects. + """ def __init__(self) -> None: self.ams_hub: dict[int, AMS] = {} @@ -30,8 +36,7 @@ class AMS: Represents the Bambulab's AMS (Automated Material System) system. """ - def __init__( - self, humidity: int, humidity_pct:int, temperature: float, **kwargs: dict[str, Any]) -> None: + def __init__(self, humidity: int, humidity_pct: int, temperature: float, **kwargs: dict[str, Any]) -> None: self.filament_trays: dict[int, FilamentTray] = {} self.humidity = humidity @@ -86,4 +91,3 @@ def __setitem__(self, index: int, filament_tray: FilamentTray): def __iter__(self) -> Iterator[FilamentTray]: """Iterate over the FilamentTray objects inside this AMS.""" return iter(self.filament_trays.values()) - From 6bee751c29050ce0009b1765c379a837a2ef04d6 Mon Sep 17 00:00:00 2001 From: Idan Bush Date: Mon, 5 May 2025 17:53:59 +0300 Subject: [PATCH 7/7] Add more Bambu filament settings --- bambulabs_api/filament_info.py | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/bambulabs_api/filament_info.py b/bambulabs_api/filament_info.py index 33cc42e..2dbe0ce 100644 --- a/bambulabs_api/filament_info.py +++ b/bambulabs_api/filament_info.py @@ -46,6 +46,36 @@ class Filament(AMSFilamentSettings, Enum): SUPPORT_G: The Support G filament settings. SUPPORT_W: The Support W filament settings. BAMBU_TPU_95A: The Bambu TPU 95A filament settings. + BAMBU_ASA_AERO: The Bambu ASA AERO filament settings. + BAMBU_PLA_METAL: The Bambu PLA Metal filament settings. + BAMBU_PETG_TRANSLUCENT: The Bambu PETG Translucent filament settings. + BAMBU_PLA_MARBLE: The Bambu PLA Marble filament settings. + BAMBU_PLA_WOOD: The Bambu PLA Wood filament settings. + BAMBU_PLA_SILK_PLUS: The Bambu PLA Silk Plus filament settings. + BAMBU_PETG_HF: The Bambu PETG HF filament settings. + BAMBU_TPU_FOR_AMS: The Bambu TPU for AMS filament settings. + BAMBU_SUPPORT_FOR_ABS: The Bambu Support for ABS filament settings. + BAMBU_PC_FR: The Bambu PC FR filament settings. + BAMBU_PLA_GALAXY: The Bambu PLA Galaxy filament settings. + BAMBU_PA6_GF: The Bambu PA6 GF filament settings. + BAMBU_PLA_AERO: The Bambu PLA AERO filament settings. + BAMBU_ASA_CF: The Bambu ASA CF filament settings. + BAMBU_PETG_CF: The Bambu PETG CF filament settings. + BAMBU_SUPPORT_FOR_PA_PET: The Bambu Support for PA PET filament settings. + BAMBU_PLA_SPARKLE: The Bambu PLA Sparkle filament settings. + BAMBU_ABS_GF: The Bambu ABS GF filament settings. + BAMBU_PAHT_CF: The Bambu PAHT CF filament settings. + BAMBU_PLA_BASIC: The Bambu PLA Basic filament settings. + BAMBU_PLA_MATTE: The Bambu PLA Matte filament settings. + BAMBU_PA6_CF: The Bambu PA6 CF filament settings. + BAMBU_PLA_SILK: The Bambu PLA Silk filament settings. + BAMBU_PVA: The Bambu PVA filament settings. + BAMBU_PLA_CF: The Bambu PLA CF filament settings. + BAMBU_SUPPORT_FOR_PLA_PETG: The Bambu Support for PLA PETG filament settings. + BAMBU_TPU_95A_HF: The Bambu TPU 95A HF filament settings. + BAMBU_PPA_CF: The Bambu PPA CF filament settings. + BAMBU_ASA: The Bambu ASA filament settings. + BAMBU_PLA_GLOW: The Bambu PLA Glow filament settings. ABS: The ABS filament settings. ASA: The ASA filament settings. PA: The PA filament settings. @@ -68,6 +98,37 @@ class Filament(AMSFilamentSettings, Enum): SUPPORT_W = "GFS00", 190, 250, "PLA-S" BAMBU_TPU_95A = "GFU01", 200, 250, "TPU" + BAMBU_ASA_AERO = "GFB02", 240, 280, "ASA" + BAMBU_PLA_METAL = "GFA02", 190, 230, "PLA" + BAMBU_PETG_TRANSLUCENT = "GFG01", 230, 260, "PETG" + BAMBU_PLA_MARBLE = "GFA07", 190, 230, "PLA" + BAMBU_PLA_WOOD = "GFA16", 190, 240, "PLA" + BAMBU_PLA_SILK_PLUS = "GFA06", 210, 240, "PLA" + BAMBU_PETG_HF = "GFG02", 230, 260, "PETG" + BAMBU_TPU_FOR_AMS = "GFU02", 230, 230, "TPU" + BAMBU_SUPPORT_FOR_ABS = "GFS06", 190, 220, "Support" + BAMBU_PC_FR = "GFC01", 260, 280, "PC" + BAMBU_PLA_GALAXY = "GFA15", 190, 230, "PLA" + BAMBU_PA6_GF = "GFN08", 260, 290, "PA6" + BAMBU_PLA_AERO = "GFA11", 220, 260, "PLA" + BAMBU_ASA_CF = "GFB51", 250, 280, "ASA" + BAMBU_PETG_CF = "GFG50", 240, 270, "PETG" + BAMBU_SUPPORT_FOR_PA_PET = "GFS03", 280, 300, "Support" + BAMBU_PLA_SPARKLE = "GFA08", 190, 230, "PLA" + BAMBU_ABS_GF = "GFB50", 240, 270, "ABS" + BAMBU_PAHT_CF = "GFN04", 260, 290, "PAHT" + BAMBU_PLA_BASIC = "GFA00", 190, 230, "PLA" + BAMBU_PLA_MATTE = "GFA01", 190, 230, "PLA" + BAMBU_PA6_CF = "GFN05", 260, 290, "PA6" + BAMBU_PLA_SILK = "GFA05", 210, 230, "PLA" + BAMBU_PVA = "GFS04", 220, 250, "PVA" + BAMBU_PLA_CF = "GFA50", 210, 240, "PLA" + BAMBU_SUPPORT_FOR_PLA_PETG = "GFS05", 190, 220, "Support" + BAMBU_TPU_95A_HF = "GFU00", 230, 230, "TPU" + BAMBU_PPA_CF = "GFN06", 280, 310, "PPA" + BAMBU_ASA = "GFB01", 240, 270, "ASA" + BAMBU_PLA_GLOW = "GFA12", 190, 230, "PLA" + ABS = "GFB99", 240, 270, "ABS" ASA = "GFB98", 240, 270, "ASA" PA = "GFN99", 270, 300, "PA"