Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions bambulabs_api/mqtt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,21 +460,27 @@ def __send_gcode_line(self, gcode_command: str) -> bool:
return self.__publish_command({"print": {"command": "gcode_line",
"param": f"{gcode_command}"}})

def send_gcode(self, gcode_command: str | list[str]) -> bool:
def send_gcode(
self,
gcode_command: str | list[str],
gcode_check: bool = True) -> bool:
"""
Send a G-code line command to the printer

Args:
gcode_command (str | list[str]): G-code command(s) to send to the
printer
gcode_check: (bool): whether to check gcode validity.
Default to True.
"""
if isinstance(gcode_command, str):
if not is_valid_gcode(gcode_command):
if gcode_check and not is_valid_gcode(gcode_command):
raise ValueError("Invalid G-code command")

return self.__send_gcode_line(gcode_command)
elif isinstance(gcode_command, list): # type: ignore
if any(not is_valid_gcode(g) for g in gcode_command):
if gcode_check and any(
not is_valid_gcode(g) for g in gcode_command):
raise ValueError("Invalid G-code command")
return self.__send_gcode_line("\n".join(gcode_command))

Expand Down