From d4a7504d67d0fafda5cf149142828d6b9f8739a7 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Wed, 7 Oct 2026 08:39:28 -0500 Subject: [PATCH] match index-less device strings to hardware units in the detection models picker A config with `edgetpu:usb` was reported as hardware that wasn't found, because the picker compared device strings exactly and the probe reports the unit as `edgetpu:usb:0`. A device without an index now resolves to the first unit of that kind, so the hardware dropdown, the unit checkboxes, and the model summary all recognize it. --- .../theme/fields/HardwarePicker.tsx | 9 ++++-- web/src/utils/detectionHardware.ts | 29 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) 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}.`), + ) + ); } /**