flashforge-python-api 1.6.0__py3-none-any.whl → 3.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- flashforge/__init__.py +137 -56
- flashforge/_removed.py +65 -0
- flashforge/api/__init__.py +12 -18
- flashforge/api/constants/__init__.py +11 -11
- flashforge/api/constants/commands.py +18 -15
- flashforge/api/constants/endpoints.py +11 -11
- flashforge/api/misc/__init__.py +8 -8
- flashforge/api/network/__init__.py +11 -11
- flashforge/api/network/utils.py +71 -71
- flashforge/backends/__init__.py +80 -0
- flashforge/backends/connect.py +275 -0
- flashforge/backends/creator5_backend.py +191 -0
- flashforge/backends/dual_api_backend.py +170 -0
- flashforge/backends/dual_api_models.py +145 -0
- flashforge/backends/http_core.py +431 -0
- flashforge/backends/http_printer_backend.py +254 -0
- flashforge/backends/legacy_backend.py +436 -0
- flashforge/backends/printer_backend.py +217 -0
- flashforge/backends/types.py +125 -0
- flashforge/capabilities/__init__.py +98 -0
- flashforge/capabilities/models.py +67 -0
- flashforge/capabilities/palettes/__init__.py +28 -0
- flashforge/capabilities/palettes/ad5x_palette.py +70 -0
- flashforge/capabilities/palettes/creator5_palette.py +78 -0
- flashforge/capabilities/palettes/palette.py +54 -0
- flashforge/{api/controls/creator5_palette.py → capabilities/palettes/palette_snap.py} +226 -258
- flashforge/capabilities/printer_capabilities.py +145 -0
- flashforge/capabilities/registry.py +125 -0
- flashforge/capabilities/resolve_model.py +61 -0
- flashforge/discovery/__init__.py +39 -39
- flashforge/discovery/discovery.py +150 -77
- flashforge/exceptions.py +90 -51
- flashforge/models/__init__.py +52 -55
- flashforge/models/machine_info.py +540 -543
- flashforge/{api/controls/info.py → models/machine_info_parser.py} +35 -242
- flashforge/models/responses.py +119 -254
- flashforge/status/__init__.py +43 -0
- flashforge/status/printer_snapshot.py +396 -0
- flashforge/tcp/__init__.py +55 -54
- flashforge/tcp/a3_client.py +427 -427
- flashforge/tcp/a4_client.py +304 -304
- flashforge/tcp/ff_client.py +609 -590
- flashforge/tcp/gcode/__init__.py +15 -13
- flashforge/tcp/gcode/a3_gcode_controller.py +109 -109
- flashforge/tcp/gcode/gcode_controller.py +292 -308
- flashforge/tcp/gcode/gcodes.py +81 -99
- flashforge/tcp/gcode/legacy_gcode_controller.py +56 -0
- flashforge/tcp/parsers/__init__.py +27 -27
- flashforge/tcp/parsers/endstop_status.py +248 -248
- flashforge/tcp/parsers/location_info.py +83 -83
- flashforge/tcp/parsers/print_status.py +180 -180
- flashforge/tcp/parsers/printer_info.py +146 -146
- flashforge/tcp/parsers/temp_info.py +218 -218
- flashforge/tcp/parsers/thumbnail_info.py +274 -274
- flashforge/tcp/tcp_client.py +52 -12
- flashforge/threemf/__init__.py +40 -40
- flashforge/threemf/parser.py +560 -560
- flashforge/threemf/warnings.py +58 -58
- {flashforge_python_api-1.6.0.dist-info → flashforge_python_api-3.1.0.dist-info}/METADATA +46 -47
- flashforge_python_api-3.1.0.dist-info/RECORD +69 -0
- {flashforge_python_api-1.6.0.dist-info → flashforge_python_api-3.1.0.dist-info}/WHEEL +1 -1
- {flashforge_python_api-1.6.0.dist-info → flashforge_python_api-3.1.0.dist-info}/licenses/LICENSE +21 -21
- flashforge/api/controls/__init__.py +0 -17
- flashforge/api/controls/control.py +0 -413
- flashforge/api/controls/files.py +0 -210
- flashforge/api/controls/job_control.py +0 -896
- flashforge/api/controls/temp_control.py +0 -309
- flashforge/client.py +0 -609
- flashforge_python_api-1.6.0.dist-info/RECORD +0 -52
- {flashforge_python_api-1.6.0.dist-info → flashforge_python_api-3.1.0.dist-info}/entry_points.txt +0 -0
flashforge/__init__.py
CHANGED
|
@@ -1,33 +1,22 @@
|
|
|
1
1
|
"""
|
|
2
2
|
FlashForge Python API
|
|
3
3
|
|
|
4
|
-
A Python library for controlling FlashForge 3D printers
|
|
5
|
-
|
|
6
|
-
temperature control, and real-time communication.
|
|
4
|
+
A Python library for controlling FlashForge 3D printers over their HTTP and TCP APIs.
|
|
5
|
+
Each printer family has its own backend; :func:`connect_printer` picks the right one.
|
|
7
6
|
|
|
8
7
|
Example:
|
|
9
|
-
Basic usage example:
|
|
10
|
-
|
|
11
8
|
```python
|
|
12
9
|
import asyncio
|
|
13
|
-
from flashforge import
|
|
10
|
+
from flashforge import ConnectOptions, ConnectTarget, PrinterDiscovery, connect_printer
|
|
14
11
|
|
|
15
12
|
async def main():
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
# Control operations
|
|
25
|
-
await client.control.set_led_on()
|
|
26
|
-
await client.control.home_axes()
|
|
27
|
-
|
|
28
|
-
# Temperature monitoring
|
|
29
|
-
temps = await client.get_temperatures()
|
|
30
|
-
print(f"Extruder: {temps.extruder_temp}°C")
|
|
13
|
+
printers = await PrinterDiscovery().discover()
|
|
14
|
+
backend = await connect_printer(printers[0], ConnectOptions(check_code="12345678"))
|
|
15
|
+
async with backend:
|
|
16
|
+
status = await backend.get_status()
|
|
17
|
+
print(status.state, status.temperatures.extruder.current)
|
|
18
|
+
if backend.capabilities.led.controllable:
|
|
19
|
+
await backend.set_led(True)
|
|
31
20
|
|
|
32
21
|
asyncio.run(main())
|
|
33
22
|
```
|
|
@@ -35,15 +24,6 @@ Example:
|
|
|
35
24
|
|
|
36
25
|
from .api.constants.commands import Commands
|
|
37
26
|
from .api.constants.endpoints import Endpoints
|
|
38
|
-
|
|
39
|
-
# Import control classes for advanced usage
|
|
40
|
-
from .api.controls import (
|
|
41
|
-
Control,
|
|
42
|
-
Files,
|
|
43
|
-
Info,
|
|
44
|
-
JobControl,
|
|
45
|
-
TempControl,
|
|
46
|
-
)
|
|
47
27
|
from .api.filament import Filament
|
|
48
28
|
from .api.misc import Temperature as TempWrapper
|
|
49
29
|
from .api.misc import format_scientific_notation
|
|
@@ -51,7 +31,49 @@ from .api.network.fnet_code import FNetCode
|
|
|
51
31
|
|
|
52
32
|
# Import utility classes
|
|
53
33
|
from .api.network.utils import NetworkUtils
|
|
54
|
-
from .
|
|
34
|
+
from .backends import (
|
|
35
|
+
AD5XBackend,
|
|
36
|
+
Adventurer5MBackend,
|
|
37
|
+
Adventurer5MProBackend,
|
|
38
|
+
ConnectOptions,
|
|
39
|
+
ConnectTarget,
|
|
40
|
+
Creator5Backend,
|
|
41
|
+
DualApiBackend,
|
|
42
|
+
FiltrationMode,
|
|
43
|
+
HttpCore,
|
|
44
|
+
HttpPrinterBackend,
|
|
45
|
+
LegacyBackend,
|
|
46
|
+
LocalJobParams,
|
|
47
|
+
MaterialMapping,
|
|
48
|
+
PrinterBackend,
|
|
49
|
+
PrinterIdentity,
|
|
50
|
+
PrintOverrides,
|
|
51
|
+
SlotAction,
|
|
52
|
+
UploadJobParams,
|
|
53
|
+
connect_printer,
|
|
54
|
+
)
|
|
55
|
+
from .capabilities import (
|
|
56
|
+
AD5X_FILAMENT_PALETTE,
|
|
57
|
+
AD5X_MATERIALS,
|
|
58
|
+
AD5X_PALETTE,
|
|
59
|
+
CREATOR5_FILAMENT_PALETTE,
|
|
60
|
+
CREATOR5_MATERIALS,
|
|
61
|
+
CREATOR5_PALETTE,
|
|
62
|
+
BackendFamily,
|
|
63
|
+
FeatureSupport,
|
|
64
|
+
LedSupport,
|
|
65
|
+
MaterialStationSupport,
|
|
66
|
+
Palette,
|
|
67
|
+
PaletteColor,
|
|
68
|
+
PrinterCapabilities,
|
|
69
|
+
get_model_palette,
|
|
70
|
+
get_palette_for_model,
|
|
71
|
+
resolve_capabilities,
|
|
72
|
+
resolve_model,
|
|
73
|
+
snap_to_ad5x_palette,
|
|
74
|
+
snap_to_creator5_palette,
|
|
75
|
+
snap_to_model_palette,
|
|
76
|
+
)
|
|
55
77
|
|
|
56
78
|
# Import discovery classes
|
|
57
79
|
from .discovery import (
|
|
@@ -65,18 +87,20 @@ from .discovery import (
|
|
|
65
87
|
FlashForgePrinterDiscovery,
|
|
66
88
|
InvalidResponseError,
|
|
67
89
|
PrinterDiscovery,
|
|
68
|
-
|
|
90
|
+
PrinterModelId,
|
|
69
91
|
PrinterStatus,
|
|
70
92
|
SocketCreationError,
|
|
71
93
|
)
|
|
72
|
-
from .exceptions import
|
|
94
|
+
from .exceptions import (
|
|
95
|
+
FlashForgeError,
|
|
96
|
+
FlashForgeResponseError,
|
|
97
|
+
InvalidParameterError,
|
|
98
|
+
NotSupportedError,
|
|
99
|
+
PrinterConnectionError,
|
|
100
|
+
)
|
|
73
101
|
|
|
74
102
|
# Import key models for convenience
|
|
75
103
|
from .models import (
|
|
76
|
-
AD5XLocalJobParams,
|
|
77
|
-
AD5XMaterialMapping,
|
|
78
|
-
AD5XSingleColorJobParams,
|
|
79
|
-
AD5XUploadParams,
|
|
80
104
|
DetailResponse,
|
|
81
105
|
FFGcodeFileEntry,
|
|
82
106
|
FFGcodeToolData,
|
|
@@ -86,6 +110,7 @@ from .models import (
|
|
|
86
110
|
GCodeListResponse,
|
|
87
111
|
GenericResponse,
|
|
88
112
|
IndepMatlInfo,
|
|
113
|
+
MachineInfoParser,
|
|
89
114
|
MachineState,
|
|
90
115
|
MatlStationInfo,
|
|
91
116
|
Product,
|
|
@@ -94,6 +119,17 @@ from .models import (
|
|
|
94
119
|
Temperature,
|
|
95
120
|
ThumbnailResponse,
|
|
96
121
|
)
|
|
122
|
+
|
|
123
|
+
# Sliced 3MF parsing (tools and materials before upload)
|
|
124
|
+
from .status import (
|
|
125
|
+
JobProgress,
|
|
126
|
+
JobSnapshot,
|
|
127
|
+
MaterialSlotSnapshot,
|
|
128
|
+
MaterialStationSnapshot,
|
|
129
|
+
PrinterRunState,
|
|
130
|
+
PrinterSnapshot,
|
|
131
|
+
TemperatureReading,
|
|
132
|
+
)
|
|
97
133
|
from .tcp import (
|
|
98
134
|
A3BuildVolume,
|
|
99
135
|
A3FileEntry,
|
|
@@ -111,6 +147,7 @@ from .tcp import (
|
|
|
111
147
|
FlashForgeTcpClientOptions,
|
|
112
148
|
GCodeController,
|
|
113
149
|
GCodes,
|
|
150
|
+
LegacyGCodeController,
|
|
114
151
|
LocationInfo,
|
|
115
152
|
MachineStatus,
|
|
116
153
|
MoveMode,
|
|
@@ -126,8 +163,6 @@ from .tcp import (
|
|
|
126
163
|
from .tcp import (
|
|
127
164
|
FlashForgeTcpClient as TcpClient,
|
|
128
165
|
)
|
|
129
|
-
|
|
130
|
-
# Sliced 3MF parsing (tools and materials before upload)
|
|
131
166
|
from .threemf import (
|
|
132
167
|
PrinterFamily,
|
|
133
168
|
ThreeMFError,
|
|
@@ -140,24 +175,73 @@ from .threemf import (
|
|
|
140
175
|
parse_3mf,
|
|
141
176
|
)
|
|
142
177
|
|
|
143
|
-
|
|
144
|
-
__version__ = "1.6.0"
|
|
178
|
+
__version__ = "3.1.0"
|
|
145
179
|
__author__ = "FlashForge Python API Contributors"
|
|
146
180
|
__email__ = "notghosttypes@gmail.com"
|
|
147
181
|
__description__ = "Python library for controlling FlashForge 3D printers"
|
|
148
182
|
|
|
149
183
|
# Public API - Main classes most users will need
|
|
150
184
|
__all__ = [
|
|
151
|
-
#
|
|
152
|
-
"
|
|
153
|
-
"
|
|
154
|
-
"
|
|
185
|
+
# Backends and the connect factory
|
|
186
|
+
"connect_printer",
|
|
187
|
+
"ConnectOptions",
|
|
188
|
+
"ConnectTarget",
|
|
189
|
+
"PrinterBackend",
|
|
190
|
+
"PrinterIdentity",
|
|
191
|
+
"HttpCore",
|
|
192
|
+
"HttpPrinterBackend",
|
|
193
|
+
"DualApiBackend",
|
|
194
|
+
"Adventurer5MBackend",
|
|
195
|
+
"Adventurer5MProBackend",
|
|
196
|
+
"AD5XBackend",
|
|
197
|
+
"Creator5Backend",
|
|
198
|
+
"LegacyBackend",
|
|
199
|
+
"UploadJobParams",
|
|
200
|
+
"LocalJobParams",
|
|
201
|
+
"MaterialMapping",
|
|
202
|
+
"PrintOverrides",
|
|
203
|
+
"FiltrationMode",
|
|
204
|
+
"SlotAction",
|
|
205
|
+
# Capabilities and palettes
|
|
206
|
+
"BackendFamily",
|
|
207
|
+
"FeatureSupport",
|
|
208
|
+
"LedSupport",
|
|
209
|
+
"MaterialStationSupport",
|
|
210
|
+
"PrinterCapabilities",
|
|
211
|
+
"PrinterModelId",
|
|
212
|
+
"resolve_capabilities",
|
|
213
|
+
"resolve_model",
|
|
214
|
+
"PaletteColor",
|
|
215
|
+
"AD5X_PALETTE",
|
|
216
|
+
"AD5X_MATERIALS",
|
|
217
|
+
"CREATOR5_PALETTE",
|
|
218
|
+
"CREATOR5_MATERIALS",
|
|
219
|
+
"AD5X_FILAMENT_PALETTE",
|
|
220
|
+
"CREATOR5_FILAMENT_PALETTE",
|
|
221
|
+
"Palette",
|
|
222
|
+
"get_model_palette",
|
|
223
|
+
"get_palette_for_model",
|
|
224
|
+
"snap_to_model_palette",
|
|
225
|
+
"snap_to_ad5x_palette",
|
|
226
|
+
"snap_to_creator5_palette",
|
|
227
|
+
# Status model
|
|
228
|
+
"PrinterSnapshot",
|
|
229
|
+
"PrinterRunState",
|
|
230
|
+
"TemperatureReading",
|
|
231
|
+
"JobSnapshot",
|
|
232
|
+
"JobProgress",
|
|
233
|
+
"MaterialStationSnapshot",
|
|
234
|
+
"MaterialSlotSnapshot",
|
|
155
235
|
# Exceptions
|
|
156
236
|
"FlashForgeError",
|
|
157
237
|
"FlashForgeResponseError",
|
|
238
|
+
"NotSupportedError",
|
|
239
|
+
"InvalidParameterError",
|
|
240
|
+
"PrinterConnectionError",
|
|
158
241
|
# Data models
|
|
159
242
|
"FFMachineInfo",
|
|
160
243
|
"FFPrinterDetail",
|
|
244
|
+
"MachineInfoParser",
|
|
161
245
|
"FFGcodeFileEntry",
|
|
162
246
|
"FFGcodeToolData",
|
|
163
247
|
"MachineState",
|
|
@@ -171,10 +255,6 @@ __all__ = [
|
|
|
171
255
|
"SlotInfo",
|
|
172
256
|
"MatlStationInfo",
|
|
173
257
|
"IndepMatlInfo",
|
|
174
|
-
"AD5XMaterialMapping",
|
|
175
|
-
"AD5XLocalJobParams",
|
|
176
|
-
"AD5XSingleColorJobParams",
|
|
177
|
-
"AD5XUploadParams",
|
|
178
258
|
"GCodeListResponse",
|
|
179
259
|
"ThumbnailResponse",
|
|
180
260
|
# Sliced 3MF parsing
|
|
@@ -187,12 +267,6 @@ __all__ = [
|
|
|
187
267
|
"ThreeMFMultiplePlatesError",
|
|
188
268
|
"ThreeMFNotSlicedError",
|
|
189
269
|
"ThreeMFWarning",
|
|
190
|
-
# Control classes for advanced usage
|
|
191
|
-
"Control",
|
|
192
|
-
"JobControl",
|
|
193
|
-
"Info",
|
|
194
|
-
"Files",
|
|
195
|
-
"TempControl",
|
|
196
270
|
# TCP classes for low-level operations
|
|
197
271
|
"TcpClient",
|
|
198
272
|
"FlashForgeTcpClient",
|
|
@@ -213,6 +287,7 @@ __all__ = [
|
|
|
213
287
|
"GCodes",
|
|
214
288
|
"GCodeController",
|
|
215
289
|
"A3GCodeController",
|
|
290
|
+
"LegacyGCodeController",
|
|
216
291
|
"A3BuildVolume",
|
|
217
292
|
"A3PrinterInfo",
|
|
218
293
|
"A3FileEntry",
|
|
@@ -224,7 +299,6 @@ __all__ = [
|
|
|
224
299
|
"PrinterDiscovery",
|
|
225
300
|
"DiscoveredPrinter",
|
|
226
301
|
"DiscoveryOptions",
|
|
227
|
-
"PrinterModel",
|
|
228
302
|
"DiscoveryProtocol",
|
|
229
303
|
"PrinterStatus",
|
|
230
304
|
"DiscoveryMonitor",
|
|
@@ -254,3 +328,10 @@ State = MachineState
|
|
|
254
328
|
|
|
255
329
|
# Add version info accessible as flashforge.version
|
|
256
330
|
version = __version__
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
def __getattr__(name: str) -> object:
|
|
334
|
+
"""Raise a clear error for names removed in 3.0 (see ``flashforge._removed``)."""
|
|
335
|
+
from ._removed import REMOVED_TOP_LEVEL, module_getattr
|
|
336
|
+
|
|
337
|
+
return module_getattr(__name__, REMOVED_TOP_LEVEL, name)
|
flashforge/_removed.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Clear errors for names that were removed in 3.0.
|
|
2
|
+
|
|
3
|
+
Code written for 1.x (for example an old Home Assistant integration) imports names
|
|
4
|
+
such as ``FlashForgeClient``. Without this module, Python only says
|
|
5
|
+
"cannot import name". The module ``__getattr__`` hooks in ``flashforge`` and
|
|
6
|
+
``flashforge.models`` raise :class:`RemovedInVersion3Error` instead, with the
|
|
7
|
+
replacement and the migration links.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
MIGRATION_GUIDE_URL = "https://gitlab.com/GhostTypes/ff-5mp-api-py/-/blob/main/CHANGELOG.md"
|
|
13
|
+
HASS_REPOSITORY_URL = "https://github.com/Parallel-7/ff-5mp-hass"
|
|
14
|
+
|
|
15
|
+
_CONNECT = "connect_printer()"
|
|
16
|
+
|
|
17
|
+
# name -> replacement, per module that exported it in 1.x.
|
|
18
|
+
REMOVED_TOP_LEVEL: dict[str, str] = {
|
|
19
|
+
"FlashForgeClient": _CONNECT,
|
|
20
|
+
"FiveMClient": _CONNECT,
|
|
21
|
+
"FiveMClientConnectionOptions": "ConnectOptions with connect_printer()",
|
|
22
|
+
"Control": "the methods of the backend that connect_printer() returns",
|
|
23
|
+
"JobControl": "the methods of the backend that connect_printer() returns",
|
|
24
|
+
"TempControl": "the methods of the backend that connect_printer() returns",
|
|
25
|
+
"Files": "the methods of the backend that connect_printer() returns",
|
|
26
|
+
"Info": "backend.get_machine_info() or backend.get_status()",
|
|
27
|
+
"PrinterModel": "PrinterModelId (DiscoveredPrinter.model)",
|
|
28
|
+
"AD5XUploadParams": "UploadJobParams",
|
|
29
|
+
"AD5XLocalJobParams": "LocalJobParams",
|
|
30
|
+
"AD5XSingleColorJobParams": "LocalJobParams",
|
|
31
|
+
"AD5XMaterialMapping": "MaterialMapping",
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
REMOVED_MODELS: dict[str, str] = {
|
|
35
|
+
"AD5XUploadParams": "flashforge.UploadJobParams",
|
|
36
|
+
"AD5XLocalJobParams": "flashforge.LocalJobParams",
|
|
37
|
+
"AD5XSingleColorJobParams": "flashforge.LocalJobParams",
|
|
38
|
+
"AD5XMaterialMapping": "flashforge.MaterialMapping",
|
|
39
|
+
"Creator5UploadParams": "flashforge.UploadJobParams",
|
|
40
|
+
"Creator5JobParams": "flashforge.LocalJobParams",
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class RemovedInVersion3Error(ImportError):
|
|
45
|
+
"""A name that existed in flashforge-python-api 1.x was removed in 3.0."""
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def removed_name_error(module: str, name: str, replacement: str) -> RemovedInVersion3Error:
|
|
49
|
+
"""Build the error for ``from <module> import <name>``."""
|
|
50
|
+
message = (
|
|
51
|
+
f"'{name}' was removed in flashforge-python-api 3.0. Use {replacement} instead. "
|
|
52
|
+
f"Migration notes: {MIGRATION_GUIDE_URL}\n"
|
|
53
|
+
"Home Assistant users: the FlashForge integration moved. In HACS, remove the old "
|
|
54
|
+
f"GhostTypes repository, add {HASS_REPOSITORY_URL} and update to 1.6.2 or later. "
|
|
55
|
+
"To keep an older integration working, install flashforge-python-api<2.0."
|
|
56
|
+
)
|
|
57
|
+
return RemovedInVersion3Error(message, name=name)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def module_getattr(module: str, table: dict[str, str], name: str) -> object:
|
|
61
|
+
"""Shared body of the module ``__getattr__`` hooks."""
|
|
62
|
+
replacement = table.get(name)
|
|
63
|
+
if replacement is not None:
|
|
64
|
+
raise removed_name_error(module, name, replacement)
|
|
65
|
+
raise AttributeError(f"module '{module}' has no attribute '{name}'")
|
flashforge/api/__init__.py
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
"""
|
|
2
|
-
FlashForge Python API - API Package
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from .constants import Commands, Endpoints
|
|
6
|
-
from .
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
"Files",
|
|
14
|
-
"Info",
|
|
15
|
-
"JobControl",
|
|
16
|
-
"TempControl",
|
|
17
|
-
"NetworkUtils",
|
|
18
|
-
]
|
|
1
|
+
"""
|
|
2
|
+
FlashForge Python API - API Package (HTTP constants and network helpers).
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from .constants import Commands, Endpoints
|
|
6
|
+
from .network import NetworkUtils
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"Commands",
|
|
10
|
+
"Endpoints",
|
|
11
|
+
"NetworkUtils",
|
|
12
|
+
]
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"""
|
|
2
|
-
FlashForge Python API - Constants Package
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from .commands import Commands
|
|
6
|
-
from .endpoints import Endpoints
|
|
7
|
-
|
|
8
|
-
__all__ = [
|
|
9
|
-
"Commands",
|
|
10
|
-
"Endpoints",
|
|
11
|
-
]
|
|
1
|
+
"""
|
|
2
|
+
FlashForge Python API - Constants Package
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from .commands import Commands
|
|
6
|
+
from .endpoints import Endpoints
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"Commands",
|
|
10
|
+
"Endpoints",
|
|
11
|
+
]
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
class Commands:
|
|
2
|
-
"""
|
|
3
|
-
Commands used in the "new" HTTP API
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
LIGHT_CONTROL_CMD = "lightControl_cmd"
|
|
7
|
-
PRINTER_CONTROL_CMD = "printerCtl_cmd"
|
|
8
|
-
JOB_CONTROL_CMD = "jobCtl_cmd"
|
|
9
|
-
CIRCULATION_CONTROL_CMD = "circulateCtl_cmd"
|
|
10
|
-
CAMERA_CONTROL_CMD = "streamCtrl_cmd"
|
|
11
|
-
TEMP_CONTROL_CMD = "temperatureCtl_cmd"
|
|
12
|
-
# AD5X + Creator 5 material-station slot metadata (name + color). Filament
|
|
13
|
-
# load/unload (`ms_cmd`) stays AD5X-only — the Creator 5 firmware has no
|
|
14
|
-
# `ms_cmd` (verified in the firmware).
|
|
15
|
-
MATERIAL_STATION_CONFIG_CMD = "msConfig_cmd"
|
|
1
|
+
class Commands:
|
|
2
|
+
"""
|
|
3
|
+
Commands used in the "new" HTTP API
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
LIGHT_CONTROL_CMD = "lightControl_cmd"
|
|
7
|
+
PRINTER_CONTROL_CMD = "printerCtl_cmd"
|
|
8
|
+
JOB_CONTROL_CMD = "jobCtl_cmd"
|
|
9
|
+
CIRCULATION_CONTROL_CMD = "circulateCtl_cmd"
|
|
10
|
+
CAMERA_CONTROL_CMD = "streamCtrl_cmd"
|
|
11
|
+
TEMP_CONTROL_CMD = "temperatureCtl_cmd"
|
|
12
|
+
# AD5X + Creator 5 material-station slot metadata (name + color). Filament
|
|
13
|
+
# load/unload (`ms_cmd`) stays AD5X-only — the Creator 5 firmware has no
|
|
14
|
+
# `ms_cmd` (verified in the firmware).
|
|
15
|
+
MATERIAL_STATION_CONFIG_CMD = "msConfig_cmd"
|
|
16
|
+
# AD5X filament load / unload / cancel on a material-station slot.
|
|
17
|
+
MATERIAL_STATION_CMD = "ms_cmd"
|
|
18
|
+
STATE_CONTROL_CMD = "stateCtrl_cmd"
|
|
@@ -4,14 +4,14 @@ CAMERA_STREAM_PORT: Final[int] = 8080
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
class Endpoints:
|
|
7
|
-
"""
|
|
8
|
-
Endpoints for the "new" HTTP API
|
|
9
|
-
"""
|
|
10
|
-
|
|
11
|
-
CONTROL = "/control"
|
|
12
|
-
DETAIL = "/detail"
|
|
13
|
-
GCODE_LIST = "/gcodeList"
|
|
14
|
-
GCODE_PRINT = "/printGcode"
|
|
15
|
-
GCODE_THUMB = "/gcodeThumb"
|
|
16
|
-
PRODUCT = "/product"
|
|
17
|
-
UPLOAD_FILE = "/uploadGcode"
|
|
7
|
+
"""
|
|
8
|
+
Endpoints for the "new" HTTP API
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
CONTROL = "/control"
|
|
12
|
+
DETAIL = "/detail"
|
|
13
|
+
GCODE_LIST = "/gcodeList"
|
|
14
|
+
GCODE_PRINT = "/printGcode"
|
|
15
|
+
GCODE_THUMB = "/gcodeThumb"
|
|
16
|
+
PRODUCT = "/product"
|
|
17
|
+
UPLOAD_FILE = "/uploadGcode"
|
flashforge/api/misc/__init__.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"""
|
|
2
|
-
FlashForge Python API - Miscellaneous Utilities
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from .scientific_notation import format_scientific_notation
|
|
6
|
-
from .temperature import Temperature
|
|
7
|
-
|
|
8
|
-
__all__ = ["Temperature", "format_scientific_notation"]
|
|
1
|
+
"""
|
|
2
|
+
FlashForge Python API - Miscellaneous Utilities
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from .scientific_notation import format_scientific_notation
|
|
6
|
+
from .temperature import Temperature
|
|
7
|
+
|
|
8
|
+
__all__ = ["Temperature", "format_scientific_notation"]
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"""
|
|
2
|
-
FlashForge Python API - Network Package
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from .fnet_code import FNetCode
|
|
6
|
-
from .utils import NetworkUtils
|
|
7
|
-
|
|
8
|
-
__all__ = [
|
|
9
|
-
"NetworkUtils",
|
|
10
|
-
"FNetCode",
|
|
11
|
-
]
|
|
1
|
+
"""
|
|
2
|
+
FlashForge Python API - Network Package
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from .fnet_code import FNetCode
|
|
6
|
+
from .utils import NetworkUtils
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"NetworkUtils",
|
|
10
|
+
"FNetCode",
|
|
11
|
+
]
|
flashforge/api/network/utils.py
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
"""
|
|
2
|
-
FlashForge Python API - Network Utilities
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
import json
|
|
6
|
-
|
|
7
|
-
import aiohttp
|
|
8
|
-
|
|
9
|
-
from ...models.responses import GenericResponse
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
async def json_from_response(response: aiohttp.ClientResponse) -> dict:
|
|
13
|
-
"""Parse JSON from a response, with a fallback for malformed Content-Type headers.
|
|
14
|
-
|
|
15
|
-
Some FlashForge printers return "appliation/json" instead of "application/json",
|
|
16
|
-
causing aiohttp to raise ContentTypeError. This helper handles both cases.
|
|
17
|
-
"""
|
|
18
|
-
try:
|
|
19
|
-
return await response.json() # type: ignore[no-any-return]
|
|
20
|
-
except aiohttp.ContentTypeError:
|
|
21
|
-
text = await response.text()
|
|
22
|
-
return json.loads(text) # type: ignore[no-any-return]
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class NetworkUtils:
|
|
26
|
-
"""Utility class for handling network responses and status codes."""
|
|
27
|
-
|
|
28
|
-
@staticmethod
|
|
29
|
-
def is_ok(response: GenericResponse | dict | None) -> bool:
|
|
30
|
-
"""
|
|
31
|
-
Checks if a response indicates success.
|
|
32
|
-
|
|
33
|
-
Args:
|
|
34
|
-
response: The response object to check
|
|
35
|
-
|
|
36
|
-
Returns:
|
|
37
|
-
True if the response indicates success, False otherwise
|
|
38
|
-
"""
|
|
39
|
-
if response is None:
|
|
40
|
-
return False
|
|
41
|
-
|
|
42
|
-
# Handle dictionary responses
|
|
43
|
-
if isinstance(response, dict):
|
|
44
|
-
code = response.get("code", -1)
|
|
45
|
-
else:
|
|
46
|
-
# Handle GenericResponse objects
|
|
47
|
-
code = getattr(response, "code", -1)
|
|
48
|
-
|
|
49
|
-
# Success codes: 0 or 200
|
|
50
|
-
return code in (0, 200)
|
|
51
|
-
|
|
52
|
-
@staticmethod
|
|
53
|
-
def get_error_message(response: GenericResponse | dict | None) -> str:
|
|
54
|
-
"""
|
|
55
|
-
Extracts error message from a response.
|
|
56
|
-
|
|
57
|
-
Args:
|
|
58
|
-
response: The response object to extract message from
|
|
59
|
-
|
|
60
|
-
Returns:
|
|
61
|
-
Error message string, or empty string if none found
|
|
62
|
-
"""
|
|
63
|
-
if response is None:
|
|
64
|
-
return "No response received"
|
|
65
|
-
|
|
66
|
-
# Handle dictionary responses
|
|
67
|
-
if isinstance(response, dict):
|
|
68
|
-
return str(response.get("message", "Unknown error"))
|
|
69
|
-
else:
|
|
70
|
-
# Handle GenericResponse objects
|
|
71
|
-
return getattr(response, "message", "Unknown error")
|
|
1
|
+
"""
|
|
2
|
+
FlashForge Python API - Network Utilities
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
import aiohttp
|
|
8
|
+
|
|
9
|
+
from ...models.responses import GenericResponse
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
async def json_from_response(response: aiohttp.ClientResponse) -> dict:
|
|
13
|
+
"""Parse JSON from a response, with a fallback for malformed Content-Type headers.
|
|
14
|
+
|
|
15
|
+
Some FlashForge printers return "appliation/json" instead of "application/json",
|
|
16
|
+
causing aiohttp to raise ContentTypeError. This helper handles both cases.
|
|
17
|
+
"""
|
|
18
|
+
try:
|
|
19
|
+
return await response.json() # type: ignore[no-any-return]
|
|
20
|
+
except aiohttp.ContentTypeError:
|
|
21
|
+
text = await response.text()
|
|
22
|
+
return json.loads(text) # type: ignore[no-any-return]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class NetworkUtils:
|
|
26
|
+
"""Utility class for handling network responses and status codes."""
|
|
27
|
+
|
|
28
|
+
@staticmethod
|
|
29
|
+
def is_ok(response: GenericResponse | dict | None) -> bool:
|
|
30
|
+
"""
|
|
31
|
+
Checks if a response indicates success.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
response: The response object to check
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
True if the response indicates success, False otherwise
|
|
38
|
+
"""
|
|
39
|
+
if response is None:
|
|
40
|
+
return False
|
|
41
|
+
|
|
42
|
+
# Handle dictionary responses
|
|
43
|
+
if isinstance(response, dict):
|
|
44
|
+
code = response.get("code", -1)
|
|
45
|
+
else:
|
|
46
|
+
# Handle GenericResponse objects
|
|
47
|
+
code = getattr(response, "code", -1)
|
|
48
|
+
|
|
49
|
+
# Success codes: 0 or 200
|
|
50
|
+
return code in (0, 200)
|
|
51
|
+
|
|
52
|
+
@staticmethod
|
|
53
|
+
def get_error_message(response: GenericResponse | dict | None) -> str:
|
|
54
|
+
"""
|
|
55
|
+
Extracts error message from a response.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
response: The response object to extract message from
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
Error message string, or empty string if none found
|
|
62
|
+
"""
|
|
63
|
+
if response is None:
|
|
64
|
+
return "No response received"
|
|
65
|
+
|
|
66
|
+
# Handle dictionary responses
|
|
67
|
+
if isinstance(response, dict):
|
|
68
|
+
return str(response.get("message", "Unknown error"))
|
|
69
|
+
else:
|
|
70
|
+
# Handle GenericResponse objects
|
|
71
|
+
return getattr(response, "message", "Unknown error")
|