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.
Files changed (70) hide show
  1. flashforge/__init__.py +137 -56
  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 +150 -77
  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 -40
  57. flashforge/threemf/parser.py +560 -560
  58. flashforge/threemf/warnings.py +58 -58
  59. {flashforge_python_api-1.6.0.dist-info → flashforge_python_api-3.1.0.dist-info}/METADATA +46 -47
  60. flashforge_python_api-3.1.0.dist-info/RECORD +69 -0
  61. {flashforge_python_api-1.6.0.dist-info → flashforge_python_api-3.1.0.dist-info}/WHEEL +1 -1
  62. {flashforge_python_api-1.6.0.dist-info → flashforge_python_api-3.1.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 -896
  67. flashforge/api/controls/temp_control.py +0 -309
  68. flashforge/client.py +0 -609
  69. flashforge_python_api-1.6.0.dist-info/RECORD +0 -52
  70. {flashforge_python_api-1.6.0.dist-info → flashforge_python_api-3.1.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,80 @@
1
+ """
2
+ Printer backends, one per family, and the connect factory.
3
+
4
+ - Dual-API (HTTP + TCP): :class:`Adventurer5MBackend`, :class:`Adventurer5MProBackend`,
5
+ :class:`AD5XBackend`.
6
+ - HTTP-only: :class:`Creator5Backend` (Creator 5 and Creator 5 Pro). No TCP code.
7
+ - Legacy (TCP only): :class:`LegacyBackend` (Adventurer 3, Adventurer 4, generic).
8
+
9
+ Use :func:`connect_printer` to get the right one.
10
+ """
11
+
12
+ from .connect import ConnectOptions, ConnectTarget, connect_printer, create_http_backend
13
+ from .creator5_backend import NOZZLE_COUNT, NOZZLE_OFF, TEMP_NO_CHANGE, TEMP_OFF, Creator5Backend
14
+ from .dual_api_backend import DualApiBackend, uses_new_job_format
15
+ from .dual_api_models import AD5XBackend, Adventurer5MBackend, Adventurer5MProBackend
16
+ from .http_core import UPLOAD_TIMEOUT, DetailResult, HttpCore, describe_detail_rejection
17
+ from .http_printer_backend import (
18
+ PRINTER_CTL_NO_CHANGE,
19
+ HttpPrinterBackend,
20
+ encode_material_mappings,
21
+ validate_material_mappings,
22
+ )
23
+ from .legacy_backend import (
24
+ A3Transport,
25
+ A4Transport,
26
+ GenericLegacyTransport,
27
+ LegacyBackend,
28
+ LegacyPrinterInfo,
29
+ LegacyTransport,
30
+ create_legacy_transport,
31
+ )
32
+ from .printer_backend import PrinterBackend, PrinterIdentity
33
+ from .types import (
34
+ FiltrationMode,
35
+ LocalJobParams,
36
+ MaterialMapping,
37
+ PrintOverrides,
38
+ SlotAction,
39
+ UploadJobParams,
40
+ )
41
+
42
+ __all__ = [
43
+ "A3Transport",
44
+ "A4Transport",
45
+ "AD5XBackend",
46
+ "Adventurer5MBackend",
47
+ "Adventurer5MProBackend",
48
+ "ConnectOptions",
49
+ "ConnectTarget",
50
+ "Creator5Backend",
51
+ "DetailResult",
52
+ "DualApiBackend",
53
+ "FiltrationMode",
54
+ "GenericLegacyTransport",
55
+ "HttpCore",
56
+ "HttpPrinterBackend",
57
+ "LegacyBackend",
58
+ "LegacyPrinterInfo",
59
+ "LegacyTransport",
60
+ "LocalJobParams",
61
+ "MaterialMapping",
62
+ "NOZZLE_COUNT",
63
+ "NOZZLE_OFF",
64
+ "PRINTER_CTL_NO_CHANGE",
65
+ "PrintOverrides",
66
+ "PrinterBackend",
67
+ "PrinterIdentity",
68
+ "SlotAction",
69
+ "TEMP_NO_CHANGE",
70
+ "TEMP_OFF",
71
+ "UPLOAD_TIMEOUT",
72
+ "UploadJobParams",
73
+ "connect_printer",
74
+ "create_http_backend",
75
+ "create_legacy_transport",
76
+ "describe_detail_rejection",
77
+ "encode_material_mappings",
78
+ "uses_new_job_format",
79
+ "validate_material_mappings",
80
+ ]
@@ -0,0 +1,275 @@
1
+ """
2
+ The connect factory. It picks the family backend and returns it ready to use.
3
+
4
+ Model resolution:
5
+
6
+ - Modern printer found by discovery: the model comes from the discovery product ID, and
7
+ the connection only verifies the serial number and check code over ``/detail``.
8
+ - No discovery result (manual IP, saved printer): the model comes from the ``/detail``
9
+ response of that check (PID first, then the factory model name).
10
+ - Legacy printer: discovery already names AD3/AD4. Without a discovery result (and with no
11
+ check code), the backend probes the TCP channel with M115.
12
+ - ``force_legacy``: always the legacy family over TCP, even for a modern printer.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import asyncio
18
+ from collections.abc import Callable
19
+ from dataclasses import dataclass
20
+
21
+ from ..capabilities.models import BackendFamily, PrinterModelId
22
+ from ..capabilities.registry import get_model_spec
23
+ from ..capabilities.resolve_model import model_from_machine_type
24
+ from ..discovery.discovery import DiscoveredPrinter
25
+ from ..exceptions import PrinterConnectionError
26
+ from ..models.machine_info import FFMachineInfo
27
+ from ..models.machine_info_parser import MachineInfoParser
28
+ from .creator5_backend import Creator5Backend
29
+ from .dual_api_backend import DualApiBackend
30
+ from .dual_api_models import AD5XBackend, Adventurer5MBackend, Adventurer5MProBackend
31
+ from .http_core import HttpCore
32
+ from .http_printer_backend import HttpPrinterBackend
33
+ from .legacy_backend import LegacyBackend, LegacyTransport, create_legacy_transport
34
+ from .printer_backend import PrinterBackend
35
+
36
+ LegacyTransportFactory = Callable[[PrinterModelId, str, "int | None"], LegacyTransport]
37
+
38
+
39
+ @dataclass(frozen=True)
40
+ class ConnectTarget:
41
+ """Where to connect. A :class:`DiscoveredPrinter` also works."""
42
+
43
+ ip_address: str
44
+ #: Serial number. Required for modern printers.
45
+ serial_number: str | None = None
46
+ #: Model from discovery or a saved printer. None when unknown.
47
+ model: PrinterModelId | None = None
48
+ #: HTTP API port from discovery (``event_port``). Default 8898.
49
+ event_port: int | None = None
50
+ #: TCP command port from discovery (``command_port``). Default 8899.
51
+ command_port: int | None = None
52
+
53
+
54
+ @dataclass(frozen=True)
55
+ class ConnectOptions:
56
+ """Options for :func:`connect_printer`."""
57
+
58
+ #: Check code (LAN access code). Required for modern printers.
59
+ check_code: str | None = None
60
+ #: Use the legacy TCP backend even for a modern printer.
61
+ force_legacy: bool = False
62
+ #: Override the HTTP API port.
63
+ http_port: int | None = None
64
+ #: Override the TCP command port.
65
+ tcp_port: int | None = None
66
+ #: HTTP request timeout in seconds.
67
+ timeout_s: float = 15.0
68
+ #: Creates the legacy TCP transport. For tests and custom transports.
69
+ legacy_transport: LegacyTransportFactory | None = None
70
+
71
+
72
+ class _HttpUnreachableError(PrinterConnectionError):
73
+ """The HTTP API did not answer at all. Internal: lets the factory try the legacy probe."""
74
+
75
+
76
+ async def _initialize_or_dispose(backend: HttpPrinterBackend | LegacyBackend) -> bool:
77
+ """
78
+ Runs ``backend.initialize()``. If the caller cancels or times out the connect while the TCP
79
+ login (``~M601``) is in flight, the backend is disposed before the cancel propagates:
80
+ an abandoned login would keep the socket open and hold the printer's control lock.
81
+ """
82
+ try:
83
+ return await backend.initialize()
84
+ except BaseException:
85
+ await asyncio.shield(backend.dispose())
86
+ raise
87
+
88
+
89
+ def _is_modern(model: PrinterModelId | None) -> bool:
90
+ if model is None:
91
+ return False
92
+ return get_model_spec(model).family in (BackendFamily.DUAL_API, BackendFamily.HTTP_ONLY)
93
+
94
+
95
+ def _legacy_model(model: PrinterModelId | None) -> PrinterModelId:
96
+ if model in (PrinterModelId.ADVENTURER_3, PrinterModelId.ADVENTURER_4):
97
+ return model
98
+ return PrinterModelId.GENERIC_LEGACY
99
+
100
+
101
+ def _as_target(target: ConnectTarget | DiscoveredPrinter) -> ConnectTarget:
102
+ if isinstance(target, ConnectTarget):
103
+ return target
104
+ model = PrinterModelId(str(target.model)) if target.model else None
105
+ return ConnectTarget(
106
+ ip_address=target.ip_address,
107
+ serial_number=target.serial_number,
108
+ model=model,
109
+ event_port=target.event_port,
110
+ command_port=target.command_port,
111
+ )
112
+
113
+
114
+ async def connect_printer(
115
+ target: ConnectTarget | DiscoveredPrinter,
116
+ options: ConnectOptions | None = None,
117
+ ) -> PrinterBackend:
118
+ """
119
+ Connects to a printer and returns its family backend.
120
+
121
+ Raises:
122
+ PrinterConnectionError: with a plain-language reason when the connection fails.
123
+ FlashForgeResponseError: the printer answered ``/detail`` with a payload that did
124
+ not parse (a library bug report, not a connection problem).
125
+ """
126
+ opts = options or ConnectOptions()
127
+ tgt = _as_target(target)
128
+ known = tgt.model if tgt.model and tgt.model != PrinterModelId.UNKNOWN else None
129
+ tcp_port = opts.tcp_port if opts.tcp_port is not None else tgt.command_port
130
+ factory = opts.legacy_transport or create_legacy_transport
131
+
132
+ if opts.force_legacy:
133
+ return await _connect_legacy(
134
+ tgt.ip_address,
135
+ PrinterModelId.GENERIC_LEGACY if _is_modern(known) else known,
136
+ tcp_port,
137
+ factory,
138
+ )
139
+ if known is not None and get_model_spec(known).family == BackendFamily.LEGACY:
140
+ return await _connect_legacy(tgt.ip_address, known, tcp_port, factory)
141
+ if not opts.check_code or not tgt.serial_number:
142
+ if _is_modern(known):
143
+ raise PrinterConnectionError(
144
+ "This printer needs its serial number and check code. Enter the check code "
145
+ "shown on the printer."
146
+ )
147
+ # Manual IP with no credentials: only a legacy printer can answer.
148
+ return await _connect_legacy(tgt.ip_address, None, tcp_port, factory)
149
+ try:
150
+ return await _connect_modern(tgt, known, opts, tcp_port)
151
+ except _HttpUnreachableError as error:
152
+ # Manual IP with a check code, but the HTTP API did not answer at all: the printer can
153
+ # be a legacy model, which has no HTTP API. Try the TCP probe; keep the HTTP error if
154
+ # that fails too. A known modern model never gets here as a legacy printer.
155
+ if _is_modern(known):
156
+ raise PrinterConnectionError(str(error)) from None
157
+ try:
158
+ return await _connect_legacy(tgt.ip_address, None, tcp_port, factory)
159
+ except PrinterConnectionError:
160
+ raise PrinterConnectionError(str(error)) from None
161
+
162
+
163
+ async def _connect_modern(
164
+ target: ConnectTarget,
165
+ known: PrinterModelId | None,
166
+ opts: ConnectOptions,
167
+ tcp_port: int | None,
168
+ ) -> HttpPrinterBackend:
169
+ http = HttpCore(
170
+ target.ip_address,
171
+ target.serial_number or "",
172
+ opts.check_code or "",
173
+ http_port=opts.http_port if opts.http_port is not None else target.event_port,
174
+ timeout_s=opts.timeout_s,
175
+ )
176
+ try:
177
+ detail = await http.fetch_detail()
178
+ if detail.response is None:
179
+ if not detail.reachable:
180
+ raise _HttpUnreachableError(detail.error or "No /detail response.")
181
+ raise PrinterConnectionError(detail.error or "No /detail response.", detail.code)
182
+ info = MachineInfoParser.from_detail(detail.response.detail)
183
+ if info is None:
184
+ raise PrinterConnectionError("The printer returned an invalid /detail response.")
185
+ # The /detail PID and the discovery PID are the same firmware value. Prefer /detail
186
+ # when it names a model; otherwise keep the discovery model.
187
+ model = info.model_id if info.model_id != PrinterModelId.UNKNOWN else known
188
+ if model is None or not _is_modern(model):
189
+ raise PrinterConnectionError(
190
+ f'The printer model is not supported (pid {info.pid}, model "{info.model}").'
191
+ )
192
+ backend = create_http_backend(model, http, info, opts, tcp_port)
193
+ except BaseException:
194
+ await http.close()
195
+ raise
196
+ if not await _initialize_or_dispose(backend):
197
+ await backend.dispose()
198
+ raise PrinterConnectionError(
199
+ "The printer accepted the check code but the control channel did not open."
200
+ if isinstance(backend, DualApiBackend)
201
+ else "The printer accepted the check code but /product failed."
202
+ )
203
+ return backend
204
+
205
+
206
+ def create_http_backend(
207
+ model: PrinterModelId,
208
+ http: HttpCore,
209
+ info: FFMachineInfo,
210
+ options: ConnectOptions | None = None,
211
+ tcp_port: int | None = None,
212
+ ) -> HttpPrinterBackend:
213
+ """Creates the HTTP backend for a modern model. Exported for tests and custom flows."""
214
+ opts = options or ConnectOptions()
215
+ port = tcp_port if tcp_port is not None else opts.tcp_port
216
+ if model == PrinterModelId.ADVENTURER_5M:
217
+ return Adventurer5MBackend(http, info, tcp_port=port)
218
+ if model == PrinterModelId.ADVENTURER_5M_PRO:
219
+ return Adventurer5MProBackend(http, info, tcp_port=port)
220
+ if model == PrinterModelId.AD5X:
221
+ return AD5XBackend(http, info, tcp_port=port)
222
+ if model in (PrinterModelId.CREATOR_5, PrinterModelId.CREATOR_5_PRO):
223
+ return Creator5Backend(model, http, info)
224
+ raise PrinterConnectionError(f"{model} is not a modern HTTP printer.")
225
+
226
+
227
+ async def _probe_legacy_model(
228
+ probe_as: PrinterModelId,
229
+ ip_address: str,
230
+ tcp_port: int | None,
231
+ factory: LegacyTransportFactory,
232
+ ) -> PrinterModelId | None:
233
+ """Logs in with one TCP client type and reads M115. None when it got no valid answer."""
234
+ probe = factory(probe_as, ip_address, tcp_port)
235
+ try:
236
+ if not await probe.init_control():
237
+ return None
238
+ info = await probe.get_info()
239
+ if info is None:
240
+ return None
241
+ return _legacy_model(model_from_machine_type(info.machine_type))
242
+ except Exception: # noqa: BLE001 - a failed probe only means "not this client type"
243
+ return None
244
+ finally:
245
+ # Also runs on cancel/timeout, so an abandoned probe login never keeps the socket.
246
+ await asyncio.shield(probe.dispose())
247
+
248
+
249
+ async def _connect_legacy(
250
+ ip_address: str,
251
+ known: PrinterModelId | None,
252
+ tcp_port: int | None,
253
+ factory: LegacyTransportFactory,
254
+ ) -> LegacyBackend:
255
+ """Connects over TCP. Without a known model, M115 decides between AD3, AD4 and generic."""
256
+ model: PrinterModelId | None = _legacy_model(known) if known else None
257
+ if model is None:
258
+ # The Adventurer 3 answers M115 in its own format, which the generic parser cannot
259
+ # read, so the A3 client is the second probe.
260
+ model = await _probe_legacy_model(
261
+ PrinterModelId.GENERIC_LEGACY, ip_address, tcp_port, factory
262
+ ) or await _probe_legacy_model(PrinterModelId.ADVENTURER_3, ip_address, tcp_port, factory)
263
+ if model is None:
264
+ raise PrinterConnectionError(
265
+ f"No answer on the TCP command channel at {ip_address}. Check the IP address "
266
+ "and that the printer is on."
267
+ )
268
+ backend = LegacyBackend(model, ip_address, factory(model, ip_address, tcp_port))
269
+ if not await _initialize_or_dispose(backend):
270
+ await backend.dispose()
271
+ raise PrinterConnectionError(
272
+ f"The printer at {ip_address} did not accept the TCP login. Close other apps that "
273
+ "use the printer and try again."
274
+ )
275
+ return backend
@@ -0,0 +1,191 @@
1
+ """
2
+ The HTTP-only family: Creator 5 and Creator 5 Pro.
3
+
4
+ These printers run no TCP server, so this backend has no TCP code at all. It is not a
5
+ subclass of the dual-API family. Temperatures go over ``temperatureCtl_cmd`` with a
6
+ 4-entry ``nozzles`` array. Material matching happens at print start (``/printGcode``).
7
+ Only the Creator 5 Pro has a chamber heater.
8
+
9
+ The Creator 5 rules come from the API docs and the emulator. They are not yet confirmed on
10
+ real hardware by the maintainers (``capabilities.hardware_verified`` is False).
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from typing import Any
16
+
17
+ from ..api.constants.commands import Commands
18
+ from ..capabilities.models import BackendFamily, PrinterModelId
19
+ from ..exceptions import InvalidParameterError
20
+ from ..models.machine_info import FFMachineInfo
21
+ from .http_core import HttpCore
22
+ from .http_printer_backend import (
23
+ HttpPrinterBackend,
24
+ encode_material_mappings,
25
+ validate_material_mappings,
26
+ )
27
+ from .types import LocalJobParams, UploadJobParams
28
+
29
+ #: ``temperatureCtl_cmd``: leave this heater unchanged.
30
+ TEMP_NO_CHANGE = -200
31
+ #: ``temperatureCtl_cmd``: turn a scalar heater (platform, chamber) off.
32
+ TEMP_OFF = -100
33
+ #: Turns a tool off inside ``nozzles``. The firmware treats only a literal 0 as off; it
34
+ #: ignores -100 there and the tool keeps heating.
35
+ NOZZLE_OFF = 0
36
+ #: The firmware ignores the ``nozzles`` array unless it has exactly 4 entries.
37
+ NOZZLE_COUNT = 4
38
+
39
+
40
+ class Creator5Backend(HttpPrinterBackend):
41
+ """Creator 5 and Creator 5 Pro."""
42
+
43
+ family = BackendFamily.HTTP_ONLY
44
+
45
+ def __init__(
46
+ self,
47
+ model: PrinterModelId,
48
+ http: HttpCore,
49
+ info: FFMachineInfo,
50
+ ) -> None:
51
+ if model not in (PrinterModelId.CREATOR_5, PrinterModelId.CREATOR_5_PRO):
52
+ raise ValueError(f"{model} is not a Creator 5 model")
53
+ super().__init__(model, http, info)
54
+
55
+ # ---- Temperatures --------------------------------------------------------------------
56
+
57
+ async def _send_temp(
58
+ self,
59
+ *,
60
+ platform: int | None = None,
61
+ chamber: int | None = None,
62
+ nozzles: list[int] | None = None,
63
+ ) -> bool:
64
+ """
65
+ Sends ``temperatureCtl_cmd``. Unset heaters are sent as TEMP_NO_CHANGE. The
66
+ ``nozzles`` array is always present with 4 entries, so a bed or chamber change
67
+ leaves every tool alone.
68
+ """
69
+ return await self.http.send_control_command(
70
+ Commands.TEMP_CONTROL_CMD,
71
+ {
72
+ "rightNozzle": TEMP_NO_CHANGE,
73
+ "leftNozzle": TEMP_NO_CHANGE,
74
+ "platform": TEMP_NO_CHANGE if platform is None else platform,
75
+ "chamber": TEMP_NO_CHANGE if chamber is None else chamber,
76
+ "nozzles": nozzles if nozzles is not None else [TEMP_NO_CHANGE] * NOZZLE_COUNT,
77
+ },
78
+ )
79
+
80
+ @staticmethod
81
+ def _nozzle_array(tool_index: int, value: int) -> list[int]:
82
+ if not isinstance(tool_index, int) or not 0 <= tool_index < NOZZLE_COUNT:
83
+ raise InvalidParameterError(
84
+ f"tool_index must be 0-{NOZZLE_COUNT - 1}, got {tool_index}."
85
+ )
86
+ nozzles = [TEMP_NO_CHANGE] * NOZZLE_COUNT
87
+ nozzles[tool_index] = value
88
+ return nozzles
89
+
90
+ async def set_extruder_temp(self, temp: int) -> bool:
91
+ """
92
+ Sets tool 0. The firmware drives tools only through ``nozzles``; it never reads
93
+ rightNozzle/leftNozzle. Use :meth:`set_tool_temp` for another tool.
94
+ """
95
+ return await self._send_temp(nozzles=self._nozzle_array(0, temp))
96
+
97
+ async def cancel_extruder_temp(self) -> bool:
98
+ return await self._send_temp(nozzles=self._nozzle_array(0, NOZZLE_OFF))
99
+
100
+ async def set_bed_temp(self, temp: int) -> bool:
101
+ return await self._send_temp(platform=temp)
102
+
103
+ async def cancel_bed_temp(self) -> bool:
104
+ return await self._send_temp(platform=TEMP_OFF)
105
+
106
+ async def set_tool_temp(self, tool_index: int, temp: int) -> bool:
107
+ return await self._send_temp(nozzles=self._nozzle_array(tool_index, temp))
108
+
109
+ async def set_tool_temps(self, temps: list[int]) -> bool:
110
+ """Sets all 4 tools. TEMP_NO_CHANGE (-200) keeps a tool, NOZZLE_OFF (0) turns it off."""
111
+ if len(temps) != NOZZLE_COUNT:
112
+ raise InvalidParameterError(f"Expected {NOZZLE_COUNT} temperatures, got {len(temps)}.")
113
+ return await self._send_temp(nozzles=list(temps))
114
+
115
+ async def cancel_tool_temp(self, tool_index: int) -> bool:
116
+ return await self._send_temp(nozzles=self._nozzle_array(tool_index, NOZZLE_OFF))
117
+
118
+ async def set_chamber_temp(self, temp: int) -> bool:
119
+ """Sets the chamber heater. Creator 5 Pro only. Keep the value in a safe range."""
120
+ if not self.capabilities.chamber.controllable:
121
+ self._unsupported("set_chamber_temp", self.capabilities.chamber.reason)
122
+ return await self._send_temp(chamber=temp)
123
+
124
+ async def cancel_chamber_temp(self) -> bool:
125
+ if not self.capabilities.chamber.controllable:
126
+ self._unsupported("cancel_chamber_temp", self.capabilities.chamber.reason)
127
+ return await self._send_temp(chamber=TEMP_OFF)
128
+
129
+ # ---- Files ---------------------------------------------------------------------------
130
+
131
+ async def get_local_files(self) -> list[str]:
132
+ """No TCP file list on this printer: the names from ``/gcodeList`` (10 most recent)."""
133
+ return [entry.gcode_file_name for entry in await self.http.fetch_recent_files()]
134
+
135
+ # ---- Upload and print start ----------------------------------------------------------
136
+
137
+ async def upload_file(self, params: UploadJobParams) -> bool:
138
+ """
139
+ Uploads a file. There is no ``firstLayerInspection`` header on this printer.
140
+ Mappings are sent only with ``start_print=True`` (the firmware keeps upload mappings
141
+ until the next print ends). ``useMatlStation`` and ``gcodeToolCnt`` are sent for
142
+ parity with FlashForge's own clients; the firmware only logs them.
143
+ """
144
+ if params.first_layer_inspection:
145
+ self._unsupported("upload_file", "The Creator 5 series has no first-layer inspection.")
146
+ mappings = params.material_mappings
147
+ headers = {
148
+ "printNow": str(params.start_print).lower(),
149
+ "levelingBeforePrint": str(params.leveling_before_print).lower(),
150
+ "flowCalibration": str(params.flow_calibration).lower(),
151
+ "timeLapseVideo": str(params.time_lapse_video).lower(),
152
+ "useMatlStation": str(bool(mappings)).lower(),
153
+ "gcodeToolCnt": str(len(mappings)),
154
+ }
155
+ if mappings:
156
+ if not params.start_print:
157
+ raise InvalidParameterError(
158
+ "Material mappings on a Creator 5 upload need start_print=True. Upload "
159
+ "without them and pass them to start_local_job instead."
160
+ )
161
+ validate_material_mappings(mappings)
162
+ headers["materialMappings"] = encode_material_mappings(mappings)
163
+ return await self.http.upload(params.file_path, headers)
164
+
165
+ async def start_local_job(self, params: LocalJobParams) -> bool:
166
+ """
167
+ Starts a stored file with ``/printGcode``, sending only the fields the Creator 5
168
+ firmware reads. Give a mapping for every tool; mappings take effect only for a .3mf.
169
+ """
170
+ if not params.file_name or not params.file_name.strip():
171
+ raise InvalidParameterError("file_name must not be empty.")
172
+ mappings = params.material_mappings
173
+ validate_material_mappings(mappings)
174
+ body: dict[str, Any] = {
175
+ "fileName": params.file_name,
176
+ "levelingBeforePrint": params.leveling_before_print,
177
+ "flowCalibration": params.flow_calibration,
178
+ "timeLapseVideo": params.time_lapse_video,
179
+ }
180
+ if mappings:
181
+ body["materialMappings"] = [m.to_wire() for m in mappings]
182
+ return await self.http.send_print_command(body)
183
+
184
+ # ---- Material station ----------------------------------------------------------------
185
+
186
+ async def configure_slot(self, slot_id: int, material_name: str, hex_color: str) -> bool:
187
+ """
188
+ Sets per-tool material name and color (``msConfig_cmd``). The Creator 5 shows its 4
189
+ tool heads as the 4 slots. There is no load/unload (``ms_cmd``).
190
+ """
191
+ return await self._send_slot_config(slot_id, material_name, hex_color)