update_hms_actions.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import asyncio
  2. import json
  3. import requests
  4. HMS_ACTIONS_JSON_PATH = "backend/app/data/hms_actions.json"
  5. HMS_REQUEST_URL = "https://e.bambulab.com/hms/GetActionImage.php"
  6. HMS_ID_TO_ACTION_NAME_MAP: dict[int, str] = {
  7. 2: "RESUME_PRINTING",
  8. 3: "RESUME_PRINTING_DEFECTS",
  9. 4: "RESUME_PRINTING_PROBELM_SOLVED",
  10. 5: "STOP_PRINTING",
  11. 6: "CHECK_ASSISTANT",
  12. 7: "FILAMENT_EXTRUDED",
  13. 8: "RETRY_FILAMENT_EXTRUDED",
  14. 9: "CONTINUE",
  15. 10: "LOAD_VIRTUAL_TRAY",
  16. 11: "OK_BUTTON",
  17. 12: "FILAMENT_LOAD_RESUME",
  18. 13: "JUMP_TO_LIVEVIEW",
  19. 23: "NO_REMINDER_NEXT_TIME",
  20. 24: "REFRESH_NOZZLE",
  21. 25: "IGNORE_NO_REMINDER_NEXT_TIME",
  22. 27: "IGNORE_RESUME",
  23. 28: "PROBLEM_SOLVED_RESUME",
  24. 29: "TURN_OFF_FIRE_ALARM",
  25. 34: "RETRY_PROBLEM_SOLVED",
  26. 35: "STOP_DRYING",
  27. 37: "CANCLE", # Note: "CANCLE" is intentionally misspelled in the BambuStudio source code
  28. 39: "REMOVE_CLOSE_BTN",
  29. 41: "PROCEED",
  30. 49: "OK_JUMP_RACK",
  31. 51: "ABORT",
  32. 54: "DISABLE_PURIFICATION",
  33. 57: "DONT_REMIND_NEXT_TIME",
  34. 10000: "DBL_CHECK_CANCEL",
  35. 10001: "DBL_CHECK_DONE",
  36. 10002: "DBL_CHECK_RETRY",
  37. 10003: "DBL_CHECK_RESUME",
  38. 10004: "DBL_CHECK_OK",
  39. }
  40. async def main():
  41. error_to_action_map: dict[str, list[str]] = {}
  42. # get the json response from the url
  43. response = requests.get(HMS_REQUEST_URL)
  44. if response.status_code == 200:
  45. data = response.json()
  46. ready_data = {}
  47. for item in data["data"]:
  48. # error_code = item["ecode"][:4] + "_" + item["ecode"][4:]
  49. mapped_actions = []
  50. for hms_id in item["actions"]:
  51. if hms_id not in HMS_ID_TO_ACTION_NAME_MAP:
  52. print(f"Warning: Unrecognized HMS action ID {hms_id} for error code {item['ecode']}")
  53. else:
  54. mapped_actions.append(HMS_ID_TO_ACTION_NAME_MAP.get(hms_id, f"UNKNOWN_ACTION_{hms_id}"))
  55. print(f"ecode: {item['ecode']}, actions: {mapped_actions}, device: {item['device']}")
  56. if item["device"] not in ready_data:
  57. ready_data[item["device"]] = {}
  58. ready_data[item["device"]][item["ecode"]] = mapped_actions
  59. # ready_data.append(
  60. # {
  61. # "ecode": item["ecode"],
  62. # "actions": mapped_actions,
  63. # "device": item["device"],
  64. # }
  65. # )
  66. with open(HMS_ACTIONS_JSON_PATH, "w") as f:
  67. json.dump(ready_data, f, indent=4)
  68. else:
  69. print("Failed to fetch data")
  70. print(error_to_action_map)
  71. # autogenerate
  72. if __name__ == "__main__":
  73. asyncio.run(main())