flashforge-python-api 1.6.0__py3-none-any.whl → 3.1.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 +137 -56
- 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 +150 -77
- 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.1.0.dist-info}/METADATA +46 -47
- flashforge_python_api-3.1.0.dist-info/RECORD +69 -0
- {flashforge_python_api-1.6.0.dist-info → flashforge_python_api-3.1.0.dist-info}/WHEEL +1 -1
- {flashforge_python_api-1.6.0.dist-info → flashforge_python_api-3.1.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.1.0.dist-info}/entry_points.txt +0 -0
|
@@ -1,146 +1,146 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Printer information parser for FlashForge 3D printers.
|
|
3
|
-
|
|
4
|
-
This module parses the response from M115 command to extract printer details
|
|
5
|
-
like model, firmware version, serial number, and capabilities.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
import logging
|
|
9
|
-
import re
|
|
10
|
-
from typing import Optional
|
|
11
|
-
|
|
12
|
-
logger = logging.getLogger(__name__)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class PrinterInfo:
|
|
16
|
-
"""
|
|
17
|
-
Represents general information about the FlashForge 3D printer.
|
|
18
|
-
|
|
19
|
-
This information is typically parsed from the response of an M115 G-code command,
|
|
20
|
-
which provides details about the printer's firmware and capabilities.
|
|
21
|
-
"""
|
|
22
|
-
|
|
23
|
-
def __init__(self) -> None:
|
|
24
|
-
"""Initialize empty printer info."""
|
|
25
|
-
self.type_name: str = ""
|
|
26
|
-
"""The machine type or model name (e.g., "FlashForge Adventurer 5M Pro")."""
|
|
27
|
-
|
|
28
|
-
self.name: str = ""
|
|
29
|
-
"""The user-assigned name of the printer."""
|
|
30
|
-
|
|
31
|
-
self.firmware_version: str = ""
|
|
32
|
-
"""The firmware version currently installed on the printer."""
|
|
33
|
-
|
|
34
|
-
self.serial_number: str = ""
|
|
35
|
-
"""The unique serial number of the printer."""
|
|
36
|
-
|
|
37
|
-
self.dimensions: str = ""
|
|
38
|
-
"""The build dimensions of the printer (e.g., "X:220 Y:220 Z:220")."""
|
|
39
|
-
|
|
40
|
-
self.mac_address: str = ""
|
|
41
|
-
"""The MAC address of the printer's network interface."""
|
|
42
|
-
|
|
43
|
-
self.tool_count: str = ""
|
|
44
|
-
"""The number of tools (extruders) the printer has."""
|
|
45
|
-
|
|
46
|
-
def from_replay(self, replay: str) -> Optional["PrinterInfo"]:
|
|
47
|
-
"""
|
|
48
|
-
Parse a raw string replay from M115 command to populate printer info.
|
|
49
|
-
|
|
50
|
-
The M115 response is expected to be a multi-line string where each line
|
|
51
|
-
provides a piece of information in a "Key: Value" format.
|
|
52
|
-
|
|
53
|
-
Expected format:
|
|
54
|
-
- Line 1: Command echo/header (ignored)
|
|
55
|
-
- Line 2: "Machine Type: [TypeName]"
|
|
56
|
-
- Line 3: "Machine Name: [Name]"
|
|
57
|
-
- Line 4: "Firmware: [FirmwareVersion]"
|
|
58
|
-
- Line 5: "SN: [SerialNumber]"
|
|
59
|
-
- Line 6: Dimensions string (e.g., "X:220 Y:220 Z:220")
|
|
60
|
-
- Line 7: "Tool count: [ToolCount]"
|
|
61
|
-
- Line 8: "Mac Address:[MacAddress]"
|
|
62
|
-
|
|
63
|
-
Args:
|
|
64
|
-
replay: The raw multi-line string response from the M115 command
|
|
65
|
-
|
|
66
|
-
Returns:
|
|
67
|
-
The populated PrinterInfo instance, or None if parsing fails
|
|
68
|
-
"""
|
|
69
|
-
if not replay:
|
|
70
|
-
return None
|
|
71
|
-
|
|
72
|
-
try:
|
|
73
|
-
lines = [
|
|
74
|
-
line.strip() for line in replay.replace("\r", "\n").split("\n") if line.strip()
|
|
75
|
-
]
|
|
76
|
-
|
|
77
|
-
for line in lines:
|
|
78
|
-
if line.startswith("Machine Type:"):
|
|
79
|
-
self.type_name = line.replace("Machine Type:", "", 1).strip()
|
|
80
|
-
elif line.startswith("Machine Name:"):
|
|
81
|
-
self.name = line.replace("Machine Name:", "", 1).strip()
|
|
82
|
-
elif line.startswith("Firmware:"):
|
|
83
|
-
self.firmware_version = line.replace("Firmware:", "", 1).strip()
|
|
84
|
-
elif line.startswith("SN:"):
|
|
85
|
-
self.serial_number = line.replace("SN:", "", 1).strip()
|
|
86
|
-
elif line.startswith("Serial Number:"):
|
|
87
|
-
self.serial_number = line.replace("Serial Number:", "", 1).strip()
|
|
88
|
-
elif line.startswith("Tool count:") or line.startswith("Tool Count:"):
|
|
89
|
-
tool_count = self._get_right(line)
|
|
90
|
-
if tool_count is not None:
|
|
91
|
-
self.tool_count = tool_count
|
|
92
|
-
elif line.startswith("Mac Address:"):
|
|
93
|
-
self.mac_address = line.replace("Mac Address:", "", 1).strip()
|
|
94
|
-
elif re.search(r"X:\s*\d+.*Y:\s*\d+.*Z:\s*\d+", line, re.IGNORECASE):
|
|
95
|
-
self.dimensions = line
|
|
96
|
-
|
|
97
|
-
if not self.type_name:
|
|
98
|
-
logger.error("PrinterInfo replay has null Machine Type")
|
|
99
|
-
return None
|
|
100
|
-
if not self.name:
|
|
101
|
-
logger.error("PrinterInfo replay has null Machine Name")
|
|
102
|
-
return None
|
|
103
|
-
if not self.firmware_version:
|
|
104
|
-
logger.error("PrinterInfo replay has null firmware version")
|
|
105
|
-
return None
|
|
106
|
-
if not self.serial_number:
|
|
107
|
-
logger.error("PrinterInfo replay has null serial number")
|
|
108
|
-
return None
|
|
109
|
-
|
|
110
|
-
return self
|
|
111
|
-
|
|
112
|
-
except Exception as e:
|
|
113
|
-
logger.error(f"Error creating PrinterInfo instance from replay: {e}")
|
|
114
|
-
return None
|
|
115
|
-
|
|
116
|
-
def _get_right(self, rp_data: str) -> str | None:
|
|
117
|
-
"""
|
|
118
|
-
Helper function to extract the value part of a "Key: Value" string.
|
|
119
|
-
|
|
120
|
-
Args:
|
|
121
|
-
rp_data: The input string (e.g., "Machine Type: Adventurer 5M Pro")
|
|
122
|
-
|
|
123
|
-
Returns:
|
|
124
|
-
The extracted value string (e.g., "Adventurer 5M Pro"), or None if parsing fails
|
|
125
|
-
"""
|
|
126
|
-
try:
|
|
127
|
-
return rp_data.split(":", 1)[1].strip()
|
|
128
|
-
except (IndexError, AttributeError):
|
|
129
|
-
return None
|
|
130
|
-
|
|
131
|
-
def __str__(self) -> str:
|
|
132
|
-
"""
|
|
133
|
-
Return a string representation of the printer information.
|
|
134
|
-
|
|
135
|
-
Returns:
|
|
136
|
-
A multi-line string detailing the printer's properties
|
|
137
|
-
"""
|
|
138
|
-
return (
|
|
139
|
-
f"Printer Type: {self.type_name}\n"
|
|
140
|
-
f"Name: {self.name}\n"
|
|
141
|
-
f"Firmware: {self.firmware_version}\n"
|
|
142
|
-
f"Serial Number: {self.serial_number}\n"
|
|
143
|
-
f"Print Dimensions: {self.dimensions}\n"
|
|
144
|
-
f"Tool Count: {self.tool_count}\n"
|
|
145
|
-
f"MAC Address: {self.mac_address}"
|
|
146
|
-
)
|
|
1
|
+
"""
|
|
2
|
+
Printer information parser for FlashForge 3D printers.
|
|
3
|
+
|
|
4
|
+
This module parses the response from M115 command to extract printer details
|
|
5
|
+
like model, firmware version, serial number, and capabilities.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import logging
|
|
9
|
+
import re
|
|
10
|
+
from typing import Optional
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class PrinterInfo:
|
|
16
|
+
"""
|
|
17
|
+
Represents general information about the FlashForge 3D printer.
|
|
18
|
+
|
|
19
|
+
This information is typically parsed from the response of an M115 G-code command,
|
|
20
|
+
which provides details about the printer's firmware and capabilities.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
def __init__(self) -> None:
|
|
24
|
+
"""Initialize empty printer info."""
|
|
25
|
+
self.type_name: str = ""
|
|
26
|
+
"""The machine type or model name (e.g., "FlashForge Adventurer 5M Pro")."""
|
|
27
|
+
|
|
28
|
+
self.name: str = ""
|
|
29
|
+
"""The user-assigned name of the printer."""
|
|
30
|
+
|
|
31
|
+
self.firmware_version: str = ""
|
|
32
|
+
"""The firmware version currently installed on the printer."""
|
|
33
|
+
|
|
34
|
+
self.serial_number: str = ""
|
|
35
|
+
"""The unique serial number of the printer."""
|
|
36
|
+
|
|
37
|
+
self.dimensions: str = ""
|
|
38
|
+
"""The build dimensions of the printer (e.g., "X:220 Y:220 Z:220")."""
|
|
39
|
+
|
|
40
|
+
self.mac_address: str = ""
|
|
41
|
+
"""The MAC address of the printer's network interface."""
|
|
42
|
+
|
|
43
|
+
self.tool_count: str = ""
|
|
44
|
+
"""The number of tools (extruders) the printer has."""
|
|
45
|
+
|
|
46
|
+
def from_replay(self, replay: str) -> Optional["PrinterInfo"]:
|
|
47
|
+
"""
|
|
48
|
+
Parse a raw string replay from M115 command to populate printer info.
|
|
49
|
+
|
|
50
|
+
The M115 response is expected to be a multi-line string where each line
|
|
51
|
+
provides a piece of information in a "Key: Value" format.
|
|
52
|
+
|
|
53
|
+
Expected format:
|
|
54
|
+
- Line 1: Command echo/header (ignored)
|
|
55
|
+
- Line 2: "Machine Type: [TypeName]"
|
|
56
|
+
- Line 3: "Machine Name: [Name]"
|
|
57
|
+
- Line 4: "Firmware: [FirmwareVersion]"
|
|
58
|
+
- Line 5: "SN: [SerialNumber]"
|
|
59
|
+
- Line 6: Dimensions string (e.g., "X:220 Y:220 Z:220")
|
|
60
|
+
- Line 7: "Tool count: [ToolCount]"
|
|
61
|
+
- Line 8: "Mac Address:[MacAddress]"
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
replay: The raw multi-line string response from the M115 command
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
The populated PrinterInfo instance, or None if parsing fails
|
|
68
|
+
"""
|
|
69
|
+
if not replay:
|
|
70
|
+
return None
|
|
71
|
+
|
|
72
|
+
try:
|
|
73
|
+
lines = [
|
|
74
|
+
line.strip() for line in replay.replace("\r", "\n").split("\n") if line.strip()
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
for line in lines:
|
|
78
|
+
if line.startswith("Machine Type:"):
|
|
79
|
+
self.type_name = line.replace("Machine Type:", "", 1).strip()
|
|
80
|
+
elif line.startswith("Machine Name:"):
|
|
81
|
+
self.name = line.replace("Machine Name:", "", 1).strip()
|
|
82
|
+
elif line.startswith("Firmware:"):
|
|
83
|
+
self.firmware_version = line.replace("Firmware:", "", 1).strip()
|
|
84
|
+
elif line.startswith("SN:"):
|
|
85
|
+
self.serial_number = line.replace("SN:", "", 1).strip()
|
|
86
|
+
elif line.startswith("Serial Number:"):
|
|
87
|
+
self.serial_number = line.replace("Serial Number:", "", 1).strip()
|
|
88
|
+
elif line.startswith("Tool count:") or line.startswith("Tool Count:"):
|
|
89
|
+
tool_count = self._get_right(line)
|
|
90
|
+
if tool_count is not None:
|
|
91
|
+
self.tool_count = tool_count
|
|
92
|
+
elif line.startswith("Mac Address:"):
|
|
93
|
+
self.mac_address = line.replace("Mac Address:", "", 1).strip()
|
|
94
|
+
elif re.search(r"X:\s*\d+.*Y:\s*\d+.*Z:\s*\d+", line, re.IGNORECASE):
|
|
95
|
+
self.dimensions = line
|
|
96
|
+
|
|
97
|
+
if not self.type_name:
|
|
98
|
+
logger.error("PrinterInfo replay has null Machine Type")
|
|
99
|
+
return None
|
|
100
|
+
if not self.name:
|
|
101
|
+
logger.error("PrinterInfo replay has null Machine Name")
|
|
102
|
+
return None
|
|
103
|
+
if not self.firmware_version:
|
|
104
|
+
logger.error("PrinterInfo replay has null firmware version")
|
|
105
|
+
return None
|
|
106
|
+
if not self.serial_number:
|
|
107
|
+
logger.error("PrinterInfo replay has null serial number")
|
|
108
|
+
return None
|
|
109
|
+
|
|
110
|
+
return self
|
|
111
|
+
|
|
112
|
+
except Exception as e:
|
|
113
|
+
logger.error(f"Error creating PrinterInfo instance from replay: {e}")
|
|
114
|
+
return None
|
|
115
|
+
|
|
116
|
+
def _get_right(self, rp_data: str) -> str | None:
|
|
117
|
+
"""
|
|
118
|
+
Helper function to extract the value part of a "Key: Value" string.
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
rp_data: The input string (e.g., "Machine Type: Adventurer 5M Pro")
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
The extracted value string (e.g., "Adventurer 5M Pro"), or None if parsing fails
|
|
125
|
+
"""
|
|
126
|
+
try:
|
|
127
|
+
return rp_data.split(":", 1)[1].strip()
|
|
128
|
+
except (IndexError, AttributeError):
|
|
129
|
+
return None
|
|
130
|
+
|
|
131
|
+
def __str__(self) -> str:
|
|
132
|
+
"""
|
|
133
|
+
Return a string representation of the printer information.
|
|
134
|
+
|
|
135
|
+
Returns:
|
|
136
|
+
A multi-line string detailing the printer's properties
|
|
137
|
+
"""
|
|
138
|
+
return (
|
|
139
|
+
f"Printer Type: {self.type_name}\n"
|
|
140
|
+
f"Name: {self.name}\n"
|
|
141
|
+
f"Firmware: {self.firmware_version}\n"
|
|
142
|
+
f"Serial Number: {self.serial_number}\n"
|
|
143
|
+
f"Print Dimensions: {self.dimensions}\n"
|
|
144
|
+
f"Tool Count: {self.tool_count}\n"
|
|
145
|
+
f"MAC Address: {self.mac_address}"
|
|
146
|
+
)
|