test_ams_ht_load_unload.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. """Load and Unload work on an AMS-HT slot.
  2. An AMS-HT tray is numbered by its unit id (128-135), as the printer reports it
  3. in tray_now. The printer card sent unit*4+slot (512 for the first AMS-HT),
  4. which the load route refused, and the commands turned 128 into ams_id 32. They
  5. now send what BambuStudio sends: ams_id = the unit id, slot_id 0, target = the
  6. unit id.
  7. """
  8. import json
  9. from unittest.mock import MagicMock
  10. import pytest
  11. from backend.app.services.bambu_mqtt import BambuMQTTClient
  12. def _client(model: str = "O1C2") -> BambuMQTTClient:
  13. client = BambuMQTTClient(ip_address="10.0.0.1", serial_number="H2C", access_code="c", model=model)
  14. client._client = MagicMock()
  15. client.state.connected = True
  16. return client
  17. def _sent(client) -> dict:
  18. return json.loads(client._client.publish.call_args[0][1])["print"]
  19. @pytest.mark.parametrize("unit", [128, 131, 135])
  20. def test_load_addresses_the_unit(unit):
  21. client = _client()
  22. assert client.ams_load_filament(unit) is True
  23. sent = _sent(client)
  24. assert (sent["ams_id"], sent["slot_id"], sent["target"]) == (unit, 0, unit)
  25. def test_a_regular_slot_is_unchanged():
  26. client = _client()
  27. assert client.ams_load_filament(6) is True
  28. sent = _sent(client)
  29. assert (sent["ams_id"], sent["slot_id"], sent["target"]) == (1, 2, 6)
  30. def test_unload_of_a_loaded_ams_ht_addresses_its_unit():
  31. """tray_now 128 named ams_id 32, a unit the printer does not have."""
  32. client = _client(model="X1C")
  33. client.state.tray_now = 128
  34. assert client.ams_unload_filament() is True
  35. assert _sent(client)["ams_id"] == 128