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.
Files changed (70) hide show
  1. flashforge/__init__.py +337 -256
  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 -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.0.0.dist-info}/METADATA +46 -47
  60. flashforge_python_api-3.0.0.dist-info/RECORD +69 -0
  61. {flashforge_python_api-1.6.0.dist-info → flashforge_python_api-3.0.0.dist-info}/WHEEL +1 -1
  62. {flashforge_python_api-1.6.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 -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.0.0.dist-info}/entry_points.txt +0 -0
flashforge/__init__.py CHANGED
@@ -1,256 +1,337 @@
1
- """
2
- FlashForge Python API
3
-
4
- A Python library for controlling FlashForge 3D printers via HTTP and TCP APIs.
5
- Provides comprehensive async support for printer control, job management, file operations,
6
- temperature control, and real-time communication.
7
-
8
- Example:
9
- Basic usage example:
10
-
11
- ```python
12
- import asyncio
13
- from flashforge import FlashForgeClient
14
-
15
- async def main():
16
- async with FlashForgeClient("192.168.1.100", "serial123", "check456") as client:
17
- if await client.initialize():
18
- print(f"Connected to {client.printer_name}")
19
-
20
- # Get printer status
21
- status = await client.get_printer_status()
22
- print(f"Status: {status.machine_state}")
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")
31
-
32
- asyncio.run(main())
33
- ```
34
- """
35
-
36
- from .api.constants.commands import Commands
37
- 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
- from .api.filament import Filament
48
- from .api.misc import Temperature as TempWrapper
49
- from .api.misc import format_scientific_notation
50
- from .api.network.fnet_code import FNetCode
51
-
52
- # Import utility classes
53
- from .api.network.utils import NetworkUtils
54
- from .client import FiveMClientConnectionOptions, FlashForgeClient
55
-
56
- # Import discovery classes
57
- from .discovery import (
58
- DiscoveredPrinter,
59
- DiscoveryError,
60
- DiscoveryMonitor,
61
- DiscoveryOptions,
62
- DiscoveryProtocol,
63
- DiscoveryTimeoutError,
64
- FlashForgePrinter,
65
- FlashForgePrinterDiscovery,
66
- InvalidResponseError,
67
- PrinterDiscovery,
68
- PrinterModel,
69
- PrinterStatus,
70
- SocketCreationError,
71
- )
72
- from .exceptions import FlashForgeError, FlashForgeResponseError
73
-
74
- # Import key models for convenience
75
- from .models import (
76
- AD5XLocalJobParams,
77
- AD5XMaterialMapping,
78
- AD5XSingleColorJobParams,
79
- AD5XUploadParams,
80
- DetailResponse,
81
- FFGcodeFileEntry,
82
- FFGcodeToolData,
83
- FFMachineInfo,
84
- FFPrinterDetail,
85
- FilamentArgs,
86
- GCodeListResponse,
87
- GenericResponse,
88
- IndepMatlInfo,
89
- MachineState,
90
- MatlStationInfo,
91
- Product,
92
- ProductResponse,
93
- SlotInfo,
94
- Temperature,
95
- ThumbnailResponse,
96
- )
97
- from .tcp import (
98
- A3BuildVolume,
99
- A3FileEntry,
100
- A3GCodeController,
101
- A3PrinterInfo,
102
- A3Thumbnail,
103
- A4BuildVolume,
104
- A4FileEntry,
105
- A4PrinterInfo,
106
- Endstop,
107
- EndstopStatus,
108
- FlashForgeA3Client,
109
- FlashForgeA4Client,
110
- FlashForgeTcpClient,
111
- FlashForgeTcpClientOptions,
112
- GCodeController,
113
- GCodes,
114
- LocationInfo,
115
- MachineStatus,
116
- MoveMode,
117
- PrinterInfo,
118
- PrintStatus,
119
- Status,
120
- TempData,
121
- TempInfo,
122
- ThumbnailInfo,
123
- )
124
-
125
- # Import TCP classes for low-level access
126
- from .tcp import (
127
- FlashForgeTcpClient as TcpClient,
128
- )
129
-
130
- # Sliced 3MF parsing (tools and materials before upload)
131
- from .threemf import (
132
- PrinterFamily,
133
- ThreeMFError,
134
- ThreeMFFilament,
135
- ThreeMFFile,
136
- ThreeMFFormatError,
137
- ThreeMFMultiplePlatesError,
138
- ThreeMFNotSlicedError,
139
- ThreeMFWarning,
140
- parse_3mf,
141
- )
142
-
143
- FiveMClient = FlashForgeClient
144
- __version__ = "1.6.0"
145
- __author__ = "FlashForge Python API Contributors"
146
- __email__ = "notghosttypes@gmail.com"
147
- __description__ = "Python library for controlling FlashForge 3D printers"
148
-
149
- # Public API - Main classes most users will need
150
- __all__ = [
151
- # Main client class
152
- "FlashForgeClient",
153
- "FiveMClient",
154
- "FiveMClientConnectionOptions",
155
- # Exceptions
156
- "FlashForgeError",
157
- "FlashForgeResponseError",
158
- # Data models
159
- "FFMachineInfo",
160
- "FFPrinterDetail",
161
- "FFGcodeFileEntry",
162
- "FFGcodeToolData",
163
- "MachineState",
164
- "Temperature",
165
- "GenericResponse",
166
- "DetailResponse",
167
- "ProductResponse",
168
- "Product",
169
- "FilamentArgs",
170
- # AD5X models
171
- "SlotInfo",
172
- "MatlStationInfo",
173
- "IndepMatlInfo",
174
- "AD5XMaterialMapping",
175
- "AD5XLocalJobParams",
176
- "AD5XSingleColorJobParams",
177
- "AD5XUploadParams",
178
- "GCodeListResponse",
179
- "ThumbnailResponse",
180
- # Sliced 3MF parsing
181
- "parse_3mf",
182
- "PrinterFamily",
183
- "ThreeMFError",
184
- "ThreeMFFilament",
185
- "ThreeMFFile",
186
- "ThreeMFFormatError",
187
- "ThreeMFMultiplePlatesError",
188
- "ThreeMFNotSlicedError",
189
- "ThreeMFWarning",
190
- # Control classes for advanced usage
191
- "Control",
192
- "JobControl",
193
- "Info",
194
- "Files",
195
- "TempControl",
196
- # TCP classes for low-level operations
197
- "TcpClient",
198
- "FlashForgeTcpClient",
199
- "FlashForgeTcpClientOptions",
200
- "FlashForgeA3Client",
201
- "FlashForgeA4Client",
202
- "PrinterInfo",
203
- "TempInfo",
204
- "TempData",
205
- "LocationInfo",
206
- "EndstopStatus",
207
- "MachineStatus",
208
- "MoveMode",
209
- "Status",
210
- "Endstop",
211
- "PrintStatus",
212
- "ThumbnailInfo",
213
- "GCodes",
214
- "GCodeController",
215
- "A3GCodeController",
216
- "A3BuildVolume",
217
- "A3PrinterInfo",
218
- "A3FileEntry",
219
- "A3Thumbnail",
220
- "A4BuildVolume",
221
- "A4PrinterInfo",
222
- "A4FileEntry",
223
- # Discovery classes
224
- "PrinterDiscovery",
225
- "DiscoveredPrinter",
226
- "DiscoveryOptions",
227
- "PrinterModel",
228
- "DiscoveryProtocol",
229
- "PrinterStatus",
230
- "DiscoveryMonitor",
231
- "DiscoveryError",
232
- "InvalidResponseError",
233
- "SocketCreationError",
234
- "DiscoveryTimeoutError",
235
- "FlashForgePrinter",
236
- "FlashForgePrinterDiscovery",
237
- # Utilities
238
- "NetworkUtils",
239
- "FNetCode",
240
- "Filament",
241
- "TempWrapper",
242
- "format_scientific_notation",
243
- "Endpoints",
244
- "Commands",
245
- # Package metadata
246
- "__version__",
247
- "__author__",
248
- "__email__",
249
- "__description__",
250
- ]
251
-
252
- # Convenience imports for common patterns
253
- State = MachineState
254
-
255
- # Add version info accessible as flashforge.version
256
- version = __version__
1
+ """
2
+ FlashForge Python API
3
+
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.
6
+
7
+ Example:
8
+ ```python
9
+ import asyncio
10
+ from flashforge import ConnectOptions, ConnectTarget, PrinterDiscovery, connect_printer
11
+
12
+ async def main():
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)
20
+
21
+ asyncio.run(main())
22
+ ```
23
+ """
24
+
25
+ from .api.constants.commands import Commands
26
+ from .api.constants.endpoints import Endpoints
27
+ from .api.filament import Filament
28
+ from .api.misc import Temperature as TempWrapper
29
+ from .api.misc import format_scientific_notation
30
+ from .api.network.fnet_code import FNetCode
31
+
32
+ # Import utility classes
33
+ from .api.network.utils import NetworkUtils
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
+ )
77
+
78
+ # Import discovery classes
79
+ from .discovery import (
80
+ DiscoveredPrinter,
81
+ DiscoveryError,
82
+ DiscoveryMonitor,
83
+ DiscoveryOptions,
84
+ DiscoveryProtocol,
85
+ DiscoveryTimeoutError,
86
+ FlashForgePrinter,
87
+ FlashForgePrinterDiscovery,
88
+ InvalidResponseError,
89
+ PrinterDiscovery,
90
+ PrinterModelId,
91
+ PrinterStatus,
92
+ SocketCreationError,
93
+ )
94
+ from .exceptions import (
95
+ FlashForgeError,
96
+ FlashForgeResponseError,
97
+ InvalidParameterError,
98
+ NotSupportedError,
99
+ PrinterConnectionError,
100
+ )
101
+
102
+ # Import key models for convenience
103
+ from .models import (
104
+ DetailResponse,
105
+ FFGcodeFileEntry,
106
+ FFGcodeToolData,
107
+ FFMachineInfo,
108
+ FFPrinterDetail,
109
+ FilamentArgs,
110
+ GCodeListResponse,
111
+ GenericResponse,
112
+ IndepMatlInfo,
113
+ MachineInfoParser,
114
+ MachineState,
115
+ MatlStationInfo,
116
+ Product,
117
+ ProductResponse,
118
+ SlotInfo,
119
+ Temperature,
120
+ ThumbnailResponse,
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
+ )
133
+ from .tcp import (
134
+ A3BuildVolume,
135
+ A3FileEntry,
136
+ A3GCodeController,
137
+ A3PrinterInfo,
138
+ A3Thumbnail,
139
+ A4BuildVolume,
140
+ A4FileEntry,
141
+ A4PrinterInfo,
142
+ Endstop,
143
+ EndstopStatus,
144
+ FlashForgeA3Client,
145
+ FlashForgeA4Client,
146
+ FlashForgeTcpClient,
147
+ FlashForgeTcpClientOptions,
148
+ GCodeController,
149
+ GCodes,
150
+ LegacyGCodeController,
151
+ LocationInfo,
152
+ MachineStatus,
153
+ MoveMode,
154
+ PrinterInfo,
155
+ PrintStatus,
156
+ Status,
157
+ TempData,
158
+ TempInfo,
159
+ ThumbnailInfo,
160
+ )
161
+
162
+ # Import TCP classes for low-level access
163
+ from .tcp import (
164
+ FlashForgeTcpClient as TcpClient,
165
+ )
166
+ from .threemf import (
167
+ PrinterFamily,
168
+ ThreeMFError,
169
+ ThreeMFFilament,
170
+ ThreeMFFile,
171
+ ThreeMFFormatError,
172
+ ThreeMFMultiplePlatesError,
173
+ ThreeMFNotSlicedError,
174
+ ThreeMFWarning,
175
+ parse_3mf,
176
+ )
177
+
178
+ __version__ = "3.0.0"
179
+ __author__ = "FlashForge Python API Contributors"
180
+ __email__ = "notghosttypes@gmail.com"
181
+ __description__ = "Python library for controlling FlashForge 3D printers"
182
+
183
+ # Public API - Main classes most users will need
184
+ __all__ = [
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",
235
+ # Exceptions
236
+ "FlashForgeError",
237
+ "FlashForgeResponseError",
238
+ "NotSupportedError",
239
+ "InvalidParameterError",
240
+ "PrinterConnectionError",
241
+ # Data models
242
+ "FFMachineInfo",
243
+ "FFPrinterDetail",
244
+ "MachineInfoParser",
245
+ "FFGcodeFileEntry",
246
+ "FFGcodeToolData",
247
+ "MachineState",
248
+ "Temperature",
249
+ "GenericResponse",
250
+ "DetailResponse",
251
+ "ProductResponse",
252
+ "Product",
253
+ "FilamentArgs",
254
+ # AD5X models
255
+ "SlotInfo",
256
+ "MatlStationInfo",
257
+ "IndepMatlInfo",
258
+ "GCodeListResponse",
259
+ "ThumbnailResponse",
260
+ # Sliced 3MF parsing
261
+ "parse_3mf",
262
+ "PrinterFamily",
263
+ "ThreeMFError",
264
+ "ThreeMFFilament",
265
+ "ThreeMFFile",
266
+ "ThreeMFFormatError",
267
+ "ThreeMFMultiplePlatesError",
268
+ "ThreeMFNotSlicedError",
269
+ "ThreeMFWarning",
270
+ # TCP classes for low-level operations
271
+ "TcpClient",
272
+ "FlashForgeTcpClient",
273
+ "FlashForgeTcpClientOptions",
274
+ "FlashForgeA3Client",
275
+ "FlashForgeA4Client",
276
+ "PrinterInfo",
277
+ "TempInfo",
278
+ "TempData",
279
+ "LocationInfo",
280
+ "EndstopStatus",
281
+ "MachineStatus",
282
+ "MoveMode",
283
+ "Status",
284
+ "Endstop",
285
+ "PrintStatus",
286
+ "ThumbnailInfo",
287
+ "GCodes",
288
+ "GCodeController",
289
+ "A3GCodeController",
290
+ "LegacyGCodeController",
291
+ "A3BuildVolume",
292
+ "A3PrinterInfo",
293
+ "A3FileEntry",
294
+ "A3Thumbnail",
295
+ "A4BuildVolume",
296
+ "A4PrinterInfo",
297
+ "A4FileEntry",
298
+ # Discovery classes
299
+ "PrinterDiscovery",
300
+ "DiscoveredPrinter",
301
+ "DiscoveryOptions",
302
+ "DiscoveryProtocol",
303
+ "PrinterStatus",
304
+ "DiscoveryMonitor",
305
+ "DiscoveryError",
306
+ "InvalidResponseError",
307
+ "SocketCreationError",
308
+ "DiscoveryTimeoutError",
309
+ "FlashForgePrinter",
310
+ "FlashForgePrinterDiscovery",
311
+ # Utilities
312
+ "NetworkUtils",
313
+ "FNetCode",
314
+ "Filament",
315
+ "TempWrapper",
316
+ "format_scientific_notation",
317
+ "Endpoints",
318
+ "Commands",
319
+ # Package metadata
320
+ "__version__",
321
+ "__author__",
322
+ "__email__",
323
+ "__description__",
324
+ ]
325
+
326
+ # Convenience imports for common patterns
327
+ State = MachineState
328
+
329
+ # Add version info accessible as flashforge.version
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}'")