anycubic-cloud-api 0.4.37__tar.gz → 0.4.38__tar.gz

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 (68) hide show
  1. {anycubic_cloud_api-0.4.37/src/anycubic_cloud_api.egg-info → anycubic_cloud_api-0.4.38}/PKG-INFO +1 -1
  2. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/pyproject.toml +1 -1
  3. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/api/functions.py +53 -0
  4. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/const/lan.py +17 -0
  5. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/orders.py +4 -0
  6. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/printer.py +339 -13
  7. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/lan/client.py +51 -3
  8. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/lan/commands.py +27 -0
  9. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/lan/handshake.py +15 -3
  10. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38/src/anycubic_cloud_api.egg-info}/PKG-INFO +1 -1
  11. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api.egg-info/SOURCES.txt +2 -0
  12. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/tests/test_lan_client.py +95 -5
  13. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/tests/test_lan_commands.py +194 -1
  14. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/tests/test_lan_handshake.py +32 -0
  15. anycubic_cloud_api-0.4.38/tests/test_lan_photon_p1_max.py +361 -0
  16. anycubic_cloud_api-0.4.38/tests/test_lan_photon_p1_max_print.py +746 -0
  17. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/COPYRIGHT +0 -0
  18. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/LICENSE +0 -0
  19. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/MANIFEST.in +0 -0
  20. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/README.md +0 -0
  21. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/setup.cfg +0 -0
  22. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/__init__.py +0 -0
  23. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/anycubic_api.py +0 -0
  24. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/api/base.py +0 -0
  25. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/api/mqtt.py +0 -0
  26. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/const/api_endpoints.py +0 -0
  27. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/const/const.py +0 -0
  28. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/const/enums.py +0 -0
  29. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/const/error_codes.py +0 -0
  30. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/const/mqtt.py +0 -0
  31. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/const/regions.py +0 -0
  32. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/consumable.py +0 -0
  33. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/files.py +0 -0
  34. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/gcode_file.py +0 -0
  35. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/print_response.py +0 -0
  36. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/print_speed_mode.py +0 -0
  37. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/printer_properties.py +0 -0
  38. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/printing_settings.py +0 -0
  39. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/data_models/project.py +0 -0
  40. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/exceptions/error_strings.py +0 -0
  41. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/exceptions/exceptions.py +0 -0
  42. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/helpers/helpers.py +0 -0
  43. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/lan/__init__.py +0 -0
  44. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/models/auth.py +0 -0
  45. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/models/cloud_upload.py +0 -0
  46. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/models/http.py +0 -0
  47. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/resources/anycubic_mqqt_tls_ca.crt +0 -0
  48. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/resources/anycubic_mqqt_tls_client.crt +0 -0
  49. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api/resources/anycubic_mqqt_tls_client.key +0 -0
  50. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api.egg-info/dependency_links.txt +0 -0
  51. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api.egg-info/requires.txt +0 -0
  52. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/src/anycubic_cloud_api.egg-info/top_level.txt +0 -0
  53. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/tests/test_auth_mode_fallback.py +0 -0
  54. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/tests/test_axis_position.py +0 -0
  55. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/tests/test_camera_kvs_0437.py +0 -0
  56. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/tests/test_endpoint_urls.py +0 -0
  57. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/tests/test_exchange_rate_limit.py +0 -0
  58. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/tests/test_filament_change_0435.py +0 -0
  59. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/tests/test_lan_reports.py +0 -0
  60. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/tests/test_null_tolerant_parsing.py +0 -0
  61. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/tests/test_partial_reports.py +0 -0
  62. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/tests/test_print_reports_0434.py +0 -0
  63. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/tests/test_printer_error_codes.py +0 -0
  64. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/tests/test_printer_slot_0436.py +0 -0
  65. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/tests/test_project_null_status.py +0 -0
  66. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/tests/test_regions.py +0 -0
  67. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/tests/test_secondary_ace.py +0 -0
  68. {anycubic_cloud_api-0.4.37 → anycubic_cloud_api-0.4.38}/tests/test_slice_param_0437.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: anycubic-cloud-api
3
- Version: 0.4.37
3
+ Version: 0.4.38
4
4
  Summary: Async client for the Anycubic Cloud API and its MQTT stream
