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
flashforge/client.py
DELETED
|
@@ -1,609 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
FlashForge Python API - Main Unified Client
|
|
3
|
-
|
|
4
|
-
This module provides the main FlashForgeClient class that orchestrates both HTTP and TCP
|
|
5
|
-
communication layers for controlling FlashForge 3D printers.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
import asyncio
|
|
9
|
-
import logging
|
|
10
|
-
from dataclasses import dataclass
|
|
11
|
-
|
|
12
|
-
import aiohttp
|
|
13
|
-
from pydantic import ValidationError
|
|
14
|
-
|
|
15
|
-
from .api.constants.endpoints import CAMERA_STREAM_PORT, Endpoints
|
|
16
|
-
from .api.controls import Control, Files, Info, JobControl, TempControl
|
|
17
|
-
from .api.controls.info import MachineInfoParser
|
|
18
|
-
from .api.network.utils import NetworkUtils, json_from_response
|
|
19
|
-
from .models import FFMachineInfo, Product, ProductResponse
|
|
20
|
-
from .tcp import FlashForgeClient as TcpClient
|
|
21
|
-
from .tcp import FlashForgeTcpClientOptions, PrinterInfo
|
|
22
|
-
from .tcp.parsers.temp_info import TempInfo
|
|
23
|
-
|
|
24
|
-
logger = logging.getLogger(__name__)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
@dataclass(slots=True)
|
|
28
|
-
class FiveMClientConnectionOptions:
|
|
29
|
-
"""Optional connection and feature overrides for FiveMClient-compatible clients."""
|
|
30
|
-
|
|
31
|
-
http_port: int | None = None
|
|
32
|
-
tcp_port: int | None = None
|
|
33
|
-
led_control_override: bool | None = None
|
|
34
|
-
# Force HTTP-only transport (skip the TCP/8899 handshake). Set this for a
|
|
35
|
-
# Creator 5 / Creator 5 Pro, which exposes no TCP service; otherwise it is
|
|
36
|
-
# auto-detected from the firmware-reported model after `verify_connection`.
|
|
37
|
-
http_only: bool | None = None
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
class FlashForgeClient:
|
|
41
|
-
"""
|
|
42
|
-
Main client for interacting with a FlashForge 3D printer.
|
|
43
|
-
|
|
44
|
-
This class provides methods for controlling the printer, managing print jobs,
|
|
45
|
-
retrieving information, and handling file operations. It orchestrates both
|
|
46
|
-
HTTP and TCP communication layers to provide a unified interface.
|
|
47
|
-
"""
|
|
48
|
-
|
|
49
|
-
def __init__(
|
|
50
|
-
self,
|
|
51
|
-
ip_address: str,
|
|
52
|
-
serial_number: str,
|
|
53
|
-
check_code: str,
|
|
54
|
-
options: FiveMClientConnectionOptions | None = None,
|
|
55
|
-
):
|
|
56
|
-
"""
|
|
57
|
-
Creates an instance of FlashForgeClient.
|
|
58
|
-
|
|
59
|
-
Args:
|
|
60
|
-
ip_address: The IP address of the printer
|
|
61
|
-
serial_number: The serial number of the printer
|
|
62
|
-
check_code: The check code for the printer
|
|
63
|
-
"""
|
|
64
|
-
# Connection parameters
|
|
65
|
-
self.ip_address = ip_address
|
|
66
|
-
self.serial_number = serial_number
|
|
67
|
-
self.check_code = check_code
|
|
68
|
-
|
|
69
|
-
# Constants
|
|
70
|
-
self._PORT = options.http_port if options and options.http_port is not None else 8898
|
|
71
|
-
self._HTTP_TIMEOUT = 15.0
|
|
72
|
-
|
|
73
|
-
# HTTP client state
|
|
74
|
-
self._http_session: aiohttp.ClientSession | None = None
|
|
75
|
-
self._http_client_event = asyncio.Event()
|
|
76
|
-
self._http_client_event.set() # Not busy initially
|
|
77
|
-
|
|
78
|
-
# FIFO mutex for command submission. asyncio.Lock hands the lock to
|
|
79
|
-
# waiters in the order they asked for it. So command POSTs run one at
|
|
80
|
-
# a time, in submission order. Scope: command POSTs only (/control,
|
|
81
|
-
# /product, /printGcode). File uploads (/uploadGcode) and read/poll
|
|
82
|
-
# POSTs (/detail, /gcodeList, /gcodeThumb) stay outside the lock. An
|
|
83
|
-
# upload can run for minutes; pause and stop must never queue behind
|
|
84
|
-
# one.
|
|
85
|
-
self._command_lock = asyncio.Lock()
|
|
86
|
-
|
|
87
|
-
# TCP client setup
|
|
88
|
-
tcp_options = None
|
|
89
|
-
if options and options.tcp_port is not None:
|
|
90
|
-
tcp_options = FlashForgeTcpClientOptions(port=options.tcp_port)
|
|
91
|
-
self.tcp_client = TcpClient(ip_address, tcp_options)
|
|
92
|
-
|
|
93
|
-
# Control instances
|
|
94
|
-
self.control = Control(self)
|
|
95
|
-
self.job_control = JobControl(self)
|
|
96
|
-
self.info = Info(self)
|
|
97
|
-
self.files = Files(self)
|
|
98
|
-
self.temp_control = TempControl(self)
|
|
99
|
-
|
|
100
|
-
# Printer information cache
|
|
101
|
-
self.printer_name: str = ""
|
|
102
|
-
self.is_pro: bool = False
|
|
103
|
-
self._is_ad5x: bool = False
|
|
104
|
-
self.is_creator5: bool = False
|
|
105
|
-
self.is_creator5_pro: bool = False
|
|
106
|
-
self.firmware_version: str = ""
|
|
107
|
-
self.firmware_ver: str = ""
|
|
108
|
-
self.mac_address: str = ""
|
|
109
|
-
self.flash_cloud_code: str = ""
|
|
110
|
-
self.polar_cloud_code: str = ""
|
|
111
|
-
self.camera_stream_url: str = ""
|
|
112
|
-
self.lifetime_print_time: str = ""
|
|
113
|
-
self.lifetime_filament_meters: str = ""
|
|
114
|
-
self.product_info: Product | None = None
|
|
115
|
-
|
|
116
|
-
# Control states
|
|
117
|
-
self.led_control: bool = False
|
|
118
|
-
self.filtration_control: bool = False
|
|
119
|
-
self._detected_led_control: bool = False
|
|
120
|
-
self._detected_filtration_control: bool = False
|
|
121
|
-
self._led_control_override = (
|
|
122
|
-
options.led_control_override
|
|
123
|
-
if options and options.led_control_override is not None
|
|
124
|
-
else None
|
|
125
|
-
)
|
|
126
|
-
self._apply_feature_overrides()
|
|
127
|
-
|
|
128
|
-
# Transport selection. Creator 5 / Creator 5 Pro have no TCP/8899
|
|
129
|
-
# service, so they must run HTTP-only. An explicit override wins;
|
|
130
|
-
# otherwise http_only is auto-set from the detected model in
|
|
131
|
-
# `verify_connection` / `cache_details`.
|
|
132
|
-
self._http_only_override: bool | None = (
|
|
133
|
-
options.http_only if options and options.http_only is not None else None
|
|
134
|
-
)
|
|
135
|
-
self._http_only: bool = bool(self._http_only_override)
|
|
136
|
-
|
|
137
|
-
@property
|
|
138
|
-
def is_ad5x(self) -> bool:
|
|
139
|
-
"""
|
|
140
|
-
Indicates if the printer is an AD5X model.
|
|
141
|
-
|
|
142
|
-
Returns:
|
|
143
|
-
True if the printer is AD5X, False otherwise
|
|
144
|
-
"""
|
|
145
|
-
return self._is_ad5x
|
|
146
|
-
|
|
147
|
-
@property
|
|
148
|
-
def http_only(self) -> bool:
|
|
149
|
-
"""
|
|
150
|
-
Indicates whether the client should avoid the TCP transport.
|
|
151
|
-
|
|
152
|
-
True for Creator 5 / Creator 5 Pro (no TCP/8899 service) or when an
|
|
153
|
-
explicit ``http_only`` override was supplied at construction. When True,
|
|
154
|
-
TCP-only operations are unavailable (see :meth:`can_use_tcp`).
|
|
155
|
-
|
|
156
|
-
Returns:
|
|
157
|
-
True if the client must operate over HTTP only
|
|
158
|
-
"""
|
|
159
|
-
return self._http_only
|
|
160
|
-
|
|
161
|
-
def can_use_tcp(self, op: str = "") -> bool:
|
|
162
|
-
"""
|
|
163
|
-
Report whether a TCP-backed operation may be attempted.
|
|
164
|
-
|
|
165
|
-
Returns False whenever this client is HTTP-only (e.g. a Creator 5 with
|
|
166
|
-
no TCP/8899 service). TCP-delegating control/temperature methods check
|
|
167
|
-
this and no-op (return False) instead of hanging on a dead socket.
|
|
168
|
-
|
|
169
|
-
Args:
|
|
170
|
-
op: Optional operation name, included in the warning log.
|
|
171
|
-
|
|
172
|
-
Returns:
|
|
173
|
-
True if TCP operations are permitted, False otherwise
|
|
174
|
-
"""
|
|
175
|
-
if self._http_only:
|
|
176
|
-
logger.debug("%s() unavailable: printer has no TCP control channel (HTTP-only).", op)
|
|
177
|
-
return False
|
|
178
|
-
return True
|
|
179
|
-
|
|
180
|
-
def _update_http_only_from_model(self) -> None:
|
|
181
|
-
"""Recompute ``http_only`` from the detected model unless overridden."""
|
|
182
|
-
if self._http_only_override is not None:
|
|
183
|
-
self._http_only = bool(self._http_only_override)
|
|
184
|
-
else:
|
|
185
|
-
self._http_only = self.is_creator5 or self.is_creator5_pro
|
|
186
|
-
|
|
187
|
-
async def __aenter__(self) -> "FlashForgeClient":
|
|
188
|
-
"""Async context manager entry."""
|
|
189
|
-
await self._ensure_http_session()
|
|
190
|
-
await self.initialize()
|
|
191
|
-
return self
|
|
192
|
-
|
|
193
|
-
async def __aexit__(
|
|
194
|
-
self,
|
|
195
|
-
exc_type: type[BaseException] | None,
|
|
196
|
-
exc_val: BaseException | None,
|
|
197
|
-
exc_tb: object,
|
|
198
|
-
) -> None:
|
|
199
|
-
"""Async context manager exit."""
|
|
200
|
-
await self.dispose()
|
|
201
|
-
|
|
202
|
-
async def _ensure_http_session(self) -> aiohttp.ClientSession:
|
|
203
|
-
"""
|
|
204
|
-
Ensures that an HTTP session is available.
|
|
205
|
-
|
|
206
|
-
Returns:
|
|
207
|
-
The HTTP session instance
|
|
208
|
-
"""
|
|
209
|
-
if self._http_session is None or self._http_session.closed:
|
|
210
|
-
timeout = aiohttp.ClientTimeout(total=self._HTTP_TIMEOUT)
|
|
211
|
-
self._http_session = aiohttp.ClientSession(timeout=timeout, headers={"Accept": "*/*"})
|
|
212
|
-
return self._http_session
|
|
213
|
-
|
|
214
|
-
@property
|
|
215
|
-
def command_lock(self) -> asyncio.Lock:
|
|
216
|
-
"""
|
|
217
|
-
The FIFO lock that serializes command-submission HTTP POSTs.
|
|
218
|
-
|
|
219
|
-
Command POSTs (/control, /product, /printGcode) hold this lock while
|
|
220
|
-
the request is in flight. asyncio.Lock serves waiters in arrival order,
|
|
221
|
-
so concurrent commands run one at a time, first come first served.
|
|
222
|
-
Uploads and read/poll requests never take this lock. So a long upload
|
|
223
|
-
cannot delay a pause or stop command.
|
|
224
|
-
"""
|
|
225
|
-
return self._command_lock
|
|
226
|
-
|
|
227
|
-
async def initialize(self) -> bool:
|
|
228
|
-
"""
|
|
229
|
-
Initializes the FlashForgeClient and verifies the connection to the printer.
|
|
230
|
-
|
|
231
|
-
Returns:
|
|
232
|
-
True if initialization is successful, False otherwise
|
|
233
|
-
"""
|
|
234
|
-
connected = await self.verify_connection()
|
|
235
|
-
if connected:
|
|
236
|
-
return True
|
|
237
|
-
logger.warning("Failed to connect to the printer.")
|
|
238
|
-
return False
|
|
239
|
-
|
|
240
|
-
@property
|
|
241
|
-
def _http_client_busy(self) -> bool:
|
|
242
|
-
"""
|
|
243
|
-
Legacy property to maintain internal API compatibility.
|
|
244
|
-
Returns True if the client is busy (event is not set), False otherwise.
|
|
245
|
-
"""
|
|
246
|
-
return not self._http_client_event.is_set()
|
|
247
|
-
|
|
248
|
-
@_http_client_busy.setter
|
|
249
|
-
def _http_client_busy(self, value: bool) -> None:
|
|
250
|
-
"""
|
|
251
|
-
Sets the busy state using the event.
|
|
252
|
-
True means busy (clear event), False means not busy (set event).
|
|
253
|
-
"""
|
|
254
|
-
if value:
|
|
255
|
-
self._http_client_event.clear()
|
|
256
|
-
else:
|
|
257
|
-
self._http_client_event.set()
|
|
258
|
-
|
|
259
|
-
async def is_http_client_busy(self) -> bool:
|
|
260
|
-
"""
|
|
261
|
-
Checks if the HTTP client is currently busy.
|
|
262
|
-
Waits until the client is not busy before returning.
|
|
263
|
-
|
|
264
|
-
Returns:
|
|
265
|
-
False (always returns False after waiting, for compatibility)
|
|
266
|
-
"""
|
|
267
|
-
await self._http_client_event.wait()
|
|
268
|
-
return False
|
|
269
|
-
|
|
270
|
-
def release_http_client(self) -> None:
|
|
271
|
-
"""Releases the HTTP client, allowing it to be used for new requests."""
|
|
272
|
-
self._http_client_busy = False
|
|
273
|
-
|
|
274
|
-
async def init_control(self) -> bool:
|
|
275
|
-
"""
|
|
276
|
-
Initializes the control interface with the printer.
|
|
277
|
-
|
|
278
|
-
This involves sending a product command and initializing TCP control.
|
|
279
|
-
|
|
280
|
-
Returns:
|
|
281
|
-
True if control initialization is successful, False otherwise
|
|
282
|
-
"""
|
|
283
|
-
if await self.send_product_command():
|
|
284
|
-
return await self.tcp_client.init_control()
|
|
285
|
-
logger.warning("New API control failed; the product command was rejected.")
|
|
286
|
-
return False
|
|
287
|
-
|
|
288
|
-
async def dispose(self) -> None:
|
|
289
|
-
"""
|
|
290
|
-
Disposes of the FlashForgeClient instance, stopping keep-alive messages
|
|
291
|
-
and cleaning up resources.
|
|
292
|
-
"""
|
|
293
|
-
# Stop TCP keep-alive and dispose. An HTTP-only client (e.g. Creator 5,
|
|
294
|
-
# which has no TCP/8899 service) never opened a TCP socket, so skip the
|
|
295
|
-
# cleanup handshake -- otherwise the logout send would attempt (and time
|
|
296
|
-
# out on) a connection that was never established.
|
|
297
|
-
if not self._http_only:
|
|
298
|
-
if hasattr(self.tcp_client, "stop_keep_alive"):
|
|
299
|
-
await self.tcp_client.stop_keep_alive(True)
|
|
300
|
-
if hasattr(self.tcp_client, "dispose"):
|
|
301
|
-
await self.tcp_client.dispose()
|
|
302
|
-
|
|
303
|
-
# Close HTTP session
|
|
304
|
-
if self._http_session and not self._http_session.closed:
|
|
305
|
-
await self._http_session.close()
|
|
306
|
-
|
|
307
|
-
self.camera_stream_url = ""
|
|
308
|
-
|
|
309
|
-
async def detect_camera_stream(self, timeout_ms: int = 3000) -> str:
|
|
310
|
-
"""
|
|
311
|
-
Probes the printer's known OEM camera endpoint.
|
|
312
|
-
|
|
313
|
-
Falls back to a short GET when HEAD is unsupported so MJPEG servers
|
|
314
|
-
that reject HEAD requests are still detected.
|
|
315
|
-
|
|
316
|
-
Args:
|
|
317
|
-
timeout_ms: Timeout for each probe attempt in milliseconds.
|
|
318
|
-
|
|
319
|
-
Returns:
|
|
320
|
-
The working camera stream URL, or an empty string if not detected.
|
|
321
|
-
"""
|
|
322
|
-
probe_url = f"http://{self.ip_address}:{CAMERA_STREAM_PORT}/?action=stream"
|
|
323
|
-
timeout = aiohttp.ClientTimeout(total=timeout_ms / 1000)
|
|
324
|
-
|
|
325
|
-
if await self._probe_camera_stream_with_method("head", probe_url, timeout):
|
|
326
|
-
return probe_url
|
|
327
|
-
|
|
328
|
-
if await self._probe_camera_stream_with_method("get", probe_url, timeout):
|
|
329
|
-
return probe_url
|
|
330
|
-
|
|
331
|
-
return ""
|
|
332
|
-
|
|
333
|
-
async def _probe_camera_stream_with_method(
|
|
334
|
-
self,
|
|
335
|
-
method: str,
|
|
336
|
-
probe_url: str,
|
|
337
|
-
timeout: aiohttp.ClientTimeout,
|
|
338
|
-
) -> bool:
|
|
339
|
-
try:
|
|
340
|
-
session = await self._ensure_http_session()
|
|
341
|
-
request = session.head if method == "head" else session.get
|
|
342
|
-
|
|
343
|
-
async with request(probe_url, timeout=timeout) as response:
|
|
344
|
-
return self._is_valid_camera_probe_response(
|
|
345
|
-
response.status, response.headers.get("Content-Type", "")
|
|
346
|
-
)
|
|
347
|
-
except Exception:
|
|
348
|
-
return False
|
|
349
|
-
|
|
350
|
-
@staticmethod
|
|
351
|
-
def _is_valid_camera_probe_response(status: int, content_type: str | None) -> bool:
|
|
352
|
-
if status != 200:
|
|
353
|
-
return False
|
|
354
|
-
|
|
355
|
-
normalized_content_type = (content_type or "").lower()
|
|
356
|
-
return (
|
|
357
|
-
normalized_content_type == ""
|
|
358
|
-
or "multipart" in normalized_content_type
|
|
359
|
-
or "video/x-mjpeg" in normalized_content_type
|
|
360
|
-
)
|
|
361
|
-
|
|
362
|
-
def cache_details(self, info: FFMachineInfo | None) -> bool:
|
|
363
|
-
"""
|
|
364
|
-
Caches machine details from the provided FFMachineInfo object.
|
|
365
|
-
|
|
366
|
-
Args:
|
|
367
|
-
info: The FFMachineInfo object containing printer details
|
|
368
|
-
|
|
369
|
-
Returns:
|
|
370
|
-
True if caching is successful, False otherwise
|
|
371
|
-
"""
|
|
372
|
-
if not info:
|
|
373
|
-
return False
|
|
374
|
-
|
|
375
|
-
# Cache all printer information
|
|
376
|
-
self.printer_name = info.name or ""
|
|
377
|
-
self.is_pro = info.is_pro
|
|
378
|
-
self.firmware_version = info.firmware_version or ""
|
|
379
|
-
self.firmware_ver = info.firmware_version.split("-")[0] if info.firmware_version else ""
|
|
380
|
-
self.mac_address = info.mac_address or ""
|
|
381
|
-
self.flash_cloud_code = info.flash_cloud_register_code or ""
|
|
382
|
-
self.polar_cloud_code = info.polar_cloud_register_code or ""
|
|
383
|
-
self.camera_stream_url = info.camera_stream_url or ""
|
|
384
|
-
self.lifetime_print_time = info.formatted_total_run_time or ""
|
|
385
|
-
self._is_ad5x = info.is_ad5x
|
|
386
|
-
self.is_creator5 = info.is_creator5
|
|
387
|
-
self.is_creator5_pro = info.is_creator5_pro
|
|
388
|
-
# Refresh transport selection now that the model flags are cached.
|
|
389
|
-
self._update_http_only_from_model()
|
|
390
|
-
|
|
391
|
-
# Format filament usage
|
|
392
|
-
filament_value = info.cumulative_filament if info.cumulative_filament is not None else 0.0
|
|
393
|
-
self.lifetime_filament_meters = f"{filament_value:.2f}m"
|
|
394
|
-
self._apply_feature_overrides()
|
|
395
|
-
|
|
396
|
-
return True
|
|
397
|
-
|
|
398
|
-
def get_endpoint(self, endpoint: str) -> str:
|
|
399
|
-
"""
|
|
400
|
-
Constructs the full API endpoint URL.
|
|
401
|
-
|
|
402
|
-
Args:
|
|
403
|
-
endpoint: The specific API endpoint path
|
|
404
|
-
|
|
405
|
-
Returns:
|
|
406
|
-
The full URL for the API endpoint
|
|
407
|
-
"""
|
|
408
|
-
return f"http://{self.ip_address}:{self._PORT}{endpoint}"
|
|
409
|
-
|
|
410
|
-
async def verify_connection(self) -> bool:
|
|
411
|
-
"""
|
|
412
|
-
Verifies the connection to the printer by retrieving machine details and TCP information.
|
|
413
|
-
|
|
414
|
-
Returns:
|
|
415
|
-
True if the connection is verified, False otherwise
|
|
416
|
-
"""
|
|
417
|
-
try:
|
|
418
|
-
# Get HTTP API response
|
|
419
|
-
response = await self.info.get_detail_response()
|
|
420
|
-
if not response or not NetworkUtils.is_ok(response):
|
|
421
|
-
logger.warning("Failed to get a valid response from the printer API.")
|
|
422
|
-
return False
|
|
423
|
-
|
|
424
|
-
# Parse machine info from detail response
|
|
425
|
-
machine_info = MachineInfoParser.from_detail(response.detail)
|
|
426
|
-
if not machine_info:
|
|
427
|
-
logger.warning("Failed to parse machine info from the /detail response.")
|
|
428
|
-
return False
|
|
429
|
-
|
|
430
|
-
# Detect http_only from the parsed model BEFORE touching TCP. The
|
|
431
|
-
# Creator 5 / Creator 5 Pro expose no TCP/8899 service, so the M115
|
|
432
|
-
# handshake would hang until the connect timeout. An explicit
|
|
433
|
-
# override always wins.
|
|
434
|
-
if self._http_only_override is not None:
|
|
435
|
-
self._http_only = bool(self._http_only_override)
|
|
436
|
-
else:
|
|
437
|
-
self._http_only = machine_info.is_creator5
|
|
438
|
-
|
|
439
|
-
# Get TCP printer information to check for Pro model
|
|
440
|
-
tcp_info: PrinterInfo | None = None
|
|
441
|
-
if not self._http_only:
|
|
442
|
-
tcp_info = await self.tcp_client.get_printer_info()
|
|
443
|
-
if tcp_info:
|
|
444
|
-
if (
|
|
445
|
-
"Pro" in tcp_info.type_name
|
|
446
|
-
and not machine_info.is_pro
|
|
447
|
-
and not machine_info.is_ad5x
|
|
448
|
-
):
|
|
449
|
-
self.is_pro = True
|
|
450
|
-
else:
|
|
451
|
-
logger.warning(
|
|
452
|
-
"Unable to get PrinterInfo from the TCP API; some features might "
|
|
453
|
-
"not work."
|
|
454
|
-
)
|
|
455
|
-
|
|
456
|
-
# Cache the details
|
|
457
|
-
return self.cache_details(machine_info)
|
|
458
|
-
|
|
459
|
-
except Exception as error:
|
|
460
|
-
logger.warning("Error in verify_connection: %s", error)
|
|
461
|
-
return False
|
|
462
|
-
|
|
463
|
-
async def send_product_command(self) -> bool:
|
|
464
|
-
"""
|
|
465
|
-
Sends a product command to the printer to retrieve control states.
|
|
466
|
-
|
|
467
|
-
This method holds the command lock while the request is in progress.
|
|
468
|
-
|
|
469
|
-
Returns:
|
|
470
|
-
True if the product command is sent successfully and valid data is received,
|
|
471
|
-
False otherwise
|
|
472
|
-
"""
|
|
473
|
-
payload = {"serialNumber": self.serial_number, "checkCode": self.check_code}
|
|
474
|
-
|
|
475
|
-
try:
|
|
476
|
-
session = await self._ensure_http_session()
|
|
477
|
-
async with self._command_lock:
|
|
478
|
-
async with session.post(
|
|
479
|
-
self.get_endpoint(Endpoints.PRODUCT),
|
|
480
|
-
json=payload,
|
|
481
|
-
headers={"Content-Type": "application/json"},
|
|
482
|
-
) as response:
|
|
483
|
-
if response.status != 200:
|
|
484
|
-
return False
|
|
485
|
-
|
|
486
|
-
data = await json_from_response(response)
|
|
487
|
-
|
|
488
|
-
# Validate response structure
|
|
489
|
-
if not NetworkUtils.is_ok(data):
|
|
490
|
-
return False
|
|
491
|
-
|
|
492
|
-
# Parse product response and set control states
|
|
493
|
-
product_response = ProductResponse(**data)
|
|
494
|
-
if product_response and product_response.product:
|
|
495
|
-
product = product_response.product
|
|
496
|
-
self.product_info = product
|
|
497
|
-
self._detected_led_control = product.lightCtrlState != 0
|
|
498
|
-
self._detected_filtration_control = not (
|
|
499
|
-
product.internalFanCtrlState == 0 or product.externalFanCtrlState == 0
|
|
500
|
-
)
|
|
501
|
-
self._apply_feature_overrides()
|
|
502
|
-
return True
|
|
503
|
-
|
|
504
|
-
except ValidationError as error:
|
|
505
|
-
# Distinct from a rejected check code, and it must not read as one:
|
|
506
|
-
# the printer answered 200 with code 0, we simply could not parse
|
|
507
|
-
# what it said. Callers treat a False return as bad credentials
|
|
508
|
-
# (ff-5mp-hass surfaces it as "check code incorrect"), so the log
|
|
509
|
-
# line is the only place the real cause can surface.
|
|
510
|
-
logger.warning(
|
|
511
|
-
"Could not parse the /product response; reporting the printer as "
|
|
512
|
-
"unavailable rather than the credentials as rejected. This usually "
|
|
513
|
-
"means the firmware added a field this library has not seen. %s",
|
|
514
|
-
error,
|
|
515
|
-
)
|
|
516
|
-
return False
|
|
517
|
-
except Exception as error:
|
|
518
|
-
logger.warning("Error in send_product_command: %s", error)
|
|
519
|
-
return False
|
|
520
|
-
|
|
521
|
-
return False
|
|
522
|
-
|
|
523
|
-
async def get_http_session(self) -> aiohttp.ClientSession:
|
|
524
|
-
"""
|
|
525
|
-
Gets the HTTP session for making requests.
|
|
526
|
-
|
|
527
|
-
Returns:
|
|
528
|
-
The HTTP session instance
|
|
529
|
-
"""
|
|
530
|
-
return await self._ensure_http_session()
|
|
531
|
-
|
|
532
|
-
# Additional convenience methods for direct access to common operations
|
|
533
|
-
|
|
534
|
-
async def get_printer_status(self) -> FFMachineInfo | None:
|
|
535
|
-
"""
|
|
536
|
-
Gets the current printer status and information.
|
|
537
|
-
|
|
538
|
-
Returns:
|
|
539
|
-
FFMachineInfo object with current printer status, or None if failed
|
|
540
|
-
"""
|
|
541
|
-
return await self.info.get()
|
|
542
|
-
|
|
543
|
-
async def get_temperatures(self) -> TempInfo | None:
|
|
544
|
-
"""
|
|
545
|
-
Gets current temperature readings from the printer.
|
|
546
|
-
|
|
547
|
-
Returns:
|
|
548
|
-
Temperature information from the TCP client
|
|
549
|
-
"""
|
|
550
|
-
return await self.tcp_client.get_temp_info()
|
|
551
|
-
|
|
552
|
-
async def home_all_axes(self) -> bool:
|
|
553
|
-
"""
|
|
554
|
-
Homes all axes (X, Y, Z) of the printer.
|
|
555
|
-
|
|
556
|
-
Returns:
|
|
557
|
-
True if successful, False otherwise
|
|
558
|
-
"""
|
|
559
|
-
return await self.control.home_axes()
|
|
560
|
-
|
|
561
|
-
async def emergency_stop(self) -> bool:
|
|
562
|
-
"""
|
|
563
|
-
Performs an emergency stop of the printer.
|
|
564
|
-
|
|
565
|
-
Returns:
|
|
566
|
-
True if successful, False otherwise
|
|
567
|
-
"""
|
|
568
|
-
return await self.job_control.cancel_print_job()
|
|
569
|
-
|
|
570
|
-
async def pause_print(self) -> bool:
|
|
571
|
-
"""
|
|
572
|
-
Pauses the current print job.
|
|
573
|
-
|
|
574
|
-
Returns:
|
|
575
|
-
True if successful, False otherwise
|
|
576
|
-
"""
|
|
577
|
-
return await self.job_control.pause_print_job()
|
|
578
|
-
|
|
579
|
-
async def resume_print(self) -> bool:
|
|
580
|
-
"""
|
|
581
|
-
Resumes a paused print job.
|
|
582
|
-
|
|
583
|
-
Returns:
|
|
584
|
-
True if successful, False otherwise
|
|
585
|
-
"""
|
|
586
|
-
return await self.job_control.resume_print_job()
|
|
587
|
-
|
|
588
|
-
def set_feature_overrides(self, *, led_control: bool | None = None) -> None:
|
|
589
|
-
"""Apply manual feature overrides for integrations that need UI-level capability control."""
|
|
590
|
-
self._led_control_override = led_control
|
|
591
|
-
self._apply_feature_overrides()
|
|
592
|
-
|
|
593
|
-
def _apply_feature_overrides(self) -> None:
|
|
594
|
-
"""Apply any configured manual capability overrides to the cached client state."""
|
|
595
|
-
self.led_control = (
|
|
596
|
-
self._led_control_override
|
|
597
|
-
if self._led_control_override is not None
|
|
598
|
-
else self._detected_led_control
|
|
599
|
-
)
|
|
600
|
-
self.filtration_control = self._detected_filtration_control
|
|
601
|
-
|
|
602
|
-
def __repr__(self) -> str:
|
|
603
|
-
"""String representation of the client."""
|
|
604
|
-
return (
|
|
605
|
-
f"FlashForgeClient(ip={self.ip_address}, "
|
|
606
|
-
f"printer='{self.printer_name}', "
|
|
607
|
-
f"pro={self.is_pro}, "
|
|
608
|
-
f"firmware='{self.firmware_ver}')"
|
|
609
|
-
)
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
flashforge/__init__.py,sha256=HojGIgobrlO5Qr9mzrHhFeuVq5a1otJPDMBa9AFuKBM,5984
|
|
2
|
-
flashforge/client.py,sha256=5DxKJyicq5LX8xfZUtIB0Q-_sh8kIFNzMMV_3Dos5fk,22519
|
|
3
|
-
flashforge/exceptions.py,sha256=LQli1pAH2X8fm3jsRD4caz0Mn-nyBjNpaJh_En7YJw0,1737
|
|
4
|
-
flashforge/api/__init__.py,sha256=vQz-DkG6LTH39bI4fyiUc0D9jQzemLh45pORLptSOlg,335
|
|
5
|
-
flashforge/api/constants/__init__.py,sha256=Q0HL2tqSBYPd4Oz49VHLS3qUvRuv__GCvTGecaLrQ-Y,163
|
|
6
|
-
flashforge/api/constants/commands.py,sha256=9WggRLBgidf4cBBXMllQVAZr64UvHOf7gNHlPEKvo2g,579
|
|
7
|
-
flashforge/api/constants/endpoints.py,sha256=oZtOFfkU64THDeCMUIVv6_0L-BOUZzgLKAUfjHkUhi8,337
|
|
8
|
-
flashforge/api/controls/__init__.py,sha256=53s-H25Pjwr0kvPk8MZ2Twy8VHGqGcO6Q6uBphhEOh4,293
|
|
9
|
-
flashforge/api/controls/control.py,sha256=mK-k3SX53wrq3-aPmMaAbAnqcOaJgvuNSR-sm1aowJM,15099
|
|
10
|
-
flashforge/api/controls/creator5_palette.py,sha256=1I6QfAYlCJcpqPzrySsXfn2EST04QYHZKVxCRnxu4AQ,8795
|
|
11
|
-
flashforge/api/controls/files.py,sha256=tOqPgf9SBIvJBgno1GMAROdoDHF_ZJOmbEac1ikq_HI,8769
|
|
12
|
-
flashforge/api/controls/info.py,sha256=E-VepEeTyquh50ssckpMGIkH9cagNZGUzn_Zb-bPplY,24846
|
|
13
|
-
flashforge/api/controls/job_control.py,sha256=-6UafeTpjYOs5gIVAHbQyTUROErJs4XW8lpI6HsLJgM,36119
|
|
14
|
-
flashforge/api/controls/temp_control.py,sha256=_qrKCfjKJsPE4dj6bXZeJRH2FjLKx2T2V3pyG2oLrgI,12991
|
|
15
|
-
flashforge/api/filament/__init__.py,sha256=isT2dl0hzUS0xMTXMm4Tip0GTG1gCsm8LKWa9xPu4Y8,104
|
|
16
|
-
flashforge/api/filament/filament.py,sha256=TtcC2G2nD9Sq4cOrCZzFLZ6Q0Ve-zfrfuEF9uQ8M3eE,1214
|
|
17
|
-
flashforge/api/misc/__init__.py,sha256=1AG7vOMRBZQtHp6QUzfr9alcJPeNv3JpU44NrznxDHs,211
|
|
18
|
-
flashforge/api/misc/redaction.py,sha256=8LG2WsFXhdBqbZ4AXYwpm8hQ_PxaOeAKmZBeG5kzAT4,2675
|
|
19
|
-
flashforge/api/misc/scientific_notation.py,sha256=KSMTrrYhPWLv0gbcEAD6u-jEOcIwUjOCOPMBi0LiO-k,826
|
|
20
|
-
flashforge/api/misc/temperature.py,sha256=qeHlCdPzLyqGDEB874Ib5AgYHMR9Qtw61shnw4G095E,1066
|
|
21
|
-
flashforge/api/network/__init__.py,sha256=G5fBoAlq-NQPDkWp579mFIqsj0v7B1Lb2TAzO6IZA0Q,164
|
|
22
|
-
flashforge/api/network/fnet_code.py,sha256=BR2niVKKk4ZfXtizUDIMXzDhlCxPHzqWg5AQQIcoj3g,402
|
|
23
|
-
flashforge/api/network/utils.py,sha256=Q5-Vj_1VN611QV_TGpDzrrZ2X8PqaGT0j00BhSHv5MM,2096
|
|
24
|
-
flashforge/discovery/__init__.py,sha256=G0WiP70EhfHdjXR1RNlv6xjhyHOdo-HWyOm9J0ds4SM,828
|
|
25
|
-
flashforge/discovery/discovery.py,sha256=-hOmVIpn8gu-rPYo8FRBfhKb_tBqwamLfmoPVYaDzLI,27614
|
|
26
|
-
flashforge/models/__init__.py,sha256=hdcK0E4KeDfv_A8Y2aPOHgHziwTjP1RPb_VP-89dOzQ,1086
|
|
27
|
-
flashforge/models/machine_info.py,sha256=Chcpoeus1pppPKMDNsGIiCGGQ6tATezUT6ML5MjubD0,24407
|
|
28
|
-
flashforge/models/responses.py,sha256=P0Zo8c6QywbS0_kEWq-8HsRwwQkCiG4MfeDcGADpPHg,10965
|
|
29
|
-
flashforge/tcp/__init__.py,sha256=hpnqoWHeRtTwJPzdsVlwGt1njKbAkrgIHKADkLSIRec,1317
|
|
30
|
-
flashforge/tcp/a3_client.py,sha256=Aqb6MuKkjnNUVdE2LbZKd7bPlFK8XPIm17C_BG_PuNU,15867
|
|
31
|
-
flashforge/tcp/a4_client.py,sha256=snmAvTCpSWFjxb8h6V7H4tk5yOoMqKEzKoBY_1JaaPs,11213
|
|
32
|
-
flashforge/tcp/ff_client.py,sha256=CJXk0Qei2FVSpbXxZhiEQgAEcTJaBab1ouooqyC4OL4,20235
|
|
33
|
-
flashforge/tcp/tcp_client.py,sha256=Ae5Z5rLJFoDYxP3T6Q_PtVNkUr94QqFEWPKtgFyMIJw,17027
|
|
34
|
-
flashforge/tcp/gcode/__init__.py,sha256=tFGlqCPFxVJNizXsIG4pMOK7IPFNnc_vIEMciULYkMY,271
|
|
35
|
-
flashforge/tcp/gcode/a3_gcode_controller.py,sha256=x84_xo_Ll5k6hMAwDWuNUo54znV-BBIfwnmeOiEa9Fs,3688
|
|
36
|
-
flashforge/tcp/gcode/gcode_controller.py,sha256=6K1VGgX59AcE_Kh_gm13dmxCY_kuzV_d2ooSpheONRI,10075
|
|
37
|
-
flashforge/tcp/gcode/gcodes.py,sha256=55Ii1JpJNJNmOnBivyF83vz3TZUPDtp01lX72NINfPQ,3658
|
|
38
|
-
flashforge/tcp/parsers/__init__.py,sha256=kDaJmiH0JcR5i693Fj3pwmINLWN0ipirN3LWGFvPst0,730
|
|
39
|
-
flashforge/tcp/parsers/endstop_status.py,sha256=k7C5P_TiKlqBxSq2ybRoBDaaDcQ_EgiZe2NLYo7ubiE,9902
|
|
40
|
-
flashforge/tcp/parsers/location_info.py,sha256=0fbqCmQ2EQQe8z9fiX0zP1YsnuVayTs81zmF3_HuGZM,2895
|
|
41
|
-
flashforge/tcp/parsers/print_status.py,sha256=C-KzukhK0TR86AP3t3XrMH4dief6pa3I-yiST4rL0mk,6271
|
|
42
|
-
flashforge/tcp/parsers/printer_info.py,sha256=CHPs6nJfEByXyG3co7Nb8_ygggxkYuc7A9O9bpQEqXE,5441
|
|
43
|
-
flashforge/tcp/parsers/temp_info.py,sha256=9wRGUM9cKvDiZD3SIxBx_qVLZbeXoYsoY3-R3vN3H4g,7938
|
|
44
|
-
flashforge/tcp/parsers/thumbnail_info.py,sha256=1U1S_gcIZ2lDpEA4622ywUew6TVw0BnzjlBAiihQwzk,10478
|
|
45
|
-
flashforge/threemf/__init__.py,sha256=xjoHiyl-RFvzMCGeZ00K197d01ZO7-j2o15Xy0ns96Y,900
|
|
46
|
-
flashforge/threemf/parser.py,sha256=mr-FJ2_Zs__VcBwPZvQXUPtBEuKUB-2fcMMaKOQYYOE,20987
|
|
47
|
-
flashforge/threemf/warnings.py,sha256=-8o7VhdaXqaOpx4ZH-A5kYybWJZepqRxmScVV3d-UzA,2472
|
|
48
|
-
flashforge_python_api-1.6.0.dist-info/METADATA,sha256=22juPUjzsx7czIfPWSgH13A846vO1Mf09_IMtibg7cw,6619
|
|
49
|
-
flashforge_python_api-1.6.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
50
|
-
flashforge_python_api-1.6.0.dist-info/entry_points.txt,sha256=AkOxlsLvQ7cvMLxn7tlzfKp_DCH2hXhbVceHIXxawpU,66
|
|
51
|
-
flashforge_python_api-1.6.0.dist-info/licenses/LICENSE,sha256=-cTA-hrmvlb3pqlQrBZQXUnKayhUjsLJMPb7TD91frM,1067
|
|
52
|
-
flashforge_python_api-1.6.0.dist-info/RECORD,,
|
{flashforge_python_api-1.6.0.dist-info → flashforge_python_api-3.0.0.dist-info}/entry_points.txt
RENAMED
|
File without changes
|