dryingPresets.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Resolving an AMS tray's material to a row in the drying preset table.
  2. //
  3. // The table itself lives with the UI that renders it; only the lookup is here,
  4. // so it can be exercised without dragging a page module into the test.
  5. export type DryingPreset = { n3f: number; n3s: number; n3f_hours: number; n3s_hours: number };
  6. // Materials whose AMS spelling differs from the preset table's key. Bambu
  7. // labels nylon "PA" while its own composites spell the family out, so PA6 and
  8. // PAHT would otherwise miss a table that has a perfectly good PA row.
  9. //
  10. // Kept in step with FILAMENT_KEY_ALIASES in backend/app/services/print_scheduler.py,
  11. // which the auto-drying scheduler reads. The two disagreeing is what #3067 was:
  12. // this popover dried a PA6-CF spool on request while the scheduler passed over
  13. // the same AMS on every sweep.
  14. const DRYING_MATERIAL_ALIASES: Record<string, string> = {
  15. 'NYLON': 'PA',
  16. 'PA6': 'PA',
  17. 'PA11': 'PA',
  18. 'PA12': 'PA',
  19. 'PAHT': 'PA',
  20. 'PPA': 'PA',
  21. };
  22. /**
  23. * Pick the preset key for a tray's material.
  24. *
  25. * The answer is always a key the table actually has, which is the whole point:
  26. * the drying popover seeds both the temperature and the filament name the start
  27. * command carries from this, and the dropdown silently falls back to its first
  28. * option when handed a value that isn't in its list. Seeding it with a raw
  29. * `tray_type` therefore displayed "PLA" while sending the raw string -- an
  30. * AMS-HT holding Support for PLA/PETG (`tray_type` "PLA-S") showed PLA in the
  31. * dropdown and told the printer PLA-S (#2774).
  32. *
  33. * `tray_type` carries plenty of spellings the table doesn't list: support
  34. * materials (PLA-S) and composites (PETG-CF, PLA-CF, ABS-GF, PAHT-CF) all dry
  35. * as their base material, so the suffix is dropped before giving up. Anything
  36. * still unrecognised lands on PLA, deliberately the coolest row -- under-drying
  37. * an exotic filament wastes a cycle, where defaulting to PA's 85 degrees would
  38. * deform a PLA spool.
  39. */
  40. export function resolveDryingPresetKey(
  41. trayType: string | null | undefined,
  42. presets: Record<string, DryingPreset>,
  43. ): string {
  44. const raw = (trayType || '').split(' ')[0].toUpperCase();
  45. for (const candidate of [raw, raw.split('-')[0]]) {
  46. const key = DRYING_MATERIAL_ALIASES[candidate] ?? candidate;
  47. if (presets[key]) return key;
  48. }
  49. return 'PLA';
  50. }