|
3 | 3 | import json |
4 | 4 | import logging |
5 | 5 | import math |
| 6 | +import re |
6 | 7 | import ssl |
7 | 8 | import threading |
8 | 9 | import time |
@@ -78,7 +79,9 @@ def __init__(self, config: BambuConfig | None = None): |
78 | 79 | * _gcode_state `READ ONLY` State reported for job status (FAILED/RUNNING/PAUSE/IDLE/FINISH). |
79 | 80 | * _gcode_file `READ ONLY` The name of the current or last printed gcode file. |
80 | 81 | * _3mf_file `READ ONLY` The name of the 3mf file currently being printed. |
| 82 | + * _3mf_file_md5 `READ ONLY` The md5 of the 3mf file currently being printed. |
81 | 83 | * _plate_num `READ ONLY` The selected plate # for the current 3mf file. |
| 84 | + * _plate_type `READ ONLY` The selected plate type for the current 3mf file. |
82 | 85 | * _subtask_name `READ ONLY` The name of the active subtask. |
83 | 86 | * _print_type `READ ONLY` Not entirely sure. Reports "idle" when no job is active. |
84 | 87 | * _percent_complete `READ ONLY` Percentage complete for the current active job. |
@@ -152,7 +155,9 @@ class level attributes are marked private. |
152 | 155 | self._gcode_state = "" |
153 | 156 | self._gcode_file = "" |
154 | 157 | self._3mf_file = "" |
| 158 | + self._3mf_file_md5 = "" |
155 | 159 | self._plate_num = 0 |
| 160 | + self._plate_type = PlateType.NONE |
156 | 161 | self._subtask_name = "" |
157 | 162 | self._print_type = "" |
158 | 163 | self._percent_complete = 0 |
@@ -456,6 +461,7 @@ def print_3mf_file( |
456 | 461 | """ |
457 | 462 | self._3mf_file = f"{name}" |
458 | 463 | self._plate_num = int(plate) |
| 464 | + self._plate_type = bed |
459 | 465 |
|
460 | 466 | file = copy.deepcopy(bambucommands.PRINT_3MF_FILE) |
461 | 467 |
|
@@ -961,20 +967,32 @@ def _on_message(self, message: str): |
961 | 967 | elif "print" in message: |
962 | 968 | status = message["print"] |
963 | 969 |
|
964 | | - if "command" in status and status["command"] == "project_file": |
| 970 | + if ( |
| 971 | + status.get("command") == "project_file" |
| 972 | + and status.get("result") == "success" |
| 973 | + ): |
965 | 974 | self._start_time = 0 |
966 | | - if self._3mf_file: |
967 | | - logger.debug("project_file request acknowledged") |
968 | | - else: |
969 | | - url = status.get("url", None) |
970 | | - subtask = status.get("subtask_name", None) |
971 | | - if url and subtask and url.startswith("https://"): |
972 | | - self._3mf_file = f"/cache/{subtask}.3mf" |
973 | | - else: |
974 | | - if "file" in status: |
975 | | - self._3mf_file = status.get("file", "") |
976 | | - else: |
977 | | - logger.warning("unable to determine file being printed") |
| 975 | + |
| 976 | + url = status.get("url", "") |
| 977 | + parts = url.split("://", 1) |
| 978 | + if len(parts) == 2: |
| 979 | + self._3mf_file = parts[1] |
| 980 | + |
| 981 | + self._3mf_file_md5 = status.get("md5", "") |
| 982 | + self._subtask_name = status.get("subtask_name", "") |
| 983 | + |
| 984 | + param = status.get("param", None) |
| 985 | + if param: |
| 986 | + match = re.search(r"plate_(\d{1,2})", param) |
| 987 | + if match: |
| 988 | + self._plate_num = int(match.group(1)) |
| 989 | + |
| 990 | + bed_type = status.get("bed_type", None) |
| 991 | + self._plate_type = ( |
| 992 | + PlateType[bed_type.upper()] |
| 993 | + if bed_type and bed_type.upper() in PlateType.__members__ |
| 994 | + else PlateType.NONE |
| 995 | + ) |
978 | 996 |
|
979 | 997 | # let's sleep for a couple seconds and do a full refresh |
980 | 998 | # if ams filament settings have changed |
@@ -1025,6 +1043,10 @@ def _on_message(self, message: str): |
1025 | 1043 | self._gcode_state = status["gcode_state"] |
1026 | 1044 | if self._gcode_state in ("FINISH", "FAILED") and self._3mf_file: |
1027 | 1045 | self._3mf_file = "" |
| 1046 | + self._3mf_file_md5 = "" |
| 1047 | + self._plate_num = None |
| 1048 | + self._plate_type = PlateType.NONE |
| 1049 | + self._subtask_name = "" |
1028 | 1050 |
|
1029 | 1051 | if "subtask_name" in status: |
1030 | 1052 | self._subtask_name = status["subtask_name"] |
@@ -1453,10 +1475,18 @@ def subtask_name(self): |
1453 | 1475 | def current_3mf_file(self): |
1454 | 1476 | return self._3mf_file |
1455 | 1477 |
|
| 1478 | + @property |
| 1479 | + def current_3mf_file_md5(self): |
| 1480 | + return self._3mf_file_md5 |
| 1481 | + |
1456 | 1482 | @property |
1457 | 1483 | def current_plate_num(self): |
1458 | 1484 | return self._plate_num |
1459 | 1485 |
|
| 1486 | + @property |
| 1487 | + def current_plate_type(self): |
| 1488 | + return self._plate_type |
| 1489 | + |
1460 | 1490 | @property |
1461 | 1491 | def gcode_file(self): |
1462 | 1492 | return self._gcode_file |
|
0 commit comments