diff --git a/bambulabs_api/client.py b/bambulabs_api/client.py index 7a6104e..e9f8ca9 100644 --- a/bambulabs_api/client.py +++ b/bambulabs_api/client.py @@ -479,3 +479,53 @@ def skip_objects(self, obj_list: list[int]) -> bool: bool: if publish command is successful """ return self.__printerMQTTClient.skip_objects(obj_list=obj_list) + + def set_part_fan_speed(self, speed: int | float) -> bool: + """ + Set the fan speed of the part fan + + Args: + speed (int | float): The speed to set the part fan + + Returns: + bool: success of setting the fan speed + """ + return self.__printerMQTTClient.set_part_fan_speed(speed) + + def set_aux_fan_speed(self, speed: int | float) -> bool: + """ + Set the fan speed of the aux part fan + + Args: + speed (int | float): The speed to set the part fan + + Returns: + bool: success of setting the fan speed + """ + return self.__printerMQTTClient.set_aux_fan_speed(speed) + + def set_chamber_fan_speed(self, speed: int | float) -> bool: + """ + Set the fan speed of the chamber fan + + Args: + speed (int | float): The speed to set the part fan + + Returns: + bool: success of setting the fan speed + """ + return self.__printerMQTTClient.set_chamber_fan_speed(speed) + + def set_auto_step_recovery(self, auto_step_recovery: bool = True) -> bool: + """ + Set whether or not to set auto step recovery + + Args: + auto_step_recovery (bool): flag to set auto step recovery. + Default True. + + Returns: + bool: success of the auto step recovery command command + """ + return self.__printerMQTTClient.set_auto_step_recovery( + auto_step_recovery) diff --git a/bambulabs_api/mqtt_client.py b/bambulabs_api/mqtt_client.py index b051729..ce26a47 100644 --- a/bambulabs_api/mqtt_client.py +++ b/bambulabs_api/mqtt_client.py @@ -331,6 +331,66 @@ def set_bed_temperature(self, temperature: int) -> bool: """ return self.__send_gcode_line(f"M140 S{temperature}\n") + def set_part_fan_speed(self, speed: int | float) -> bool: + """ + Set the fan speed of the part fan + + Args: + speed (int | float): The speed to set the part fan + + Returns: + bool: success of setting the fan speed + """ + return self._set_fan_speed(speed, 1) + + def set_aux_fan_speed(self, speed: int | float) -> bool: + """ + Set the fan speed of the aux part fan + + Args: + speed (int | float): The speed to set the part fan + + Returns: + bool: success of setting the fan speed + """ + return self._set_fan_speed(speed, 2) + + def set_chamber_fan_speed(self, speed: int | float) -> bool: + """ + Set the fan speed of the chamber fan + + Args: + speed (int | float): The speed to set the part fan + + Returns: + bool: success of setting the fan speed + """ + return self._set_fan_speed(speed, 3) + + def _set_fan_speed(self, speed: int | float, fan_num: int) -> bool: + """ + Set the fan speed of a fan + + Args: + speed (int | float): The speed to set the fan to + fan_num (int): Id of the fan to be set + + Returns: + bool: success of setting the fan speed + """ + if isinstance(speed, int): + if speed > 255 or speed < 0: + raise ValueError(f"Fan Speed {speed} is not between 0 and 255") + return self.__send_gcode_line(f"M106 P{fan_num} S{speed}\n") + + elif isinstance(speed, float): + if speed < 0 or speed > 1: + raise ValueError(f"Fan Speed {speed} is not between 0 and 1") + speed = round(255 / speed) + return self.__send_gcode_line(f"M106 P{fan_num} S{speed}\n") + + raise ValueError("Fan Speed is not float or int") + def set_bed_height(self, height: int) -> bool: """ Set the absolute height of the bed (Z-axis). @@ -353,6 +413,21 @@ def auto_home(self) -> bool: """ return self.__send_gcode_line("G28\n") + def set_auto_step_recovery(self, auto_step_recovery: bool = True) -> bool: + """ + Set whether or not to set auto step recovery + + Args: + auto_step_recovery (bool): flag to set auto step recovery. + Default True. + + Returns: + bool: success of the auto step recovery command command + """ + return self.__publish_command({"print": { + "command": "gcode_line", "auto_recovery": auto_step_recovery + }}) + def set_print_speed_lvl(self, speed_lvl: int = 1) -> bool: """ Set the print speed