flashforge-python-api 1.5.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.
Files changed (71) hide show
  1. flashforge/__init__.py +337 -233
  2. flashforge/_removed.py +65 -0
  3. flashforge/api/__init__.py +12 -18
  4. flashforge/api/constants/__init__.py +11 -11
  5. flashforge/api/constants/commands.py +18 -15
  6. flashforge/api/constants/endpoints.py +11 -11
  7. flashforge/api/misc/__init__.py +8 -8
  8. flashforge/api/network/__init__.py +11 -11
  9. flashforge/api/network/utils.py +71 -71
  10. flashforge/backends/__init__.py +80 -0
  11. flashforge/backends/connect.py +275 -0
  12. flashforge/backends/creator5_backend.py +191 -0
  13. flashforge/backends/dual_api_backend.py +170 -0
  14. flashforge/backends/dual_api_models.py +145 -0
  15. flashforge/backends/http_core.py +431 -0
  16. flashforge/backends/http_printer_backend.py +254 -0
  17. flashforge/backends/legacy_backend.py +436 -0
  18. flashforge/backends/printer_backend.py +217 -0
  19. flashforge/backends/types.py +125 -0
  20. flashforge/capabilities/__init__.py +98 -0
  21. flashforge/capabilities/models.py +67 -0
  22. flashforge/capabilities/palettes/__init__.py +28 -0
  23. flashforge/capabilities/palettes/ad5x_palette.py +70 -0
  24. flashforge/capabilities/palettes/creator5_palette.py +78 -0
  25. flashforge/capabilities/palettes/palette.py +54 -0
  26. flashforge/{api/controls/creator5_palette.py → capabilities/palettes/palette_snap.py} +226 -258
  27. flashforge/capabilities/printer_capabilities.py +145 -0
  28. flashforge/capabilities/registry.py +125 -0
  29. flashforge/capabilities/resolve_model.py +61 -0
  30. flashforge/discovery/__init__.py +39 -39
  31. flashforge/discovery/discovery.py +730 -763
  32. flashforge/exceptions.py +90 -51
  33. flashforge/models/__init__.py +52 -55
  34. flashforge/models/machine_info.py +540 -543
  35. flashforge/{api/controls/info.py → models/machine_info_parser.py} +35 -242
  36. flashforge/models/responses.py +119 -254
  37. flashforge/status/__init__.py +43 -0
  38. flashforge/status/printer_snapshot.py +396 -0
  39. flashforge/tcp/__init__.py +55 -54
  40. flashforge/tcp/a3_client.py +427 -427
  41. flashforge/tcp/a4_client.py +304 -304
  42. flashforge/tcp/ff_client.py +609 -590
  43. flashforge/tcp/gcode/__init__.py +15 -13
  44. flashforge/tcp/gcode/a3_gcode_controller.py +109 -109
  45. flashforge/tcp/gcode/gcode_controller.py +292 -308
  46. flashforge/tcp/gcode/gcodes.py +81 -99
  47. flashforge/tcp/gcode/legacy_gcode_controller.py +56 -0
  48. flashforge/tcp/parsers/__init__.py +27 -27
  49. flashforge/tcp/parsers/endstop_status.py +248 -248
  50. flashforge/tcp/parsers/location_info.py +83 -83
  51. flashforge/tcp/parsers/print_status.py +180 -180
  52. flashforge/tcp/parsers/printer_info.py +146 -146
  53. flashforge/tcp/parsers/temp_info.py +218 -218
  54. flashforge/tcp/parsers/thumbnail_info.py +274 -274
  55. flashforge/tcp/tcp_client.py +52 -12
  56. flashforge/threemf/__init__.py +40 -0
  57. flashforge/threemf/parser.py +560 -0
  58. flashforge/threemf/warnings.py +58 -0
  59. flashforge_python_api-3.0.0.dist-info/METADATA +184 -0
  60. flashforge_python_api-3.0.0.dist-info/RECORD +69 -0
  61. {flashforge_python_api-1.5.0.dist-info → flashforge_python_api-3.0.0.dist-info}/WHEEL +1 -1
  62. {flashforge_python_api-1.5.0.dist-info → flashforge_python_api-3.0.0.dist-info}/licenses/LICENSE +21 -21
  63. flashforge/api/controls/__init__.py +0 -17
  64. flashforge/api/controls/control.py +0 -413
  65. flashforge/api/controls/files.py +0 -210
  66. flashforge/api/controls/job_control.py +0 -880
  67. flashforge/api/controls/temp_control.py +0 -309
  68. flashforge/client.py +0 -609
  69. flashforge_python_api-1.5.0.dist-info/METADATA +0 -152
  70. flashforge_python_api-1.5.0.dist-info/RECORD +0 -49
  71. {flashforge_python_api-1.5.0.dist-info → flashforge_python_api-3.0.0.dist-info}/entry_points.txt +0 -0
