test_ams_lite_version_info_3348.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. """The AMS Lite gets its serial number and firmware from get_version (#3348).
  2. Like every AMS, the AMS Lite reports both only in the printer's get_version
  3. answer, as a module of its own: "ams_f1/<id>". That prefix was not recognised,
  4. so the module was skipped and the unit showed neither. The module names and
  5. fields below are from real A1 and A2L captures (ha-bambulab mock data). The
  6. A2L reports its AMS Lite as unit 16, which is stored as 6.
  7. """
  8. import pytest
  9. from backend.app.services.bambu_mqtt import BambuMQTTClient
  10. @pytest.fixture
  11. def client():
  12. return BambuMQTTClient(ip_address="192.168.1.100", serial_number="TESTAMSLITE", access_code="12345678")
  13. def _version(name, sw_ver="00.00.07.94", sn="AMSLITE0001"):
  14. return {
  15. "command": "get_version",
  16. "module": [
  17. {"name": "ota", "sw_ver": "01.08.01.00"},
  18. {"name": name, "sw_ver": sw_ver, "hw_ver": "AMS_F102", "sn": sn},
  19. ],
  20. }
  21. def _push(unit_id):
  22. return {"ams": [{"id": str(unit_id), "tray": [{"id": "0"}, {"id": "1"}, {"id": "2"}, {"id": "3"}]}]}
  23. def _unit(client, unit_id):
  24. return next(u for u in client.state.raw_data["ams"] if int(u["id"]) == unit_id)
  25. @pytest.mark.parametrize(("module", "pushed_id", "stored_id"), [("ams_f1/0", 0, 0), ("ams_f1/16", 16, 6)])
  26. class TestAmsLite:
  27. def test_version_after_the_ams_push(self, client, module, pushed_id, stored_id):
  28. client._handle_ams_data(_push(pushed_id))
  29. client._handle_version_info(_version(module))
  30. unit = _unit(client, stored_id)
  31. assert (unit["sn"], unit["sw_ver"], unit["module_type"]) == ("AMSLITE0001", "00.00.07.94", "ams_f1")
  32. def test_version_before_the_first_ams_push(self, client, module, pushed_id, stored_id):
  33. client._handle_version_info(_version(module))
  34. client._handle_ams_data(_push(pushed_id))
  35. unit = _unit(client, stored_id)
  36. assert (unit["sn"], unit["sw_ver"]) == ("AMSLITE0001", "00.00.07.94")
  37. def test_no_missing_version_warning(self, client, module, pushed_id, stored_id, caplog):
  38. client._handle_ams_data(_push(pushed_id))
  39. client._handle_version_info(_version(module))
  40. assert "not available in version info" not in caplog.text
  41. def test_other_ams_modules_are_unchanged(client):
  42. client._handle_ams_data(
  43. {"ams": [{"id": "0", "tray": []}, {"id": "128", "tray": []}]},
  44. )
  45. client._handle_version_info(
  46. {
  47. "module": [
  48. {"name": "n3f/0", "sw_ver": "03.00.21.29", "sn": "N3F0001"},
  49. {"name": "n3s/128", "sw_ver": "03.00.21.30", "sn": "N3S0001"},
  50. ]
  51. }
  52. )
  53. assert (_unit(client, 0)["sn"], _unit(client, 0)["module_type"]) == ("N3F0001", "n3f")
  54. assert (_unit(client, 128)["sn"], _unit(client, 128)["module_type"]) == ("N3S0001", "n3s")