-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbambuCmds.py
executable file
·85 lines (73 loc) · 3.46 KB
/
bambuCmds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/python3
#
#
# 1/28/2024 - initial release - https://github.com/bdwilson/obico-bambu-octoprint
#
# * Requires bambu_connect: https://github.com/mattcar15/bambu-connect
# pip install bambu-connect
#
# Warning: there is no verification that your commands were sent.
#
import time
from bambu_connect import BambuClient, PrinterStatus
import pprint
import os
import argparse
parser = argparse.ArgumentParser(description='Bambu Execute Client')
parser.add_argument('-c','--cmd', help='Command could be: pause, resume, stop, speed_slient, speed_normal, speed_sport, speed_ludacris, light_on, light_off', required=True)
parser.add_argument('-i','--ip', help='IP Address of Bambu Printer', required=True)
parser.add_argument('-s','--serial', help='Serial # of Bambu Printer', required=True)
parser.add_argument('-a','--access', help='Access code from your Printer menu', required=True)
args = vars(parser.parse_args())
class MyParser(argparse.ArgumentParser):
def error(self, message):
sys.stderr.write('error: %s\n' % message)
self.print_help()
sys.exit(2)
# info came from: https://community.home-assistant.io/t/bambu-lab-x1-x1c-mqtt/489510/29
# https://github.com/greghesp/ha-bambulab/blob/main/custom_components/bambu_lab/pybambu/commands.py
pause = f'{{"print": {{ "sequence_id": 0, "command": "pause"}}, "user_id":"1234567890"}}'
resume = f'{{"print": {{ "sequence_id": 0, "command": "resume"}}, "user_id":"1234567890"}}'
stop = f'{{"print": {{ "sequence_id": 0, "command": "stop"}}, "user_id":"1234567890"}}'
speed_silent = f'{{"print":{{"sequence_id":"2004","command":"print_speed","param":"1"}},"user_id":"1234567890"}}'
speed_normal = f'{{"print":{{"sequence_id":"2004","command":"print_speed","param":"2"}},"user_id":"1234567890"}}'
speed_sport = f'{{"print":{{"sequence_id":"2004","command":"print_speed","param":"3"}},"user_id":"1234567890"}}'
speed_ludacris = f'{{"print": {{"sequence_id":"2004","command":"print_speed","param":"4"}},"user_id":"1234567890"}}'
# P1 and X1 the led_node = chamber_light, A1 and A1 mini led_node = # camera_light
light_on = f'{{"system": {{"sequence_id": "0", "command": "ledctrl", "led_node": "camera_light", "led_mode": "on", "led_on_time": 500, "led_off_time": 500, "loop_times": 0, "interval_time": 0}}, "user_id":"1234567890"}}'
light_off = f'{{"system": {{"sequence_id": "0", "command": "ledctrl", "led_node": "camera_light", "led_mode": "off", "led_on_time": 500, "led_off_time": 500, "loop_times": 0, "interval_time": 0}}, "user_id":"1234567890"}}'
def main():
if (args['cmd'] == "pause"):
cmd = pause
elif (args['cmd'] == "resume"):
cmd = resume
elif (args['cmd'] == "stop"):
cmd = stop
elif (args['cmd'] == "light_on"):
cmd = light_on
elif (args['cmd'] == "light_off"):
cmd = light_off
elif (args['cmd'] == "speed_silent"):
cmd = speed_silent
elif (args['cmd'] == "speed_normal"):
cmd = speed_normal
elif (args['cmd'] == "speed_sport"):
cmd = speed_sport
elif (args['cmd'] == "speed_ludacris"):
cmd = speed_ludacris
else:
print("Invalid argument: %s", args['cmd'])
cmd = None
try:
bambu_client = BambuClient(args['ip'], args['access'], args['serial'])
except Exception as e:
print("Failed to connect %s", e)
try:
if (cmd is not None) and (bambu_client is not None):
bambu_client.executeClient.send_command(cmd)
print("Command successfully executed")
except Exception as e:
print("Failed to execute command: %s", e)
bambu_client.executeClient.disconnect()
if __name__ == "__main__":
main()