printer_models.py 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. """Printer model normalization utilities.
  2. Converts 3MF printer model names (e.g., "Bambu Lab X1 Carbon") to
  3. normalized short names (e.g., "X1C") that match database storage.
  4. """
  5. # Map from 3MF printer_model strings to normalized short names
  6. PRINTER_MODEL_MAP = {
  7. "Bambu Lab X1 Carbon": "X1C",
  8. "Bambu Lab X1": "X1",
  9. "Bambu Lab X1E": "X1E",
  10. "Bambu Lab P1S": "P1S",
  11. "Bambu Lab P1P": "P1P",
  12. "Bambu Lab P2S": "P2S",
  13. "Bambu Lab A1": "A1",
  14. "Bambu Lab A1 Mini": "A1 Mini",
  15. "Bambu Lab A1 mini": "A1 Mini",
  16. # Bambu cloud rolled out a terse model-code rename mid-2026 (#1649);
  17. # 3MFs prepared with newer cloud presets may carry this short form.
  18. "Bambu Lab A1M": "A1 Mini",
  19. "Bambu Lab H2D": "H2D",
  20. "Bambu Lab H2D Pro": "H2D Pro",
  21. "Bambu Lab H2C": "H2C",
  22. "Bambu Lab H2S": "H2S",
  23. "Bambu Lab X2D": "X2D",
  24. }
  25. # Map from printer_model_id (internal codes in slice_info.config) to short names
  26. # These are the codes Bambu Studio uses internally
  27. PRINTER_MODEL_ID_MAP = {
  28. # X1 series
  29. "C11": "X1C",
  30. "C12": "X1",
  31. "C13": "X1E",
  32. # P1 series
  33. "P1P": "P1P",
  34. "P1S": "P1S",
  35. # P2 series
  36. "P2S": "P2S",
  37. # X2 series
  38. "N6": "X2D",
  39. # A1 series
  40. "A11": "A1",
  41. "A12": "A1 Mini",
  42. "N1": "A1 Mini",
  43. "N2S": "A1",
  44. "A04": "A1 Mini",
  45. # H2 series (Office/H series)
  46. "O1D": "H2D",
  47. "O1E": "H2D Pro", # Some devices report O1E
  48. "O2D": "H2D Pro", # Some devices report O2D
  49. "O1C": "H2C",
  50. "O1C2": "H2C",
  51. "O1S": "H2S",
  52. }
  53. # Rod/rail type classification for maintenance tasks.
  54. # Carbon rods: X1, P1 series (CoreXY with carbon fiber rods)
  55. # Steel rods: P2S, X2D series (hardened steel linear shafts)
  56. # Linear rails: A1, H2 series (linear rail motion system)
  57. # Values must be uppercase with spaces stripped for normalized comparison.
  58. CARBON_ROD_MODELS = frozenset(
  59. [
  60. # Display names (uppercase, no spaces)
  61. "X1",
  62. "X1C",
  63. "X1E",
  64. "P1P",
  65. "P1S",
  66. # Internal codes
  67. "C11", # X1C
  68. "C12", # X1
  69. "C13", # X1E
  70. ]
  71. )
  72. STEEL_ROD_MODELS = frozenset(
  73. [
  74. # Display names (uppercase, no spaces)
  75. "P2S",
  76. "X2D",
  77. # Internal codes
  78. "N7", # P2S
  79. "N6", # X2D
  80. ]
  81. )
  82. LINEAR_RAIL_MODELS = frozenset(
  83. [
  84. # Display names (uppercase, no spaces)
  85. "A1",
  86. "A1MINI",
  87. "H2D",
  88. "H2DPRO",
  89. "H2C",
  90. "H2S",
  91. # Internal codes
  92. "N1", # A1 Mini
  93. "N2S", # A1
  94. "A04", # A1 Mini (alternate)
  95. "A11", # A1
  96. "A12", # A1 Mini
  97. "O1D", # H2D
  98. "O1E", # H2D Pro
  99. "O2D", # H2D Pro (alternate)
  100. "O1C", # H2C
  101. "O1C2", # H2C (dual nozzle variant)
  102. "O1S", # H2S
  103. ]
  104. )
  105. # Models without any external storage (MicroSD / SD card slot).
  106. # The A1 and A1 Mini ship with internal storage only — there is no
  107. # firmware-side "Store sent files on external storage" toggle and no
  108. # slicer-side equivalent surfaces one. The connection diagnostic's
  109. # external_storage check (printer_diagnostic.py) must skip on these
  110. # models instead of reporting fail from a 0-valued home_flag bit.
  111. NO_EXTERNAL_STORAGE_MODELS = frozenset(
  112. [
  113. # Display names (uppercase, no spaces)
  114. "A1",
  115. "A1MINI",
  116. # Internal codes
  117. "N1", # A1 Mini
  118. "N2S", # A1
  119. "A04", # A1 Mini (alternate)
  120. "A11", # A1
  121. "A12", # A1 Mini
  122. ]
  123. )
  124. # Models with an ethernet port.
  125. # X1, P1P, A1, A1 Mini do NOT have ethernet.
  126. ETHERNET_MODELS = frozenset(
  127. [
  128. # Display names (uppercase, no spaces)
  129. "X1C",
  130. "X1E",
  131. "X2D",
  132. "P1S",
  133. "P2S",
  134. "H2D",
  135. "H2DPRO",
  136. "H2C",
  137. "H2S",
  138. # Internal codes
  139. "C11", # X1C
  140. "C13", # X1E
  141. "N6", # X2D
  142. "P1S", # P1S
  143. "O1D", # H2D
  144. "O1E", # H2D Pro
  145. "O2D", # H2D Pro (alternate)
  146. "O1C", # H2C
  147. "O1C2", # H2C (dual nozzle variant)
  148. "O1S", # H2S
  149. ]
  150. )
  151. # Dual-nozzle (dual-extruder) printers. Single source of truth for nozzle
  152. # class — consumed by ``BambuMQTTClient.start_print``, the K-profile routes,
  153. # and the re-slice nozzle-class guard (previously an inline model tuple
  154. # duplicated across all three). Re-slicing a model laid out for a single-nozzle
  155. # printer onto one of these — or vice versa — is not yet supported: the source
  156. # 3MF's embedded single-nozzle filament/extruder layout is not a valid
  157. # dual-nozzle project and BambuStudio's multi-extruder validator rejects it.
  158. DUAL_NOZZLE_MODELS = frozenset(
  159. [
  160. # Display names (uppercase, no spaces)
  161. "H2D",
  162. "H2DPRO",
  163. "H2C",
  164. "X2D",
  165. # Internal codes
  166. "O1D", # H2D
  167. "O1E", # H2D Pro
  168. "O2D", # H2D Pro (alternate)
  169. "O1C", # H2C
  170. "O1C2", # H2C (dual nozzle variant)
  171. "N6", # X2D
  172. ]
  173. )
  174. def has_ethernet(model: str | None) -> bool:
  175. """Return True if the printer model has an ethernet port."""
  176. if not model:
  177. return False
  178. normalized = model.strip().upper().replace(" ", "").replace("-", "")
  179. return normalized in ETHERNET_MODELS
  180. def has_external_storage(model: str | None) -> bool:
  181. """Return True if the printer model can have a MicroSD / external storage slot.
  182. Defaults to True when the model is unknown — the diagnostic only flips
  183. its check on for the explicit no-storage list. New models added to the
  184. Bambu lineup without a slot must be added to ``NO_EXTERNAL_STORAGE_MODELS``
  185. or the diagnostic will continue to evaluate ``store_to_sdcard`` against
  186. a hardware feature the printer doesn't have.
  187. """
  188. if not model:
  189. return True
  190. normalized = model.strip().upper().replace(" ", "").replace("-", "")
  191. return normalized not in NO_EXTERNAL_STORAGE_MODELS
  192. def is_dual_nozzle_model(model: str | None) -> bool:
  193. """Return True if the printer model has two nozzles (H2D family / X2D)."""
  194. if not model:
  195. return False
  196. normalized = model.strip().upper().replace(" ", "").replace("-", "")
  197. return normalized in DUAL_NOZZLE_MODELS
  198. def get_rod_type(model: str | None) -> str | None:
  199. """Return the rod/rail type for a printer model.
  200. Returns:
  201. "carbon" for X1/P1 series (carbon fiber rods),
  202. "steel_rod" for P2S/X2D series (hardened steel rods),
  203. "linear_rail" for A1/H2 series (linear rails),
  204. None for unknown models.
  205. """
  206. if not model:
  207. return None
  208. normalized = model.strip().upper().replace(" ", "").replace("-", "")
  209. if normalized in CARBON_ROD_MODELS:
  210. return "carbon"
  211. if normalized in STEEL_ROD_MODELS:
  212. return "steel_rod"
  213. if normalized in LINEAR_RAIL_MODELS:
  214. return "linear_rail"
  215. return None
  216. def normalize_printer_model_id(model_id: str | None) -> str | None:
  217. """Convert printer_model_id (internal code) to normalized short name.
  218. Args:
  219. model_id: The printer_model_id from slice_info.config (e.g., "C11", "O1D")
  220. Returns:
  221. Normalized short name (e.g., "X1C", "H2D") or the original ID if unknown.
  222. """
  223. if not model_id:
  224. return None
  225. # Check known mappings
  226. if model_id in PRINTER_MODEL_ID_MAP:
  227. return PRINTER_MODEL_ID_MAP[model_id]
  228. # Return original if unknown (might already be a short name)
  229. return model_id
  230. def normalize_printer_model(raw_model: str | None) -> str | None:
  231. """Convert 3MF printer_model to normalized short name.
  232. Args:
  233. raw_model: The printer_model string from 3MF metadata
  234. (e.g., "Bambu Lab X1 Carbon")
  235. Returns:
  236. Normalized short name (e.g., "X1C") or None if input is empty.
  237. Unknown models have "Bambu Lab " prefix stripped.
  238. """
  239. if not raw_model:
  240. return None
  241. # Check known mappings first
  242. if raw_model in PRINTER_MODEL_MAP:
  243. return PRINTER_MODEL_MAP[raw_model]
  244. # Strip "Bambu Lab " prefix for unknown models
  245. stripped = raw_model.replace("Bambu Lab ", "").strip()
  246. return stripped or None