printer_models.py 8.1 KB

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