5
5
  Author: WaresWichall, Nino Bondonno
6
6
  Maintainer: Nino Bondonno
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "anycubic-cloud-api"
7
- version = "0.4.37"
7
+ version = "0.4.38"
8
8
  description = "Async client for the Anycubic Cloud API and its MQTT stream"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -450,6 +450,42 @@ class AnycubicAPIFunctions(AnycubicAPIBase):
450
450
 
451
451
  return data
452
452
 
453
+ @staticmethod
454
+ def _lan_start_ams_settings(
455
+ order_request: AnycubicBaseOrderRequest,
456
+ ) -> dict[str, Any] | None:
457
+ """The filament mapping a local print start carries, or None.
458
+
459
+ Locally the cloud order's ``ams_info`` travels inside ``data`` as
460
+ ``ams_settings``, with only the fields the printer was seen to accept.
461
+ """
462
+ if order_request.order_id != AnycubicOrderID.START_PRINT:
463
+ return None
464
+
465
+ if not isinstance(order_request, AnycubicProjectCtrlOrderRequest):
466
+ return None
467
+
468
+ ams_info = order_request.ams_info
469
+
470
+ if not ams_info or not ams_info.get('ams_box_mapping'):
471
+ return None
472
+
473
+ mapping_keys = (
474
+ 'paint_index',
475
+ 'ams_index',
476
+ 'paint_color',
477
+ 'ams_color',
478
+ 'material_type',
479
+ )
480
+
481
+ return {
482
+ 'use_ams': True,
483
+ 'ams_box_mapping': [
484
+ {key: entry.get(key) for key in mapping_keys}
485
+ for entry in ams_info['ams_box_mapping']
486
+ ],
487
+ }
488
+
453
489
  def _send_anycubic_order_over_lan(
454
490
  self,
455
491
  order_request: AnycubicBaseOrderRequest,
@@ -470,6 +506,23 @@ class AnycubicAPIFunctions(AnycubicAPIBase):
470
506
 
471
507
  data = order_request.order_data
472
508
 
509
+ if command.default_data is not None:
510
+ data = {**command.default_data, **(data or {})}
511
+
512
+ ams_settings = self._lan_start_ams_settings(order_request)
513
+
514
+ if ams_settings is not None:
515
+ # A Kobra with an ACE refuses a local start without the order's
516
+ # filament mapping (10115, "The device cannot parse the file"),
517
+ # and starts it once the mapping and project_type 1 are added.
518
+ # Verified on a Kobra S1 with an ACE Pro. An order without a
519
+ # mapping (a resin printer, or no ACE) is sent as it was.
520
+ data = {
521
+ **(data or {}),
522
+ 'project_type': 1,
523
+ 'ams_settings': ams_settings,
524
+ }
525
+
473
526
  if command.needs_taskid:
474
527
  project_id = order_request.project_id
475
528
 
@@ -32,5 +32,22 @@ LAN_HTTP_TIMEOUT = 10
32
32
  # see AnycubicLANHandshake for why that is the right trade-off here.
33
33
  LAN_MQTT_DEFAULT_PORT = 9883
34
34
 
35
+ # Where a printer serves its camera once a local capture has been started.
36
+ # The Kobras name this address themselves in their info report; a Photon P1
37
+ # Max sends no info report and leaves the handshake's "rtsp" field empty, but
38
+ # serves the same FLV stream on the same port.
39
+ LAN_CAMERA_STREAM_PORT = 18088
40
+ LAN_CAMERA_STREAM_PATH = "/flv"
41
+
42
+ # How far the camera picture has to be turned, clockwise in degrees, to stand
43
+ # upright. A printer mounts its camera wherever it fits and serves the picture
44
+ # as the sensor sees it; nothing in the stream or in any report says which way
45
+ # is up, so it is recorded here per model as it is found. A Photon P1 Max
46
+ # (132) delivers its picture lying on its side.
47
+ LAN_CAMERA_ROTATION_BY_MODEL: dict[int, int] = {
48
+ 132: 270,
49
+ }
50
+ LAN_CAMERA_ROTATIONS = (0, 90, 180, 270)
51
+
35
52
  LAN_REQUIRED_INFO_FIELDS = ("token", "ctrlInfoUrl", "modelId")
36
53
  LAN_REQUIRED_BROKER_FIELDS = ("broker", "username", "password", "deviceId")
@@ -234,6 +234,10 @@ class AnycubicProjectCtrlOrderRequest(AnycubicProjectOrderRequest):
234
234
  else:
235
235
  self._ams_info = None
236
236
 
237
+ @property
238
+ def ams_info(self) -> dict[str, Any] | None:
239
+ return self._ams_info
240
+
237
241
  @property
238
242
  def order_request_data(self) -> dict[str, Any]:
239
243
  return {
@@ -4,6 +4,7 @@ import re
4
4
  from collections.abc import Mapping
5
5
  from typing import TYPE_CHECKING, Any
6
6
 
7
+ from ..const.lan import LAN_CAMERA_ROTATION_BY_MODEL, LAN_CAMERA_ROTATIONS
7
8
  from ..const.enums import (
8
9
  AnycubicFunctionID,
9
10
  AnycubicPrinterMaterialType,
@@ -206,6 +207,16 @@ class AnycubicPrinter:
206
207
  "_has_peripheral_camera",
207
208
  "_has_peripheral_multi_color_box",
208
209
  "_has_peripheral_udisk",
210
+ "_has_peripheral_smart_resin_vat",
211
+ "_has_peripheral_air_purifier",
212
+ "_resin_temperature",
213
+ "_release_film",
214
+ "_camera_is_streaming",
215
+ "_camera_rotation",
216
+ "_auto_operations",
217
+ "_print_self_check",
218
+ "_last_print_error",
219
+ "_last_print_finish",
209
220
  "_is_bound_to_user",
210
221
  "_job_download_progress",
211
222
  "_lights",
@@ -326,6 +337,18 @@ class AnycubicPrinter:
326
337
  self._has_peripheral_camera: bool | None = None
327
338
  self._has_peripheral_multi_color_box: bool | None = None
328
339
  self._has_peripheral_udisk: bool | None = None
340
+ self._has_peripheral_smart_resin_vat: bool | None = None
341
+ self._has_peripheral_air_purifier: bool | None = None
342
+ # Resin printers only. None until the printer has said.
343
+ self._resin_temperature: float | None = None
344
+ self._release_film: dict[str, int] | None = None
345
+ self._camera_is_streaming: bool | None = None
346
+ # None means "whatever this model needs"; a number is someone's choice.
347
+ self._camera_rotation: int | None = None
348
+ self._auto_operations: dict[str, dict[str, int]] | None = None
349
+ self._print_self_check: dict[str, int] | None = None
350
+ self._last_print_error: dict[str, Any] | None = None
351
+ self._last_print_finish: dict[str, Any] | None = None
329
352
  self._is_bound_to_user: bool = True
330
353
  self._job_download_progress: int = 0
331
354
  self._aux_fan_speed: int | None = None
@@ -353,6 +376,34 @@ class AnycubicPrinter:
353
376
  def set_has_peripheral_udisk(self, has_peripheral: bool) -> None:
354
377
  self._has_peripheral_udisk = bool(has_peripheral)
355
378
 
379
+ def set_camera_rotation(self, degrees: int | None) -> None:
380
+ """Choose how far the camera picture is turned, clockwise.
381
+
382
+ 0, 90, 180 or 270. None goes back to what the model needs by itself --
383
+ for a printer standing on its side or hanging upside down, the model's
384
+ own answer is the wrong one and this is how to say so.
385
+ """
386
+ if degrees is None:
387
+ self._camera_rotation = None
388
+ return
389
+
390
+ degrees = int(degrees) % 360
391
+
392
+ if degrees not in LAN_CAMERA_ROTATIONS:
393
+ raise ValueError(
394
+ f"Camera rotation must be one of {LAN_CAMERA_ROTATIONS}, not {degrees}."
395
+ )
396
+
397
+ self._camera_rotation = degrees
398
+
399
+ def set_camera_stream_url(self, url: str | None) -> None:
400
+ """Say where this printer's camera is served.
401
+
402
+ For printers that never name the address themselves: whoever holds the
403
+ local connection knows the host and can fill it in.
404
+ """
405
+ self._camera_stream_url = url
406
+
356
407
  def _set_type_function_ids(self, type_function_ids: list[int] | None) -> None:
357
408
  if isinstance(type_function_ids, list):
358
409
  self._type_function_ids = type_function_ids
@@ -1248,6 +1299,54 @@ class AnycubicPrinter:
1248
1299
  data,
1249
1300
  )
1250
1301
  return
1302
+ elif action == 'start' and state == 'copying':
1303
+ # A resin printer copying the file off its USB stick before it
1304
+ # starts: {'taskid': '-1', 'progress': 50}. The same thing a
1305
+ # download is to a cloud print.
1306
+ data = payload['data']
1307
+ self._is_printing = 2
1308
+ self._set_job_download_progress(data.get('progress'))
1309
+ data.get('taskid')
1310
+ return
1311
+ elif action == 'start' and state == 'waiting':
1312
+ # The job exists but the printer will not go on by itself -- on a
1313
+ # Photon P1 Max this arrived with code 1301 when its pre-print
1314
+ # check failed (an empty vat). Still a job, so still busy; the
1315
+ # code has already been recorded above.
1316
+ data = payload['data']
1317
+ self._is_printing = 2
1318
+ self._update_latest_project_with_mqtt_print_status_data(
1319
+ project_id,
1320
+ AnycubicPrintStatus.Checking,
1321
+ data,
1322
+ )
1323
+ return
1324
+ elif action in ('monitor', 'autoOperation') and state == 'monitoring':
1325
+ # The printer's own checks before and during a print, as a list of
1326
+ # {'name': ..., 'status': ...}: hardware for "monitor", the
1327
+ # pre-print steps (levelling, resin, residue ...) for
1328
+ # "autoOperation". 0 passed, -1 pending, -2 not applicable.
1329
+ data = payload['data']
1330
+ checks = self._print_self_check or {}
1331
+
1332
+ for check in data.get('checkStatus') or []:
1333
+ name = check.get('name')
1334
+
1335
+ if name is not None:
1336
+ checks[str(name)] = int(check.get('status') or 0)
1337
+
1338
+ self._print_self_check = checks
1339
+ data.get('taskid')
1340
+ return
1341
+ elif action == 'pause' and state == 'unablePause':
1342
+ # Refused, for instance during the pre-print checks (code 9000).
1343
+ # Nothing changed, so nothing is changed here either.
1344
+ _drain(payload['data'])
1345
+ return
1346
+ elif action == 'resume' and state == 'unable-resume':
1347
+ # Refused: there was nothing paused to resume (code 102).
1348
+ _drain(payload['data'])
1349
+ return
1251
1350
  elif action == 'start' and state == 'checking':
1252
1351
  self._is_printing = 2
1253
1352
  self._update_latest_project_with_mqtt_checking_status_data(
@@ -1608,14 +1707,21 @@ class AnycubicPrinter:
1608
1707
  payload: AnycubicConsumableData,
1609
1708
  ) -> None:
1610
1709
  if action == 'listLocal' and state == 'done':
1611
- data = payload['data']['records']
1710
+ listing = payload['data']
1711
+ # Sent by a Photon P1 Max alongside the records; 0 on the one
1712
+ # listing seen so far, meaning unknown. Read so it is not mistaken
1713
+ # for something unhandled.
1714
+ listing.get('list_mode')
1715
+ data = listing['records']
1612
1716
  self._set_local_file_list(data)
1613
1717
  return
1614
1718
  elif action == 'deleteLocal' and state == 'success':
1615
1719
  # Not Yet Needed
1616
1720
  return
1617
1721
  elif action == 'listUdisk' and state == 'done':
1618
- data = payload['data']['records']
1722
+ listing = payload['data']
1723
+ listing.get('list_mode')
1724
+ data = listing['records']
1619
1725
  self._set_udisk_file_list(data)
1620
1726
  return
1621
1727
  elif action == 'deleteUdisk' and state == 'success':
@@ -1646,27 +1752,98 @@ class AnycubicPrinter:
1646
1752
  if 'udisk' in data:
1647
1753
  self.set_has_peripheral_udisk(data['udisk'])
1648
1754
 
1755
+ # Resin printers list their own two.
1756
+ if 'smartResinVat' in data:
1757
+ self._has_peripheral_smart_resin_vat = bool(data['smartResinVat'])
1758
+
1759
+ if 'airpure' in data:
1760
+ self._has_peripheral_air_purifier = bool(data['airpure'])
1761
+
1649
1762
  return
1650
1763
  else:
1651
1764
  raise AnycubicMQTTUnknownUpdate(ErrorsMQTTUpdate.peripherals)
1652
1765
 
1766
+ def _process_mqtt_update_properties(
1767
+ self,
1768
+ action: str,
1769
+ state: str,
1770
+ payload: AnycubicConsumableData,
1771
+ ) -> None:
1772
+ """Readings a resin printer pushes unasked, every few seconds.
1773
+
1774
+ Captured from a Photon P1 Max: ``{'resin_temp': 24.389999}``.
1775
+ """
1776
+ if action != 'report' or state != 'done':
1777
+ raise AnycubicMQTTUnknownUpdate(ErrorsMQTTUpdate.unknown.format('properties'))
1778
+
1779
+ data = payload['data']
1780
+
1781
+ if not data:
1782
+ return
1783
+
1784
+ if 'resin_temp' in data:
1785
+ resin_temp = data['resin_temp']
1786
+ self._resin_temperature = float(resin_temp) if resin_temp is not None else None
1787
+
1788
+ def _process_mqtt_update_release_film(
1789
+ self,
1790
+ action: str,
1791
+ state: str,
1792
+ payload: AnycubicConsumableData,
1793
+ ) -> None:
1794
+ """How worn the release film is.
1795
+
1796
+ Captured from a Photon P1 Max: ``{'times': 0, 'layers': 0, 'status': 0}``.
1797
+ """
1798
+ if action != 'get' or state != 'done':
1799
+ raise AnycubicMQTTUnknownUpdate(ErrorsMQTTUpdate.unknown.format('releaseFilm'))
1800
+
1801
+ data = payload['data']
1802
+
1803
+ if not data:
1804
+ return
1805
+
1806
+ self._release_film = {
1807
+ 'times': int(data.get('times') or 0),
1808
+ 'layers': int(data.get('layers') or 0),
1809
+ 'status': int(data.get('status') or 0),
1810
+ }
1811
+
1653
1812
  def _process_mqtt_update_video(
1654
1813
  self,
1655
1814
  action: str,
1656
1815
  state: str | None,
1657
1816
  payload: AnycubicConsumableData,
1658
1817
  ) -> None:
1659
- """The printer reporting on the cloud camera push (#49).
1660
-
1661
- After a camera-open order the printer answers ``startCapture`` with
1662
- ``initSuccess`` and then ``pushStarted`` once video is going out, or
1663
- ``initFailed`` / ``pushFailed``. These used to be logged as an unknown
1664
- update, which hid the one fact that matters when the picture never
1665
- arrives: whether the printer actually started sending it.
1818
+ """The printer reporting on its camera.
1819
+
1820
+ Cloud camera push (#49): after a camera-open order the printer answers
1821
+ ``startCapture`` with ``initSuccess`` and then ``pushStarted`` once
1822
+ video is going out, or ``initFailed`` / ``pushFailed``. These used to
1823
+ be logged as an unknown update, which hid the one fact that matters
1824
+ when the picture never arrives: whether the printer actually started
1825
+ sending it.
1826
+
1827
+ Local stream: a Photon P1 Max answers ``startCapture`` with state
1828
+ ``initSuccess`` and ``stopCapture`` with ``done`` (twice: push ended,
1829
+ then stopped), followed by one more ``stopCapture`` in state
1830
+ ``initSuccess`` with code 1404 once nothing is left to stop. None of
1831
+ them carry data.
1666
1832
  """
1833
+ if action not in ('startCapture', 'stopCapture'):
1834
+ raise AnycubicMQTTUnknownUpdate(ErrorsMQTTUpdate.unknown.format('video'))
1835
+
1667
1836
  if state:
1668
1837
  self._camera_push_state = str(state)
1669
1838
 
1839
+ if action == 'startCapture':
1840
+ if state == 'initSuccess':
1841
+ self._camera_is_streaming = True
1842
+ elif state in ('failed', 'initFailed'):
1843
+ self._camera_is_streaming = False
1844
+ else:
1845
+ self._camera_is_streaming = False
1846
+
1670
1847
  data = payload.get('data')
1671
1848
 
1672
1849
  if isinstance(data, Mapping):
@@ -1681,6 +1858,64 @@ class AnycubicPrinter:
1681
1858
  """Forget the last push state, so a new viewing session waits for its own."""
1682
1859
  self._camera_push_state = None
1683
1860
 
1861
+ def _process_mqtt_update_auto_operation(
1862
+ self,
1863
+ action: str,
1864
+ state: str,
1865
+ payload: AnycubicConsumableData,
1866
+ ) -> None:
1867
+ """Which automatic steps a resin printer has, and which are switched on.
1868
+
1869
+ Sent by a Photon P1 Max when a print is started, as a list of
1870
+ ``{'name': 'levelling', 'support': 1, 'editable': 0, 'status': 1}``.
1871
+ """
1872
+ if action != 'reportStatus' or state != 'done':
1873
+ raise AnycubicMQTTUnknownUpdate(ErrorsMQTTUpdate.unknown.format('autoOperation'))
1874
+
1875
+ data = payload['data']
1876
+
1877
+ if not data:
1878
+ return
1879
+
1880
+ operations: dict[str, dict[str, int]] = {}
1881
+
1882
+ for operation in data.get('currentStatus') or []:
1883
+ name = operation.get('name')
1884
+
1885
+ if name is None:
1886
+ continue
1887
+
1888
+ operations[str(name)] = {
1889
+ 'support': int(operation.get('support') or 0),
1890
+ 'editable': int(operation.get('editable') or 0),
1891
+ 'status': int(operation.get('status') or 0),
1892
+ }
1893
+
1894
+ self._auto_operations = operations
1895
+
1896
+ def _process_mqtt_update_buried(
1897
+ self,
1898
+ action: str,
1899
+ state: str | None,
1900
+ payload: AnycubicConsumableData,
1901
+ ) -> None:
1902
+ """The printer's own event log entries for a job.
1903
+
1904
+ Two have been seen from a Photon P1 Max, neither with a state or a
1905
+ result code: ``PrintError`` when a job stalls (error code, stage,
1906
+ layer) and ``PrintFinish`` when it ends (how it ended, how long it
1907
+ ran). They are the only place the printer says *why* in one message,
1908
+ so they are kept as they come.
1909
+ """
1910
+ data = _drain(payload['data'])
1911
+
1912
+ if action == 'PrintError':
1913
+ self._last_print_error = data
1914
+ elif action == 'PrintFinish':
1915
+ self._last_print_finish = data
1916
+ else:
1917
+ raise AnycubicMQTTUnknownUpdate(ErrorsMQTTUpdate.unknown.format('buried'))
1918
+
1684
1919
  def _process_mqtt_update_light(
1685
1920
  self,
1686
1921
  action: str,
@@ -1968,6 +2203,21 @@ class AnycubicPrinter:
1968
2203
  elif msg_type == 'light':
1969
2204
  self._process_mqtt_update_light(action, state, payload)
1970
2205
 
2206
+ elif msg_type == 'properties':
2207
+ self._process_mqtt_update_properties(action, state, payload)
2208
+
2209
+ elif msg_type == 'releaseFilm':
2210
+ self._process_mqtt_update_release_film(action, state, payload)
2211
+
2212
+ elif msg_type == 'video':
2213
+ self._process_mqtt_update_video(action, state, payload)
2214
+
2215
+ elif msg_type == 'autoOperation':
2216
+ self._process_mqtt_update_auto_operation(action, state, payload)
2217
+
2218
+ elif msg_type == 'buried':
2219
+ self._process_mqtt_update_buried(action, state, payload)
2220
+
1971
2221
  elif msg_type == 'info':
1972
2222
  self._process_mqtt_update_info(action, state, payload)
1973
2223
 
@@ -1977,9 +2227,6 @@ class AnycubicPrinter:
1977
2227
  elif msg_type in ('event', 'printerevent', 'printer_event'):
1978
2228
  self._process_mqtt_update_event(action, state, payload)
1979
2229
 
1980
- elif msg_type == 'video':
1981
- self._process_mqtt_update_video(action, state, payload)
1982
-
1983
2230
  else:
1984
2231
  raise AnycubicMQTTUnknownUpdate(ErrorsMQTTUpdate.unknown.format(msg_type))
1985
2232
 
@@ -2396,14 +2643,93 @@ class AnycubicPrinter:
2396
2643
  def has_peripheral_udisk(self) -> bool | None:
2397
2644
  return self._has_peripheral_udisk
2398
2645
 
2646
+ @property
2647
+ def has_peripheral_smart_resin_vat(self) -> bool | None:
2648
+ return self._has_peripheral_smart_resin_vat
2649
+
2650
+ @property
2651
+ def has_peripheral_air_purifier(self) -> bool | None:
2652
+ return self._has_peripheral_air_purifier
2653
+
2399
2654
  @property
2400
2655
  def connected_peripherals(self) -> dict[str, bool | None]:
2401
- return {
2656
+ peripherals = {
2402
2657
  "camera": self.has_peripheral_camera,
2403
2658
  "ace": self.has_peripheral_multi_color_box,
2404
2659
  "usb_disk": self.has_peripheral_udisk,
2405
2660
  }
2406
2661
 
2662
+ # Only for printers that mention them, so a filament printer's list
2663
+ # does not grow two entries it will never fill.
2664
+ if self._has_peripheral_smart_resin_vat is not None:
2665
+ peripherals["smart_resin_vat"] = self._has_peripheral_smart_resin_vat
2666
+
2667
+ if self._has_peripheral_air_purifier is not None:
2668
+ peripherals["air_purifier"] = self._has_peripheral_air_purifier
2669
+
2670
+ return peripherals
2671
+
2672
+ @property
2673
+ def resin_temperature(self) -> float | None:
2674
+ """Resin temperature in degrees Celsius, as a resin printer reports it."""
2675
+ return self._resin_temperature
2676
+
2677
+ @property
2678
+ def release_film_times(self) -> int | None:
2679
+ """How many times the release film has been used."""
2680
+ return self._release_film['times'] if self._release_film else None
2681
+
2682
+ @property
2683
+ def release_film_layers(self) -> int | None:
2684
+ """How many layers have been printed on the release film."""
2685
+ return self._release_film['layers'] if self._release_film else None
2686
+
2687
+ @property
2688
+ def release_film_status(self) -> int | None:
2689
+ """The printer's own verdict on the film; 0 on a fresh one."""
2690
+ return self._release_film['status'] if self._release_film else None
2691
+
2692
+ @property
2693
+ def auto_operations(self) -> dict[str, dict[str, int]] | None:
2694
+ """A resin printer's automatic steps: support, editable and status per name."""
2695
+ return self._auto_operations
2696
+
2697
+ @property
2698
+ def print_self_check(self) -> dict[str, int] | None:
2699
+ """The printer's own checks around a print: 0 passed, -1 pending, -2 not applicable."""
2700
+ return self._print_self_check
2701
+
2702
+ @property
2703
+ def last_print_error(self) -> dict[str, Any] | None:
2704
+ """What the printer logged when a job last stalled."""
2705
+ return self._last_print_error
2706
+
2707
+ @property
2708
+ def last_print_finish(self) -> dict[str, Any] | None:
2709
+ """What the printer logged when a job last ended."""
2710
+ return self._last_print_finish
2711
+
2712
+ @property
2713
+ def camera_rotation(self) -> int:
2714
+ """Degrees to turn the camera picture, clockwise, for it to stand upright.
2715
+
2716
+ A chosen value if there is one, otherwise what is known for this
2717
+ model, otherwise 0. The stream itself is never altered; this is for
2718
+ whoever shows it.
2719
+ """
2720
+ if self._camera_rotation is not None:
2721
+ return self._camera_rotation
2722
+
2723
+ try:
2724
+ return LAN_CAMERA_ROTATION_BY_MODEL.get(int(self._machine_type), 0)
2725
+ except (TypeError, ValueError):
2726
+ return 0
2727
+
2728
+ @property
2729
+ def camera_is_streaming(self) -> bool | None:
2730
+ """Whether the local camera stream is being served. None until told."""
2731
+ return self._camera_is_streaming
2732
+
2407
2733
  @property
2408
2734
  def material_type(self) -> AnycubicPrinterMaterialType | str | None:
2409
2735
  return self._material_type