Files
bambuddy/frontend/src/utils/dryingPresets.ts
T
maziggy 1eea194953 Resolve a spool's material to a known drying preset before starting a cycle (#2774)
The drying popover prefilled its material from the loaded spool without
checking the preset table had that material. An AMS-HT holding Support for
PLA/PETG (tray_type PLA-S) fell back to PLA's temperature but kept PLA-S as
the material, and the dropdown displays its first option when handed a value
outside its list -- so it read PLA while PLA-S was sent. Same gap for every
composite: PETG-CF prefilled at PLA's 45C.

Resolve the tray_type to a key the table has before setting either value.
Support materials and composites resolve to their base, nylon is aliased
under its several spellings, and anything unrecognised falls back to PLA --
the coolest row, so an unknown material under-dries rather than deforming a
PLA spool.

Also record request-topic messages in the MQTT debug log. That topic carries
every command a printer is given, including Bambu Studio's, and returned
before the logging block -- so a capture could show only what the printer
said, never what it was told.
2026-08-06 08:19:01 +02:00

46 lines
2.0 KiB
TypeScript

// Resolving an AMS tray's material to a row in the drying preset table.
//
// The table itself lives with the UI that renders it; only the lookup is here,
// so it can be exercised without dragging a page module into the test.
export type DryingPreset = { n3f: number; n3s: number; n3f_hours: number; n3s_hours: number };
// Materials whose AMS spelling differs from the preset table's key. Bambu
// labels nylon "PA" while its own composites spell the family out, so PA6 and
// PAHT would otherwise miss a table that has a perfectly good PA row.
const DRYING_MATERIAL_ALIASES: Record<string, string> = {
'NYLON': 'PA',
'PA6': 'PA',
'PAHT': 'PA',
};
/**
* Pick the preset key for a tray's material.
*
* The answer is always a key the table actually has, which is the whole point:
* the drying popover seeds both the temperature and the filament name the start
* command carries from this, and the dropdown silently falls back to its first
* option when handed a value that isn't in its list. Seeding it with a raw
* `tray_type` therefore displayed "PLA" while sending the raw string -- an
* AMS-HT holding Support for PLA/PETG (`tray_type` "PLA-S") showed PLA in the
* dropdown and told the printer PLA-S (#2774).
*
* `tray_type` carries plenty of spellings the table doesn't list: support
* materials (PLA-S) and composites (PETG-CF, PLA-CF, ABS-GF, PAHT-CF) all dry
* as their base material, so the suffix is dropped before giving up. Anything
* still unrecognised lands on PLA, deliberately the coolest row -- under-drying
* an exotic filament wastes a cycle, where defaulting to PA's 85 degrees would
* deform a PLA spool.
*/
export function resolveDryingPresetKey(
trayType: string | null | undefined,
presets: Record<string, DryingPreset>,
): string {
const raw = (trayType || '').split(' ')[0].toUpperCase();
for (const candidate of [raw, raw.split('-')[0]]) {
const key = DRYING_MATERIAL_ALIASES[candidate] ?? candidate;
if (presets[key]) return key;
}
return 'PLA';
}