diff --git a/web/src/components/config-form/theme/fields/HardwarePicker.tsx b/web/src/components/config-form/theme/fields/HardwarePicker.tsx index fb2bcb72ef..1ee1a12867 100644 --- a/web/src/components/config-form/theme/fields/HardwarePicker.tsx +++ b/web/src/components/config-form/theme/fields/HardwarePicker.tsx @@ -15,6 +15,7 @@ import { hardwareForDevices, MAX_DETECTORS, recommendedDetectorCount, + resolveUnitDevice, } from "@/utils/detectionHardware"; type HardwarePickerProps = { @@ -60,9 +61,13 @@ export function HardwarePicker({ return []; } + const assigned = devices.map((device) => + resolveUnitDevice(selected, device), + ); + return selected.units .map((unit) => unit.device) - .filter((device) => devices.includes(device)); + .filter((device) => assigned.includes(device)); }, [selected, devices]); /** Spread `count` detectors round robin over the selected units. */ @@ -200,7 +205,7 @@ export function HardwarePicker({ handleUnitToggle(unit.device, checked === true) diff --git a/web/src/utils/detectionHardware.ts b/web/src/utils/detectionHardware.ts index 622cf4f184..bf7676604f 100644 --- a/web/src/utils/detectionHardware.ts +++ b/web/src/utils/detectionHardware.ts @@ -21,10 +21,31 @@ export function hardwareForDevices( return undefined; } - return hardware.find((entry) => { - const known = new Set(entry.units.map((unit) => unit.device)); - return devices.every((device) => known.has(device)); - }); + return hardware.find((entry) => + devices.every((device) => resolveUnitDevice(entry, device)), + ); +} + +/** + * The unit device string a configured device refers to. + * + * A config may leave the index off, such as "edgetpu:usb", which the detector + * resolves to the first unit of that kind. + */ +export function resolveUnitDevice( + entry: DetectionHardware, + device: string, +): string | undefined { + const unitDevices = entry.units.map((unit) => unit.device); + + return ( + unitDevices.find((candidate) => candidate === device) ?? + unitDevices.find( + (candidate) => + candidate.startsWith(`${device}:`) || + candidate.startsWith(`${device}.`), + ) + ); } /**