@@ -1,218 +1,218 @@
1
- """
2
- Temperature information parser for FlashForge 3D printers.
3
-
4
- This module parses the response from M105 command to extract temperature data
5
- for the extruder and print bed.
6
- """
7
-
8
- import logging
9
- from typing import Optional
10
-
11
- logger = logging.getLogger(__name__)
12
-
13
-
14
- class TempData:
15
- """
16
- Represents temperature data for a single component (e.g., extruder or bed).
17
-
18
- Includes current temperature and target (set) temperature.
19
- Temperatures are stored as strings but can be retrieved as numbers.
20
- """
21
-
22
- def __init__(self, data: str) -> None:
23
- """
24
- Create a TempData instance by parsing a temperature string.
25
-
26
- The input string can be in the format "current/set" (e.g., "210/210")
27
- or just "current" (e.g., "25") if the target temperature is not specified.
28
- It also handles and removes a trailing "/0.0" if present from some printer firmwares.
29
- All temperatures are rounded to the nearest integer.
30
-
31
- Args:
32
- data: The temperature data string (e.g., "210/210", "25", "60/60/0.0")
33
- """
34
- # Handle potential formatting issues by removing any non-relevant part
35
- data = data.replace("/0.0", "") # Remove trailing '/0.0' if exists
36
-
37
- if "/" in data:
38
- # Replay has current/set temps
39
- split_temps = data.split("/")
40
- self._current = self._parse_temp_data(split_temps[0].strip())
41
- self._set = (
42
- self._parse_temp_data(split_temps[1].strip()) if len(split_temps) > 1 else None
43
- )
44
- else:
45
- # Replay only has current temp (when printer is idle)
46
- self._current = self._parse_temp_data(data)
47
- self._set = None
48
-
49
- def _parse_temp_data(self, data: str) -> str:
50
- """
51
- Parse a raw temperature string value, round it, and return as string.
52
-
53
- Args:
54
- data: The raw temperature string (e.g., "210.5", "60")
55
-
56
- Returns:
57
- The rounded temperature as a string
58
- """
59
- if "." in data:
60
- data = data.split(".")[0].strip() # Truncate decimal part before rounding
61
- temp = round(float(data))
62
- return str(temp)
63
-
64
- def get_full(self) -> str:
65
- """
66
- Get the full temperature string, including current and set temperatures.
67
-
68
- Returns:
69
- A string in the format "current/set" or just "current" if set temperature is not available
70
- """
71
- if self._set is None:
72
- return self._current
73
- return f"{self._current}/{self._set}"
74
-
75
- def get_current(self) -> int:
76
- """
77
- Get the current temperature as a number.
78
-
79
- Returns:
80
- The current temperature in Celsius
81
- """
82
- return int(self._current)
83
-
84
- def get_set(self) -> int:
85
- """
86
- Get the target (set) temperature as a number.
87
-
88
- Returns:
89
- The set temperature in Celsius, or 0 if not set
90
- """
91
- return int(self._set) if self._set else 0
92
-
93
-
94
- class TempInfo:
95
- """
96
- Represents the temperature information for the printer's extruder and bed.
97
-
98
- This data is typically parsed from the response of an M105 G-code command,
99
- which reports the current and target temperatures.
100
- """
101
-
102
- def __init__(self) -> None:
103
- """Initialize empty temperature info."""
104
- self._extruder_temp: TempData | None = None
105
- """Temperature data for the extruder."""
106
-
107
- self._bed_temp: TempData | None = None
108
- """Temperature data for the print bed."""
109
-
110
- def from_replay(self, replay: str) -> Optional["TempInfo"]:
111
- """
112
- Parse a raw string replay from M105 command to populate temperature info.
113
-
114
- The M105 response format is usually a single line (after the "ok" or command echo)
115
- containing temperature segments like "T0:25/0" or "T:210/210 B:60/60".
116
- This method splits the relevant line by spaces and then parses each segment.
117
- It looks for segments starting with "T0:", "T):", or "T:" for extruder temperature,
118
- and "B:" for bed temperature.
119
-
120
- Args:
121
- replay: The raw multi-line string response from the printer
122
-
123
- Returns:
124
- The populated TempInfo instance, or None if parsing fails
125
- """
126
- if not replay:
127
- return None
128
-
129
- try:
130
- lines = [
131
- line.strip() for line in replay.replace("\r", "\n").split("\n") if line.strip()
132
- ]
133
- if not lines:
134
- logger.error("TempInfo replay has invalid data: %s", replay)
135
- return None
136
-
137
- extruder_data_str = None
138
- bed_data_str = None
139
-
140
- for line in lines:
141
- for segment in line.split(" "):
142
- if segment.startswith("T0:"):
143
- extruder_data_str = segment.replace("T0:", "")
144
- elif segment.startswith("T):"):
145
- extruder_data_str = segment.replace("T):", "")
146
- elif segment.startswith("T:"):
147
- extruder_data_str = segment.replace("T:", "")
148
- elif segment.startswith("B:"):
149
- bed_data_str = segment.replace("B:", "")
150
-
151
- # If we found extruder data, create TempData object
152
- if extruder_data_str:
153
- self._extruder_temp = TempData(extruder_data_str)
154
- else:
155
- logger.error(f"No extruder temperature found in replay data: {replay}")
156
- return None # Extruder temp is critical
157
-
158
- # If we found bed data, create TempData object; otherwise, default to 0/0
159
- if bed_data_str:
160
- self._bed_temp = TempData(bed_data_str)
161
- else:
162
- logger.warning(
163
- f"No bed temperature found in replay data, defaulting to 0/0: {replay}"
164
- )
165
- self._bed_temp = TempData("0/0") # Default if not present
166
-
167
- return self
168
-
169
- except Exception as e:
170
- logger.error(f"Unable to create TempInfo instance from replay: {e}")
171
- logger.error(f"Raw replay data: {replay}")
172
- return None
173
-
174
- def get_extruder_temp(self) -> TempData | None:
175
- """
176
- Get the extruder temperature data.
177
-
178
- Returns:
179
- A TempData object for the extruder, or None if not available
180
- """
181
- return self._extruder_temp
182
-
183
- def get_bed_temp(self) -> TempData | None:
184
- """
185
- Get the print bed temperature data.
186
-
187
- Returns:
188
- A TempData object for the bed, or None if not available
189
- """
190
- return self._bed_temp
191
-
192
- def is_cooled(self) -> bool:
193
- """
194
- Check if both the bed and extruder are cooled down to relatively low temperatures.
195
-
196
- Bed temperature <= 40°C and extruder temperature <= 200°C (though 200 is still hot).
197
- Use with caution, as "cooled" here is relative and 200C is still very hot for an extruder.
198
-
199
- Returns:
200
- True if temperatures are at or below the defined thresholds, False otherwise
201
- """
202
- bed_temp = self._bed_temp.get_current() if self._bed_temp else 0
203
- extruder_temp = self._extruder_temp.get_current() if self._extruder_temp else 0
204
- return bed_temp <= 40 and extruder_temp <= 200
205
-
206
- def are_temps_safe(self) -> bool:
207
- """
208
- Check if the current temperatures are within a generally safe operating range.
209
-
210
- Prevents overheating (extruder < 250°C, bed < 100°C).
211
- These are arbitrary "safe" limits and might need adjustment based on specific printer/material.
212
-
213
- Returns:
214
- True if temperatures are below the defined "safe" thresholds, False otherwise
215
- """
216
- bed_temp = self._bed_temp.get_current() if self._bed_temp else 0
217
- extruder_temp = self._extruder_temp.get_current() if self._extruder_temp else 0
218
- return extruder_temp < 250 and bed_temp < 100
1
+ """
2
+ Temperature information parser for FlashForge 3D printers.
3
+
4
+ This module parses the response from M105 command to extract temperature data
5
+ for the extruder and print bed.
6
+ """
7
+
8
+ import logging
9
+ from typing import Optional
10
+
11
+ logger = logging.getLogger(__name__)
12
+
13
+
14
+ class TempData:
15
+ """
16
+ Represents temperature data for a single component (e.g., extruder or bed).
17
+
18
+ Includes current temperature and target (set) temperature.
19
+ Temperatures are stored as strings but can be retrieved as numbers.
20
+ """
21
+
22
+ def __init__(self, data: str) -> None:
23
+ """
24
+ Create a TempData instance by parsing a temperature string.
25
+
26
+ The input string can be in the format "current/set" (e.g., "210/210")
27
+ or just "current" (e.g., "25") if the target temperature is not specified.
28
+ It also handles and removes a trailing "/0.0" if present from some printer firmwares.
29
+ All temperatures are rounded to the nearest integer.
30
+
31
+ Args:
32
+ data: The temperature data string (e.g., "210/210", "25", "60/60/0.0")
33
+ """
34
+ # Handle potential formatting issues by removing any non-relevant part
35
+ data = data.replace("/0.0", "") # Remove trailing '/0.0' if exists
36
+
37
+ if "/" in data:
38
+ # Replay has current/set temps
39
+ split_temps = data.split("/")
40
+ self._current = self._parse_temp_data(split_temps[0].strip())
41
+ self._set = (
42
+ self._parse_temp_data(split_temps[1].strip()) if len(split_temps) > 1 else None
43
+ )
44
+ else:
45
+ # Replay only has current temp (when printer is idle)
46
+ self._current = self._parse_temp_data(data)
47
+ self._set = None
48
+
49
+ def _parse_temp_data(self, data: str) -> str:
50
+ """
51
+ Parse a raw temperature string value, round it, and return as string.
52
+
53
+ Args:
54
+ data: The raw temperature string (e.g., "210.5", "60")
55
+
56
+ Returns:
57
+ The rounded temperature as a string
58
+ """
59
+ if "." in data:
60
+ data = data.split(".")[0].strip() # Truncate decimal part before rounding
61
+ temp = round(float(data))
62
+ return str(temp)
63
+
64
+ def get_full(self) -> str:
65
+ """
66
+ Get the full temperature string, including current and set temperatures.
67
+
68
+ Returns:
69
+ A string in the format "current/set" or just "current" if set temperature is not available
70
+ """
71
+ if self._set is None:
72
+ return self._current
73
+ return f"{self._current}/{self._set}"
74
+
75
+ def get_current(self) -> int:
76
+ """
77
+ Get the current temperature as a number.
78
+
79
+ Returns:
80
+ The current temperature in Celsius
81
+ """
82
+ return int(self._current)
83
+
84
+ def get_set(self) -> int:
85
+ """
86
+ Get the target (set) temperature as a number.
87
+
88
+ Returns:
89
+ The set temperature in Celsius, or 0 if not set
90
+ """
91
+ return int(self._set) if self._set else 0
92
+
93
+
94
+ class TempInfo:
95
+ """
96
+ Represents the temperature information for the printer's extruder and bed.
97
+
98
+ This data is typically parsed from the response of an M105 G-code command,
99
+ which reports the current and target temperatures.
100
+ """
101
+
102
+ def __init__(self) -> None:
103
+ """Initialize empty temperature info."""
104
+ self._extruder_temp: TempData | None = None
105
+ """Temperature data for the extruder."""
106
+
107
+ self._bed_temp: TempData | None = None
108
+ """Temperature data for the print bed."""
109
+
110
+ def from_replay(self, replay: str) -> Optional["TempInfo"]:
111
+ """
112
+ Parse a raw string replay from M105 command to populate temperature info.
113
+
114
+ The M105 response format is usually a single line (after the "ok" or command echo)
115
+ containing temperature segments like "T0:25/0" or "T:210/210 B:60/60".
116
+ This method splits the relevant line by spaces and then parses each segment.
117
+ It looks for segments starting with "T0:", "T):", or "T:" for extruder temperature,
118
+ and "B:" for bed temperature.
119
+
120
+ Args:
121
+ replay: The raw multi-line string response from the printer
122
+
123
+ Returns:
124
+ The populated TempInfo instance, or None if parsing fails
125
+ """
126
+ if not replay:
127
+ return None
128
+
129
+ try:
130
+ lines = [
131
+ line.strip() for line in replay.replace("\r", "\n").split("\n") if line.strip()
132
+ ]
133
+ if not lines:
134
+ logger.error("TempInfo replay has invalid data: %s", replay)
135
+ return None
136
+
137
+ extruder_data_str = None
138
+ bed_data_str = None
139
+
140
+ for line in lines:
141
+ for segment in line.split(" "):
142
+ if segment.startswith("T0:"):
143
+ extruder_data_str = segment.replace("T0:", "")
144
+ elif segment.startswith("T):"):
145
+ extruder_data_str = segment.replace("T):", "")
146
+ elif segment.startswith("T:"):
147
+ extruder_data_str = segment.replace("T:", "")
148
+ elif segment.startswith("B:"):
149
+ bed_data_str = segment.replace("B:", "")
150
+
151
+ # If we found extruder data, create TempData object
152
+ if extruder_data_str:
153
+ self._extruder_temp = TempData(extruder_data_str)
154
+ else:
155
+ logger.error(f"No extruder temperature found in replay data: {replay}")
156
+ return None # Extruder temp is critical
157
+
158
+ # If we found bed data, create TempData object; otherwise, default to 0/0
159
+ if bed_data_str:
160
+ self._bed_temp = TempData(bed_data_str)
161
+ else:
162
+ logger.warning(
163
+ f"No bed temperature found in replay data, defaulting to 0/0: {replay}"
164
+ )
165
+ self._bed_temp = TempData("0/0") # Default if not present
166
+
167
+ return self
168
+
169
+ except Exception as e:
170
+ logger.error(f"Unable to create TempInfo instance from replay: {e}")
171
+ logger.error(f"Raw replay data: {replay}")
172
+ return None
173
+
174
+ def get_extruder_temp(self) -> TempData | None:
175
+ """
176
+ Get the extruder temperature data.
177
+
178
+ Returns:
179
+ A TempData object for the extruder, or None if not available
180
+ """
181
+ return self._extruder_temp
182
+
183
+ def get_bed_temp(self) -> TempData | None:
184
+ """
185
+ Get the print bed temperature data.
186
+
187
+ Returns:
188
+ A TempData object for the bed, or None if not available
189
+ """
190
+ return self._bed_temp
191
+
192
+ def is_cooled(self) -> bool:
193
+ """
194
+ Check if both the bed and extruder are cooled down to relatively low temperatures.
195
+
196
+ Bed temperature <= 40°C and extruder temperature <= 200°C (though 200 is still hot).
197
+ Use with caution, as "cooled" here is relative and 200C is still very hot for an extruder.
198
+
199
+ Returns:
200
+ True if temperatures are at or below the defined thresholds, False otherwise
201
+ """
202
+ bed_temp = self._bed_temp.get_current() if self._bed_temp else 0
203
+ extruder_temp = self._extruder_temp.get_current() if self._extruder_temp else 0
204
+ return bed_temp <= 40 and extruder_temp <= 200
205
+
206
+ def are_temps_safe(self) -> bool:
207
+ """
208
+ Check if the current temperatures are within a generally safe operating range.
209
+
210
+ Prevents overheating (extruder < 250°C, bed < 100°C).
211
+ These are arbitrary "safe" limits and might need adjustment based on specific printer/material.
212
+
213
+ Returns:
214
+ True if temperatures are below the defined "safe" thresholds, False otherwise
215
+ """
216
+ bed_temp = self._bed_temp.get_current() if self._bed_temp else 0
217
+ extruder_temp = self._extruder_temp.get_current() if self._extruder_temp else 0
218
+ return extruder_temp < 250 and bed_temp < 100