flashforge-python-api 1.6.0__py3-none-any.whl → 3.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- flashforge/__init__.py +337 -256
- flashforge/_removed.py +65 -0
- flashforge/api/__init__.py +12 -18
- flashforge/api/constants/__init__.py +11 -11
- flashforge/api/constants/commands.py +18 -15
- flashforge/api/constants/endpoints.py +11 -11
- flashforge/api/misc/__init__.py +8 -8
- flashforge/api/network/__init__.py +11 -11
- flashforge/api/network/utils.py +71 -71
- flashforge/backends/__init__.py +80 -0
- flashforge/backends/connect.py +275 -0
- flashforge/backends/creator5_backend.py +191 -0
- flashforge/backends/dual_api_backend.py +170 -0
- flashforge/backends/dual_api_models.py +145 -0
- flashforge/backends/http_core.py +431 -0
- flashforge/backends/http_printer_backend.py +254 -0
- flashforge/backends/legacy_backend.py +436 -0
- flashforge/backends/printer_backend.py +217 -0
- flashforge/backends/types.py +125 -0
- flashforge/capabilities/__init__.py +98 -0
- flashforge/capabilities/models.py +67 -0
- flashforge/capabilities/palettes/__init__.py +28 -0
- flashforge/capabilities/palettes/ad5x_palette.py +70 -0
- flashforge/capabilities/palettes/creator5_palette.py +78 -0
- flashforge/capabilities/palettes/palette.py +54 -0
- flashforge/{api/controls/creator5_palette.py → capabilities/palettes/palette_snap.py} +226 -258
- flashforge/capabilities/printer_capabilities.py +145 -0
- flashforge/capabilities/registry.py +125 -0
- flashforge/capabilities/resolve_model.py +61 -0
- flashforge/discovery/__init__.py +39 -39
- flashforge/discovery/discovery.py +730 -763
- flashforge/exceptions.py +90 -51
- flashforge/models/__init__.py +52 -55
- flashforge/models/machine_info.py +540 -543
- flashforge/{api/controls/info.py → models/machine_info_parser.py} +35 -242
- flashforge/models/responses.py +119 -254
- flashforge/status/__init__.py +43 -0
- flashforge/status/printer_snapshot.py +396 -0
- flashforge/tcp/__init__.py +55 -54
- flashforge/tcp/a3_client.py +427 -427
- flashforge/tcp/a4_client.py +304 -304
- flashforge/tcp/ff_client.py +609 -590
- flashforge/tcp/gcode/__init__.py +15 -13
- flashforge/tcp/gcode/a3_gcode_controller.py +109 -109
- flashforge/tcp/gcode/gcode_controller.py +292 -308
- flashforge/tcp/gcode/gcodes.py +81 -99
- flashforge/tcp/gcode/legacy_gcode_controller.py +56 -0
- flashforge/tcp/parsers/__init__.py +27 -27
- flashforge/tcp/parsers/endstop_status.py +248 -248
- flashforge/tcp/parsers/location_info.py +83 -83
- flashforge/tcp/parsers/print_status.py +180 -180
- flashforge/tcp/parsers/printer_info.py +146 -146
- flashforge/tcp/parsers/temp_info.py +218 -218
- flashforge/tcp/parsers/thumbnail_info.py +274 -274
- flashforge/tcp/tcp_client.py +52 -12
- flashforge/threemf/__init__.py +40 -40
- flashforge/threemf/parser.py +560 -560
- flashforge/threemf/warnings.py +58 -58
- {flashforge_python_api-1.6.0.dist-info → flashforge_python_api-3.0.0.dist-info}/METADATA +46 -47
- flashforge_python_api-3.0.0.dist-info/RECORD +69 -0
- {flashforge_python_api-1.6.0.dist-info → flashforge_python_api-3.0.0.dist-info}/WHEEL +1 -1
- {flashforge_python_api-1.6.0.dist-info → flashforge_python_api-3.0.0.dist-info}/licenses/LICENSE +21 -21
- flashforge/api/controls/__init__.py +0 -17
- flashforge/api/controls/control.py +0 -413
- flashforge/api/controls/files.py +0 -210
- flashforge/api/controls/job_control.py +0 -896
- flashforge/api/controls/temp_control.py +0 -309
- flashforge/client.py +0 -609
- flashforge_python_api-1.6.0.dist-info/RECORD +0 -52
- {flashforge_python_api-1.6.0.dist-info → flashforge_python_api-3.0.0.dist-info}/entry_points.txt +0 -0
|
@@ -1,248 +1,248 @@
|
|
|
1
|
-
"""
|
|
2
|
-
FlashForge Python API - Endstop Status Parser
|
|
3
|
-
|
|
4
|
-
Parses endstop and machine status information from M119 command responses.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
import logging
|
|
8
|
-
import re
|
|
9
|
-
from enum import Enum
|
|
10
|
-
from typing import Optional
|
|
11
|
-
|
|
12
|
-
logger = logging.getLogger(__name__)
|
|
13
|
-
|
|
14
|
-
# Pre-compiled regex to match key:value pairs where value is an integer
|
|
15
|
-
KV_PATTERN = re.compile(r"([A-Za-z0-9-]+):\s*(\d+)")
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class MachineStatus(Enum):
|
|
19
|
-
"""Enumerates the possible operational statuses of the machine."""
|
|
20
|
-
|
|
21
|
-
BUILDING_FROM_SD = "BUILDING_FROM_SD"
|
|
22
|
-
BUILDING_COMPLETED = "BUILDING_COMPLETED"
|
|
23
|
-
PAUSED = "PAUSED"
|
|
24
|
-
READY = "READY"
|
|
25
|
-
BUSY = "BUSY"
|
|
26
|
-
DEFAULT = "DEFAULT"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class MoveMode(Enum):
|
|
30
|
-
"""Enumerates the possible movement modes of the printer."""
|
|
31
|
-
|
|
32
|
-
MOVING = "MOVING"
|
|
33
|
-
PAUSED = "PAUSED"
|
|
34
|
-
READY = "READY"
|
|
35
|
-
WAIT_ON_TOOL = "WAIT_ON_TOOL"
|
|
36
|
-
HOMING = "HOMING"
|
|
37
|
-
DEFAULT = "DEFAULT"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
class Status:
|
|
41
|
-
"""
|
|
42
|
-
Represents additional status flags parsed from a status line.
|
|
43
|
-
The meaning of S, L, J, F flags can be specific to printer firmware or model.
|
|
44
|
-
"""
|
|
45
|
-
|
|
46
|
-
def __init__(self, data: str):
|
|
47
|
-
"""
|
|
48
|
-
Creates an instance of Status by parsing a string line.
|
|
49
|
-
It uses regular expressions to find key-value pairs like "S:0".
|
|
50
|
-
|
|
51
|
-
Args:
|
|
52
|
-
data: The string line containing status flags (e.g., "Status S:0 L:0 J:0 F:0")
|
|
53
|
-
"""
|
|
54
|
-
matches: dict[str, str] = dict(KV_PATTERN.findall(data))
|
|
55
|
-
self.s: int = int(matches.get("S", -1))
|
|
56
|
-
self.l: int = int(matches.get("L", -1))
|
|
57
|
-
self.j: int = int(matches.get("J", -1))
|
|
58
|
-
self.f: int = int(matches.get("F", -1))
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
class Endstop:
|
|
62
|
-
"""
|
|
63
|
-
Represents the state of the printer's endstops.
|
|
64
|
-
Typically, a value of 0 means not triggered, and 1 means triggered.
|
|
65
|
-
"""
|
|
66
|
-
|
|
67
|
-
def __init__(self, data: str):
|
|
68
|
-
"""
|
|
69
|
-
Creates an instance of Endstop by parsing a string line.
|
|
70
|
-
It uses regular expressions to find key-value pairs like "X-max:0".
|
|
71
|
-
|
|
72
|
-
Args:
|
|
73
|
-
data: The string line containing endstop states (e.g., "Endstop X-max:0 Y-max:0 Z-min:1")
|
|
74
|
-
"""
|
|
75
|
-
matches: dict[str, str] = dict(KV_PATTERN.findall(data))
|
|
76
|
-
self.x_max: int = int(matches.get("X-max", -1))
|
|
77
|
-
self.y_max: int = int(matches.get("Y-max", -1))
|
|
78
|
-
self.z_min: int = int(matches.get("Z-min", -1))
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
class EndstopStatus:
|
|
82
|
-
"""
|
|
83
|
-
Represents the status of the printer's endstops and various other machine states.
|
|
84
|
-
|
|
85
|
-
This information is typically parsed from the response of an M119 command or a similar
|
|
86
|
-
consolidated status report from the printer. It includes endstop states, machine operational status,
|
|
87
|
-
movement mode, LED status, and the currently loaded file.
|
|
88
|
-
"""
|
|
89
|
-
|
|
90
|
-
def __init__(self) -> None:
|
|
91
|
-
"""Initialize a new EndstopStatus instance."""
|
|
92
|
-
self.endstop: Endstop | None = None
|
|
93
|
-
self.machine_status: MachineStatus = MachineStatus.DEFAULT
|
|
94
|
-
self.move_mode: MoveMode = MoveMode.DEFAULT
|
|
95
|
-
self.status: Status | None = None
|
|
96
|
-
self.filament_status: str = ""
|
|
97
|
-
self.led_enabled: bool = False
|
|
98
|
-
self.current_file: str | None = None
|
|
99
|
-
|
|
100
|
-
def from_replay(self, replay: str) -> Optional["EndstopStatus"]:
|
|
101
|
-
"""
|
|
102
|
-
Parses a raw string replay (typically from an M119 or similar status command)
|
|
103
|
-
to populate the properties of this EndstopStatus instance.
|
|
104
|
-
|
|
105
|
-
The replay is expected to be a multi-line string where each line provides specific information:
|
|
106
|
-
- Line 1 (data[0]): Usually a command echo or header, ignored
|
|
107
|
-
- Line 2 (data[1]): Parsed into the endstop object
|
|
108
|
-
- Line 3 (data[2]): Parsed to determine machine_status by checking for keywords
|
|
109
|
-
- Line 4 (data[3]): Parsed to determine move_mode by checking for keywords
|
|
110
|
-
- Line 5 (data[4]): Parsed into the status object
|
|
111
|
-
- Line 6 (data[5]): Parsed to determine led_enabled (1 for true, 0 for false)
|
|
112
|
-
- Line 7 (data[6]): Parsed to get current_file, or None if empty
|
|
113
|
-
|
|
114
|
-
Args:
|
|
115
|
-
replay: The raw multi-line string response from the printer
|
|
116
|
-
|
|
117
|
-
Returns:
|
|
118
|
-
The populated EndstopStatus instance, or None if parsing fails
|
|
119
|
-
"""
|
|
120
|
-
if not replay:
|
|
121
|
-
return None
|
|
122
|
-
|
|
123
|
-
try:
|
|
124
|
-
lines = [
|
|
125
|
-
line.strip() for line in replay.replace("\r", "\n").split("\n") if line.strip()
|
|
126
|
-
]
|
|
127
|
-
if not lines:
|
|
128
|
-
return None
|
|
129
|
-
|
|
130
|
-
endstop_line = next((line for line in lines if "Endstop" in line), None)
|
|
131
|
-
if endstop_line is None:
|
|
132
|
-
return None
|
|
133
|
-
|
|
134
|
-
self.endstop = Endstop(endstop_line)
|
|
135
|
-
|
|
136
|
-
for line in lines:
|
|
137
|
-
if line.startswith("MachineStatus:"):
|
|
138
|
-
machine_status = line.replace("MachineStatus:", "", 1).strip().upper()
|
|
139
|
-
if "BUILDING_FROM_SD" in machine_status:
|
|
140
|
-
self.machine_status = MachineStatus.BUILDING_FROM_SD
|
|
141
|
-
elif "BUILDING_COMPLETED" in machine_status:
|
|
142
|
-
self.machine_status = MachineStatus.BUILDING_COMPLETED
|
|
143
|
-
elif "PAUSED" in machine_status:
|
|
144
|
-
self.machine_status = MachineStatus.PAUSED
|
|
145
|
-
elif "READY" in machine_status or "IDLE" in machine_status:
|
|
146
|
-
self.machine_status = MachineStatus.READY
|
|
147
|
-
elif "BUSY" in machine_status:
|
|
148
|
-
self.machine_status = MachineStatus.BUSY
|
|
149
|
-
else:
|
|
150
|
-
logger.warning("EndstopStatus: unknown MachineStatus: %s", machine_status)
|
|
151
|
-
self.machine_status = MachineStatus.DEFAULT
|
|
152
|
-
elif line.startswith("MoveMode:"):
|
|
153
|
-
move_mode = line.replace("MoveMode:", "", 1).strip().upper()
|
|
154
|
-
if "MOVING" in move_mode:
|
|
155
|
-
self.move_mode = MoveMode.MOVING
|
|
156
|
-
elif "PAUSED" in move_mode:
|
|
157
|
-
self.move_mode = MoveMode.PAUSED
|
|
158
|
-
elif "READY" in move_mode or move_mode in {"0", "0.0"}:
|
|
159
|
-
self.move_mode = MoveMode.READY
|
|
160
|
-
elif "WAIT_ON_TOOL" in move_mode:
|
|
161
|
-
self.move_mode = MoveMode.WAIT_ON_TOOL
|
|
162
|
-
elif "HOMING" in move_mode:
|
|
163
|
-
self.move_mode = MoveMode.HOMING
|
|
164
|
-
else:
|
|
165
|
-
logger.warning("EndstopStatus: unknown MoveMode: %s", move_mode)
|
|
166
|
-
self.move_mode = MoveMode.DEFAULT
|
|
167
|
-
elif line.startswith("Status "):
|
|
168
|
-
self.status = Status(line)
|
|
169
|
-
elif line.startswith("FilamentStatus:"):
|
|
170
|
-
self.filament_status = line.replace("FilamentStatus:", "", 1).strip()
|
|
171
|
-
elif line.startswith("LEDStatus:"):
|
|
172
|
-
led_status = line.replace("LEDStatus:", "", 1).strip().lower()
|
|
173
|
-
self.led_enabled = led_status == "on"
|
|
174
|
-
elif line.startswith("LED:"):
|
|
175
|
-
led_str = line.replace("LED:", "", 1).strip()
|
|
176
|
-
try:
|
|
177
|
-
self.led_enabled = int(led_str) == 1
|
|
178
|
-
except ValueError:
|
|
179
|
-
self.led_enabled = False
|
|
180
|
-
elif line.startswith("CurrentFile:"):
|
|
181
|
-
current_file = line.replace("CurrentFile:", "", 1).strip()
|
|
182
|
-
self.current_file = current_file if current_file else None
|
|
183
|
-
elif line.startswith("PrintFileName:"):
|
|
184
|
-
current_file = line.replace("PrintFileName:", "", 1).strip()
|
|
185
|
-
self.current_file = current_file if current_file else None
|
|
186
|
-
|
|
187
|
-
return self
|
|
188
|
-
|
|
189
|
-
except Exception as e:
|
|
190
|
-
logger.warning("Unable to create an EndstopStatus from the reply: %s", e)
|
|
191
|
-
logger.debug("Reply that failed to parse: %s", replay)
|
|
192
|
-
return None
|
|
193
|
-
|
|
194
|
-
def is_print_complete(self) -> bool:
|
|
195
|
-
"""
|
|
196
|
-
Checks if the machine status indicates that a print has been completed.
|
|
197
|
-
|
|
198
|
-
Returns:
|
|
199
|
-
True if machine_status is BUILDING_COMPLETED, False otherwise
|
|
200
|
-
"""
|
|
201
|
-
return self.machine_status == MachineStatus.BUILDING_COMPLETED
|
|
202
|
-
|
|
203
|
-
def is_printing(self) -> bool:
|
|
204
|
-
"""
|
|
205
|
-
Checks if the machine status indicates that a print is currently in progress from SD.
|
|
206
|
-
|
|
207
|
-
Returns:
|
|
208
|
-
True if machine_status is BUILDING_FROM_SD, False otherwise
|
|
209
|
-
"""
|
|
210
|
-
return self.machine_status == MachineStatus.BUILDING_FROM_SD
|
|
211
|
-
|
|
212
|
-
def is_ready(self) -> bool:
|
|
213
|
-
"""
|
|
214
|
-
Checks if the printer is in a ready state (both move mode and machine status are READY).
|
|
215
|
-
|
|
216
|
-
Returns:
|
|
217
|
-
True if the printer is ready, False otherwise
|
|
218
|
-
"""
|
|
219
|
-
return self.move_mode == MoveMode.READY and self.machine_status == MachineStatus.READY
|
|
220
|
-
|
|
221
|
-
def is_paused(self) -> bool:
|
|
222
|
-
"""
|
|
223
|
-
Checks if the printer is currently paused (either machine status or move mode is PAUSED).
|
|
224
|
-
|
|
225
|
-
Returns:
|
|
226
|
-
True if the printer is paused, False otherwise
|
|
227
|
-
"""
|
|
228
|
-
return self.machine_status == MachineStatus.PAUSED or self.move_mode == MoveMode.PAUSED
|
|
229
|
-
|
|
230
|
-
def __str__(self) -> str:
|
|
231
|
-
"""String representation of the endstop status."""
|
|
232
|
-
return (
|
|
233
|
-
f"EndstopStatus(machine={self.machine_status.value}, "
|
|
234
|
-
f"move={self.move_mode.value}, led={self.led_enabled}, "
|
|
235
|
-
f"file='{self.current_file}')"
|
|
236
|
-
)
|
|
237
|
-
|
|
238
|
-
def __repr__(self) -> str:
|
|
239
|
-
"""Detailed string representation for debugging."""
|
|
240
|
-
return (
|
|
241
|
-
f"EndstopStatus("
|
|
242
|
-
f"endstop={self.endstop}, "
|
|
243
|
-
f"machine_status={self.machine_status}, "
|
|
244
|
-
f"move_mode={self.move_mode}, "
|
|
245
|
-
f"status={self.status}, "
|
|
246
|
-
f"led_enabled={self.led_enabled}, "
|
|
247
|
-
f"current_file='{self.current_file}')"
|
|
248
|
-
)
|
|
1
|
+
"""
|
|
2
|
+
FlashForge Python API - Endstop Status Parser
|
|
3
|
+
|
|
4
|
+
Parses endstop and machine status information from M119 command responses.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import logging
|
|
8
|
+
import re
|
|
9
|
+
from enum import Enum
|
|
10
|
+
from typing import Optional
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
# Pre-compiled regex to match key:value pairs where value is an integer
|
|
15
|
+
KV_PATTERN = re.compile(r"([A-Za-z0-9-]+):\s*(\d+)")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class MachineStatus(Enum):
|
|
19
|
+
"""Enumerates the possible operational statuses of the machine."""
|
|
20
|
+
|
|
21
|
+
BUILDING_FROM_SD = "BUILDING_FROM_SD"
|
|
22
|
+
BUILDING_COMPLETED = "BUILDING_COMPLETED"
|
|
23
|
+
PAUSED = "PAUSED"
|
|
24
|
+
READY = "READY"
|
|
25
|
+
BUSY = "BUSY"
|
|
26
|
+
DEFAULT = "DEFAULT"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class MoveMode(Enum):
|
|
30
|
+
"""Enumerates the possible movement modes of the printer."""
|
|
31
|
+
|
|
32
|
+
MOVING = "MOVING"
|
|
33
|
+
PAUSED = "PAUSED"
|
|
34
|
+
READY = "READY"
|
|
35
|
+
WAIT_ON_TOOL = "WAIT_ON_TOOL"
|
|
36
|
+
HOMING = "HOMING"
|
|
37
|
+
DEFAULT = "DEFAULT"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Status:
|
|
41
|
+
"""
|
|
42
|
+
Represents additional status flags parsed from a status line.
|
|
43
|
+
The meaning of S, L, J, F flags can be specific to printer firmware or model.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
def __init__(self, data: str):
|
|
47
|
+
"""
|
|
48
|
+
Creates an instance of Status by parsing a string line.
|
|
49
|
+
It uses regular expressions to find key-value pairs like "S:0".
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
data: The string line containing status flags (e.g., "Status S:0 L:0 J:0 F:0")
|
|
53
|
+
"""
|
|
54
|
+
matches: dict[str, str] = dict(KV_PATTERN.findall(data))
|
|
55
|
+
self.s: int = int(matches.get("S", -1))
|
|
56
|
+
self.l: int = int(matches.get("L", -1))
|
|
57
|
+
self.j: int = int(matches.get("J", -1))
|
|
58
|
+
self.f: int = int(matches.get("F", -1))
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class Endstop:
|
|
62
|
+
"""
|
|
63
|
+
Represents the state of the printer's endstops.
|
|
64
|
+
Typically, a value of 0 means not triggered, and 1 means triggered.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
def __init__(self, data: str):
|
|
68
|
+
"""
|
|
69
|
+
Creates an instance of Endstop by parsing a string line.
|
|
70
|
+
It uses regular expressions to find key-value pairs like "X-max:0".
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
data: The string line containing endstop states (e.g., "Endstop X-max:0 Y-max:0 Z-min:1")
|
|
74
|
+
"""
|
|
75
|
+
matches: dict[str, str] = dict(KV_PATTERN.findall(data))
|
|
76
|
+
self.x_max: int = int(matches.get("X-max", -1))
|
|
77
|
+
self.y_max: int = int(matches.get("Y-max", -1))
|
|
78
|
+
self.z_min: int = int(matches.get("Z-min", -1))
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class EndstopStatus:
|
|
82
|
+
"""
|
|
83
|
+
Represents the status of the printer's endstops and various other machine states.
|
|
84
|
+
|
|
85
|
+
This information is typically parsed from the response of an M119 command or a similar
|
|
86
|
+
consolidated status report from the printer. It includes endstop states, machine operational status,
|
|
87
|
+
movement mode, LED status, and the currently loaded file.
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
def __init__(self) -> None:
|
|
91
|
+
"""Initialize a new EndstopStatus instance."""
|
|
92
|
+
self.endstop: Endstop | None = None
|
|
93
|
+
self.machine_status: MachineStatus = MachineStatus.DEFAULT
|
|
94
|
+
self.move_mode: MoveMode = MoveMode.DEFAULT
|
|
95
|
+
self.status: Status | None = None
|
|
96
|
+
self.filament_status: str = ""
|
|
97
|
+
self.led_enabled: bool = False
|
|
98
|
+
self.current_file: str | None = None
|
|
99
|
+
|
|
100
|
+
def from_replay(self, replay: str) -> Optional["EndstopStatus"]:
|
|
101
|
+
"""
|
|
102
|
+
Parses a raw string replay (typically from an M119 or similar status command)
|
|
103
|
+
to populate the properties of this EndstopStatus instance.
|
|
104
|
+
|
|
105
|
+
The replay is expected to be a multi-line string where each line provides specific information:
|
|
106
|
+
- Line 1 (data[0]): Usually a command echo or header, ignored
|
|
107
|
+
- Line 2 (data[1]): Parsed into the endstop object
|
|
108
|
+
- Line 3 (data[2]): Parsed to determine machine_status by checking for keywords
|
|
109
|
+
- Line 4 (data[3]): Parsed to determine move_mode by checking for keywords
|
|
110
|
+
- Line 5 (data[4]): Parsed into the status object
|
|
111
|
+
- Line 6 (data[5]): Parsed to determine led_enabled (1 for true, 0 for false)
|
|
112
|
+
- Line 7 (data[6]): Parsed to get current_file, or None if empty
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
replay: The raw multi-line string response from the printer
|
|
116
|
+
|
|
117
|
+
Returns:
|
|
118
|
+
The populated EndstopStatus instance, or None if parsing fails
|
|
119
|
+
"""
|
|
120
|
+
if not replay:
|
|
121
|
+
return None
|
|
122
|
+
|
|
123
|
+
try:
|
|
124
|
+
lines = [
|
|
125
|
+
line.strip() for line in replay.replace("\r", "\n").split("\n") if line.strip()
|
|
126
|
+
]
|
|
127
|
+
if not lines:
|
|
128
|
+
return None
|
|
129
|
+
|
|
130
|
+
endstop_line = next((line for line in lines if "Endstop" in line), None)
|
|
131
|
+
if endstop_line is None:
|
|
132
|
+
return None
|
|
133
|
+
|
|
134
|
+
self.endstop = Endstop(endstop_line)
|
|
135
|
+
|
|
136
|
+
for line in lines:
|
|
137
|
+
if line.startswith("MachineStatus:"):
|
|
138
|
+
machine_status = line.replace("MachineStatus:", "", 1).strip().upper()
|
|
139
|
+
if "BUILDING_FROM_SD" in machine_status:
|
|
140
|
+
self.machine_status = MachineStatus.BUILDING_FROM_SD
|
|
141
|
+
elif "BUILDING_COMPLETED" in machine_status:
|
|
142
|
+
self.machine_status = MachineStatus.BUILDING_COMPLETED
|
|
143
|
+
elif "PAUSED" in machine_status:
|
|
144
|
+
self.machine_status = MachineStatus.PAUSED
|
|
145
|
+
elif "READY" in machine_status or "IDLE" in machine_status:
|
|
146
|
+
self.machine_status = MachineStatus.READY
|
|
147
|
+
elif "BUSY" in machine_status:
|
|
148
|
+
self.machine_status = MachineStatus.BUSY
|
|
149
|
+
else:
|
|
150
|
+
logger.warning("EndstopStatus: unknown MachineStatus: %s", machine_status)
|
|
151
|
+
self.machine_status = MachineStatus.DEFAULT
|
|
152
|
+
elif line.startswith("MoveMode:"):
|
|
153
|
+
move_mode = line.replace("MoveMode:", "", 1).strip().upper()
|
|
154
|
+
if "MOVING" in move_mode:
|
|
155
|
+
self.move_mode = MoveMode.MOVING
|
|
156
|
+
elif "PAUSED" in move_mode:
|
|
157
|
+
self.move_mode = MoveMode.PAUSED
|
|
158
|
+
elif "READY" in move_mode or move_mode in {"0", "0.0"}:
|
|
159
|
+
self.move_mode = MoveMode.READY
|
|
160
|
+
elif "WAIT_ON_TOOL" in move_mode:
|
|
161
|
+
self.move_mode = MoveMode.WAIT_ON_TOOL
|
|
162
|
+
elif "HOMING" in move_mode:
|
|
163
|
+
self.move_mode = MoveMode.HOMING
|
|
164
|
+
else:
|
|
165
|
+
logger.warning("EndstopStatus: unknown MoveMode: %s", move_mode)
|
|
166
|
+
self.move_mode = MoveMode.DEFAULT
|
|
167
|
+
elif line.startswith("Status "):
|
|
168
|
+
self.status = Status(line)
|
|
169
|
+
elif line.startswith("FilamentStatus:"):
|
|
170
|
+
self.filament_status = line.replace("FilamentStatus:", "", 1).strip()
|
|
171
|
+
elif line.startswith("LEDStatus:"):
|
|
172
|
+
led_status = line.replace("LEDStatus:", "", 1).strip().lower()
|
|
173
|
+
self.led_enabled = led_status == "on"
|
|
174
|
+
elif line.startswith("LED:"):
|
|
175
|
+
led_str = line.replace("LED:", "", 1).strip()
|
|
176
|
+
try:
|
|
177
|
+
self.led_enabled = int(led_str) == 1
|
|
178
|
+
except ValueError:
|
|
179
|
+
self.led_enabled = False
|
|
180
|
+
elif line.startswith("CurrentFile:"):
|
|
181
|
+
current_file = line.replace("CurrentFile:", "", 1).strip()
|
|
182
|
+
self.current_file = current_file if current_file else None
|
|
183
|
+
elif line.startswith("PrintFileName:"):
|
|
184
|
+
current_file = line.replace("PrintFileName:", "", 1).strip()
|
|
185
|
+
self.current_file = current_file if current_file else None
|
|
186
|
+
|
|
187
|
+
return self
|
|
188
|
+
|
|
189
|
+
except Exception as e:
|
|
190
|
+
logger.warning("Unable to create an EndstopStatus from the reply: %s", e)
|
|
191
|
+
logger.debug("Reply that failed to parse: %s", replay)
|
|
192
|
+
return None
|
|
193
|
+
|
|
194
|
+
def is_print_complete(self) -> bool:
|
|
195
|
+
"""
|
|
196
|
+
Checks if the machine status indicates that a print has been completed.
|
|
197
|
+
|
|
198
|
+
Returns:
|
|
199
|
+
True if machine_status is BUILDING_COMPLETED, False otherwise
|
|
200
|
+
"""
|
|
201
|
+
return self.machine_status == MachineStatus.BUILDING_COMPLETED
|
|
202
|
+
|
|
203
|
+
def is_printing(self) -> bool:
|
|
204
|
+
"""
|
|
205
|
+
Checks if the machine status indicates that a print is currently in progress from SD.
|
|
206
|
+
|
|
207
|
+
Returns:
|
|
208
|
+
True if machine_status is BUILDING_FROM_SD, False otherwise
|
|
209
|
+
"""
|
|
210
|
+
return self.machine_status == MachineStatus.BUILDING_FROM_SD
|
|
211
|
+
|
|
212
|
+
def is_ready(self) -> bool:
|
|
213
|
+
"""
|
|
214
|
+
Checks if the printer is in a ready state (both move mode and machine status are READY).
|
|
215
|
+
|
|
216
|
+
Returns:
|
|
217
|
+
True if the printer is ready, False otherwise
|
|
218
|
+
"""
|
|
219
|
+
return self.move_mode == MoveMode.READY and self.machine_status == MachineStatus.READY
|
|
220
|
+
|
|
221
|
+
def is_paused(self) -> bool:
|
|
222
|
+
"""
|
|
223
|
+
Checks if the printer is currently paused (either machine status or move mode is PAUSED).
|
|
224
|
+
|
|
225
|
+
Returns:
|
|
226
|
+
True if the printer is paused, False otherwise
|
|
227
|
+
"""
|
|
228
|
+
return self.machine_status == MachineStatus.PAUSED or self.move_mode == MoveMode.PAUSED
|
|
229
|
+
|
|
230
|
+
def __str__(self) -> str:
|
|
231
|
+
"""String representation of the endstop status."""
|
|
232
|
+
return (
|
|
233
|
+
f"EndstopStatus(machine={self.machine_status.value}, "
|
|
234
|
+
f"move={self.move_mode.value}, led={self.led_enabled}, "
|
|
235
|
+
f"file='{self.current_file}')"
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
def __repr__(self) -> str:
|
|
239
|
+
"""Detailed string representation for debugging."""
|
|
240
|
+
return (
|
|
241
|
+
f"EndstopStatus("
|
|
242
|
+
f"endstop={self.endstop}, "
|
|
243
|
+
f"machine_status={self.machine_status}, "
|
|
244
|
+
f"move_mode={self.move_mode}, "
|
|
245
|
+
f"status={self.status}, "
|
|
246
|
+
f"led_enabled={self.led_enabled}, "
|
|
247
|
+
f"current_file='{self.current_file}')"
|
|
248
|
+
)
|