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,254 +1,119 @@
1
- """
2
- FlashForge Python API - Response Models
3
- """
4
-
5
- from pydantic import BaseModel, ConfigDict, Field, field_validator
6
-
7
- from .machine_info import FFGcodeFileEntry, FFPrinterDetail
8
-
9
-
10
- class GenericResponse(BaseModel):
11
- """Represents a generic response from the printer's API."""
12
-
13
- # `extra="allow"` on every inbound model: this is the envelope each printer
14
- # response inherits, so a firmware update that adds one top-level key must
15
- # not fail validation here. Callers cannot tell a parse failure from a real
16
- # error - `send_product_command` returns a bare False either way, which the
17
- # HA integration reports to the user as "check code incorrect".
18
- model_config = ConfigDict(extra="allow")
19
-
20
- code: int
21
- message: str = ""
22
-
23
-
24
- class DetailResponse(GenericResponse):
25
- """Represents the structure of the response from the printer's detail endpoint."""
26
-
27
- detail: FFPrinterDetail
28
-
29
-
30
- class Product(BaseModel):
31
- """
32
- Defines the structure of the `product` object nested within a `ProductResponse`.
33
-
34
- This contains various control state flags reported by the printer,
35
- indicating the status or availability of certain features like temperature controls,
36
- fan controls, and light controls. A state of 0 often means off/unavailable,
37
- while other numbers (typically 1) mean on/available or a specific mode.
38
-
39
- Field names match the actual camelCase format returned by the printer.
40
- """
41
-
42
- # `extra="allow"`: an unrecognized control-state flag must not fail
43
- # validation. `send_product_command` has no fallback - it returns False,
44
- # which is indistinguishable from the printer rejecting the credentials.
45
- model_config = ConfigDict(extra="allow")
46
-
47
- chamberTempCtrlState: int # noqa: N815 - field must match API camelCase response format
48
- externalFanCtrlState: int # noqa: N815 - field must match API camelCase response format
49
- internalFanCtrlState: int # noqa: N815 - field must match API camelCase response format
50
- lightCtrlState: int # noqa: N815 - field must match API camelCase response format
51
- nozzleTempCtrlState: int # noqa: N815 - field must match API camelCase response format
52
- platformTempCtrlState: int # noqa: N815 - field must match API camelCase response format
53
-
54
-
55
- class ProductResponse(GenericResponse):
56
- """
57
- Represents the expected structure of the response from the "product command"
58
- sent to the printer (typically to the `/product` endpoint).
59
-
60
- This response includes general status information (via `GenericResponse`)
61
- and a nested `product` object containing specific control states.
62
- """
63
-
64
- product: Product
65
-
66
-
67
- class FilamentArgs(BaseModel):
68
- """Represents the arguments for controlling the printer's filtration system."""
69
-
70
- model_config = ConfigDict(extra="forbid")
71
-
72
- internal: str = Field(description="Internal filtration state ('open' or 'close')")
73
- external: str = Field(description="External filtration state ('open' or 'close')")
74
-
75
- @field_validator("internal", "external")
76
- @classmethod
77
- def validate_filtration_state(cls, v: str) -> str:
78
- """Validate that the state is either 'open' or 'close'."""
79
- if v not in {"open", "close"}:
80
- raise ValueError(f"Filtration state must be 'open' or 'close', got: {v}")
81
- return v
82
-
83
- @classmethod
84
- def create(cls, internal_on: bool, external_on: bool) -> "FilamentArgs":
85
- """
86
- Create FilamentArgs from boolean states.
87
-
88
- Args:
89
- internal_on: Whether internal filtration should be open (True) or closed (False)
90
- external_on: Whether external filtration should be open (True) or closed (False)
91
-
92
- Returns:
93
- FilamentArgs instance with proper string states
94
- """
95
- return cls(
96
- internal="open" if internal_on else "close", external="open" if external_on else "close"
97
- )
98
-
99
-
100
- class AD5XMaterialMapping(BaseModel):
101
- """Represents a material mapping for AD5X multi-color printing. Maps a tool (extruder) to a specific material station slot."""
102
-
103
- # `extra="forbid"` deliberately, as on every outbound param model below:
104
- # these are request bodies this library constructs, so no firmware update
105
- # can break them, and forbidding extras turns a caller's typo'd keyword
106
- # into an error instead of a field the printer silently ignores.
107
- model_config = ConfigDict(extra="forbid", populate_by_name=True)
108
-
109
- tool_id: int = Field(ge=0, le=3, description="Tool ID (0-based: 0, 1, 2, 3)")
110
- slot_id: int = Field(ge=1, le=4, description="Slot ID (1-based: 1, 2, 3, 4)")
111
- material_name: str = Field(description="Name of the material (e.g., 'PLA', 'SILK')")
112
- tool_material_color: str = Field(
113
- description="Hex color code for the tool material (e.g., '#FFFFFF')"
114
- )
115
- slot_material_color: str = Field(
116
- description="Hex color code for the slot material (e.g., '#46328E')"
117
- )
118
-
119
- @field_validator("tool_material_color", "slot_material_color")
120
- @classmethod
121
- def validate_hex_color(cls, v: str) -> str:
122
- """Validate that the color is a valid hex color code."""
123
- import re
124
-
125
- if not re.match(r"^#[0-9A-Fa-f]{6}$", v):
126
- raise ValueError(f"Invalid hex color format: {v}")
127
- return v
128
-
129
-
130
- class AD5XLocalJobParams(BaseModel):
131
- """Parameters for starting an AD5X local job with material mappings. Used for multi-color prints that utilize the material station."""
132
-
133
- model_config = ConfigDict(extra="forbid", populate_by_name=True)
134
-
135
- file_name: str = Field(description="Name of the file on the printer to start")
136
- leveling_before_print: bool = Field(
137
- description="Whether to perform bed leveling before printing"
138
- )
139
- material_mappings: list[AD5XMaterialMapping] = Field(
140
- min_length=1, max_length=4, description="Array of material mappings (1-4 items)"
141
- )
142
-
143
-
144
- class AD5XSingleColorJobParams(BaseModel):
145
- """Parameters for starting an AD5X single-color local job. Used for single-color prints that do not require the material station."""
146
-
147
- model_config = ConfigDict(extra="forbid", populate_by_name=True)
148
-
149
- file_name: str = Field(description="Name of the file on the printer to start")
150
- leveling_before_print: bool = Field(
151
- description="Whether to perform bed leveling before printing"
152
- )
153
-
154
-
155
- class AD5XUploadParams(BaseModel):
156
- """Parameters for uploading a file to AD5X printer with material station support. Extends basic upload functionality with AD5X-specific features."""
157
-
158
- model_config = ConfigDict(extra="forbid", populate_by_name=True)
159
-
160
- file_path: str = Field(description="Local file path to upload")
161
- start_print: bool = Field(description="Whether to start printing immediately after upload")
162
- leveling_before_print: bool = Field(
163
- description="Whether to perform bed leveling before printing"
164
- )
165
- flow_calibration: bool = Field(description="Whether to enable flow calibration")
166
- first_layer_inspection: bool = Field(description="Whether to enable first layer inspection")
167
- time_lapse_video: bool = Field(description="Whether to enable time lapse video recording")
168
- material_mappings: list[AD5XMaterialMapping] = Field(
169
- min_length=1,
170
- max_length=4,
171
- description="Array of material mappings for the material station (1-4 items)",
172
- )
173
-
174
-
175
- class Creator5JobParams(BaseModel):
176
- """Parameters for starting a Creator 5 / Creator 5 Pro local print job.
177
-
178
- The body carries NO ``useMatlStation`` / ``gcodeToolCnt`` /
179
- ``firstLayerInspection`` (the latter doesn't exist on the C5).
180
- ``flowCalibration`` and ``timeLapseVideo`` are always present (default False).
181
- Map every tool, including a single-tool print: without mappings the firmware
182
- prints each tool from the slot with the slicer's filament number (filament 1
183
- -> slot 1). Mappings take effect only for a .3mf file.
184
- """
185
-
186
- model_config = ConfigDict(extra="forbid", populate_by_name=True)
187
-
188
- file_name: str = Field(description="Name of the file on the printer to start")
189
- leveling_before_print: bool = Field(
190
- description="Whether to perform bed leveling before printing"
191
- )
192
- flow_calibration: bool = Field(default=False, description="Whether to enable flow calibration")
193
- time_lapse_video: bool = Field(
194
- default=False, description="Whether to enable time lapse video recording"
195
- )
196
- material_mappings: list[AD5XMaterialMapping] | None = Field(
197
- default=None,
198
- max_length=4,
199
- description="Per-tool material mappings (1-4 items); recommended for every print",
200
- )
201
-
202
-
203
- class Creator5UploadParams(BaseModel):
204
- """Parameters for uploading a file to a Creator 5 / Creator 5 Pro.
205
-
206
- Mirrors the AD5X upload but omits ``firstLayerInspection`` (absent on the
207
- C5). ``material_mappings`` is sent as the base64 ``materialMappings`` header
208
- only when ``start_print`` is true. The firmware only logs ``use_matl_station``
209
- and ``gcode_tool_cnt``. The C5 firmware checks the booleans as the string
210
- "true"/"false".
211
- """
212
-
213
- model_config = ConfigDict(extra="forbid", populate_by_name=True)
214
-
215
- file_path: str = Field(description="Local file path to upload")
216
- start_print: bool = Field(description="Whether to start printing immediately after upload")
217
- leveling_before_print: bool = Field(
218
- description="Whether to perform bed leveling before printing"
219
- )
220
- flow_calibration: bool = Field(default=False, description="Whether to enable flow calibration")
221
- time_lapse_video: bool = Field(
222
- default=False, description="Whether to enable time lapse video recording"
223
- )
224
- use_matl_station: bool = Field(description="Whether this is a multi-tool material-station job")
225
- gcode_tool_cnt: int = Field(
226
- ge=1, le=4, description="Number of tools in the G-code (1-4 for the C5)"
227
- )
228
- material_mappings: list[AD5XMaterialMapping] | None = Field(
229
- default=None,
230
- max_length=4,
231
- description="Optional per-tool material mappings, sent only when start_print is true",
232
- )
233
-
234
-
235
- class GCodeListResponse(GenericResponse):
236
- """Represents the response structure for a G-code file list request."""
237
-
238
- # `extra="allow"`: see FFGcodeFileEntry. An unknown field at either level
239
- # costs the caller all per-file metadata, so neither level may forbid one.
240
- model_config = ConfigDict(extra="allow", populate_by_name=True)
241
-
242
- gcode_list: list[str] | list[FFGcodeFileEntry] | None = Field(default=None, alias="gcodeList")
243
- gcode_list_detail: list[FFGcodeFileEntry] | None = Field(default=None, alias="gcodeListDetail")
244
-
245
-
246
- class ThumbnailResponse(GenericResponse):
247
- """Represents the response structure for a G-code thumbnail request."""
248
-
249
- # `extra="allow"`: inbound, see GenericResponse.
250
- model_config = ConfigDict(extra="allow", populate_by_name=True)
251
-
252
- image_data: str = Field(
253
- alias="imageData", description="The thumbnail image data encoded as a base64 string"
254
- )
1
+ """
2
+ FlashForge Python API - Response Models
3
+ """
4
+
5
+ from pydantic import BaseModel, ConfigDict, Field, field_validator
6
+
7
+ from .machine_info import FFGcodeFileEntry, FFPrinterDetail
8
+
9
+
10
+ class GenericResponse(BaseModel):
11
+ """Represents a generic response from the printer's API."""
12
+
13
+ # `extra="allow"` on every inbound model: this is the envelope each printer
14
+ # response inherits, so a firmware update that adds one top-level key must
15
+ # not fail validation here. Callers cannot tell a parse failure from a real
16
+ # error - `send_product_command` returns a bare False either way, which the
17
+ # HA integration reports to the user as "check code incorrect".
18
+ model_config = ConfigDict(extra="allow")
19
+
20
+ code: int
21
+ message: str = ""
22
+
23
+
24
+ class DetailResponse(GenericResponse):
25
+ """Represents the structure of the response from the printer's detail endpoint."""
26
+
27
+ detail: FFPrinterDetail
28
+
29
+
30
+ class Product(BaseModel):
31
+ """
32
+ Defines the structure of the `product` object nested within a `ProductResponse`.
33
+
34
+ This contains various control state flags reported by the printer,
35
+ indicating the status or availability of certain features like temperature controls,
36
+ fan controls, and light controls. A state of 0 often means off/unavailable,
37
+ while other numbers (typically 1) mean on/available or a specific mode.
38
+
39
+ Field names match the actual camelCase format returned by the printer.
40
+ """
41
+
42
+ # `extra="allow"`: an unrecognized control-state flag must not fail
43
+ # validation. `send_product_command` has no fallback - it returns False,
44
+ # which is indistinguishable from the printer rejecting the credentials.
45
+ model_config = ConfigDict(extra="allow")
46
+
47
+ chamberTempCtrlState: int # noqa: N815 - field must match API camelCase response format
48
+ externalFanCtrlState: int # noqa: N815 - field must match API camelCase response format
49
+ internalFanCtrlState: int # noqa: N815 - field must match API camelCase response format
50
+ lightCtrlState: int # noqa: N815 - field must match API camelCase response format
51
+ nozzleTempCtrlState: int # noqa: N815 - field must match API camelCase response format
52
+ platformTempCtrlState: int # noqa: N815 - field must match API camelCase response format
53
+
54
+
55
+ class ProductResponse(GenericResponse):
56
+ """
57
+ Represents the expected structure of the response from the "product command"
58
+ sent to the printer (typically to the `/product` endpoint).
59
+
60
+ This response includes general status information (via `GenericResponse`)
61
+ and a nested `product` object containing specific control states.
62
+ """
63
+
64
+ product: Product
65
+
66
+
67
+ class FilamentArgs(BaseModel):
68
+ """Represents the arguments for controlling the printer's filtration system."""
69
+
70
+ model_config = ConfigDict(extra="forbid")
71
+
72
+ internal: str = Field(description="Internal filtration state ('open' or 'close')")
73
+ external: str = Field(description="External filtration state ('open' or 'close')")
74
+
75
+ @field_validator("internal", "external")
76
+ @classmethod
77
+ def validate_filtration_state(cls, v: str) -> str:
78
+ """Validate that the state is either 'open' or 'close'."""
79
+ if v not in {"open", "close"}:
80
+ raise ValueError(f"Filtration state must be 'open' or 'close', got: {v}")
81
+ return v
82
+
83
+ @classmethod
84
+ def create(cls, internal_on: bool, external_on: bool) -> "FilamentArgs":
85
+ """
86
+ Create FilamentArgs from boolean states.
87
+
88
+ Args:
89
+ internal_on: Whether internal filtration should be open (True) or closed (False)
90
+ external_on: Whether external filtration should be open (True) or closed (False)
91
+
92
+ Returns:
93
+ FilamentArgs instance with proper string states
94
+ """
95
+ return cls(
96
+ internal="open" if internal_on else "close", external="open" if external_on else "close"
97
+ )
98
+
99
+
100
+ class GCodeListResponse(GenericResponse):
101
+ """Represents the response structure for a G-code file list request."""
102
+
103
+ # `extra="allow"`: see FFGcodeFileEntry. An unknown field at either level
104
+ # costs the caller all per-file metadata, so neither level may forbid one.
105
+ model_config = ConfigDict(extra="allow", populate_by_name=True)
106
+
107
+ gcode_list: list[str] | list[FFGcodeFileEntry] | None = Field(default=None, alias="gcodeList")
108
+ gcode_list_detail: list[FFGcodeFileEntry] | None = Field(default=None, alias="gcodeListDetail")
109
+
110
+
111
+ class ThumbnailResponse(GenericResponse):
112
+ """Represents the response structure for a G-code thumbnail request."""
113
+
114
+ # `extra="allow"`: inbound, see GenericResponse.
115
+ model_config = ConfigDict(extra="allow", populate_by_name=True)
116
+
117
+ image_data: str = Field(
118
+ alias="imageData", description="The thumbnail image data encoded as a base64 string"
119
+ )
@@ -0,0 +1,43 @@
1
+ """The status model: one normalized printer snapshot for every family."""
2
+
3
+ from .printer_snapshot import (
4
+ CumulativeStats,
5
+ Fans,
6
+ FiltrationSnapshot,
7
+ JobProgress,
8
+ JobSnapshot,
9
+ LegacyStatusInput,
10
+ MaterialSlotSnapshot,
11
+ MaterialStationSnapshot,
12
+ PrinterRunState,
13
+ PrinterSnapshot,
14
+ PrintSettings,
15
+ TemperatureReading,
16
+ Temperatures,
17
+ legacy_machine_state,
18
+ reading,
19
+ snapshot_from_legacy,
20
+ snapshot_from_machine_info,
21
+ to_run_state,
22
+ )
23
+
24
+ __all__ = [
25
+ "CumulativeStats",
26
+ "Fans",
27
+ "FiltrationSnapshot",
28
+ "JobProgress",
29
+ "JobSnapshot",
30
+ "LegacyStatusInput",
31
+ "MaterialSlotSnapshot",
32
+ "MaterialStationSnapshot",
33
+ "PrintSettings",
34
+ "PrinterRunState",
35
+ "PrinterSnapshot",
36
+ "TemperatureReading",
37
+ "Temperatures",
38
+ "legacy_machine_state",
39
+ "reading",
40
+ "snapshot_from_legacy",
41
+ "snapshot_from_machine_info",
42
+ "to_run_state",
43
+ ]