mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-10-07 23:32:48 +03:00
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.
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
|||||||
hardwareForDevices,
|
hardwareForDevices,
|
||||||
MAX_DETECTORS,
|
MAX_DETECTORS,
|
||||||
recommendedDetectorCount,
|
recommendedDetectorCount,
|
||||||
|
resolveUnitDevice,
|
||||||
} from "@/utils/detectionHardware";
|
} from "@/utils/detectionHardware";
|
||||||
|
|
||||||
type HardwarePickerProps = {
|
type HardwarePickerProps = {
|
||||||
@@ -60,9 +61,13 @@ export function HardwarePicker({
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const assigned = devices.map((device) =>
|
||||||
|
resolveUnitDevice(selected, device),
|
||||||
|
);
|
||||||
|
|
||||||
return selected.units
|
return selected.units
|
||||||
.map((unit) => unit.device)
|
.map((unit) => unit.device)
|
||||||
.filter((device) => devices.includes(device));
|
.filter((device) => assigned.includes(device));
|
||||||
}, [selected, devices]);
|
}, [selected, devices]);
|
||||||
|
|
||||||
/** Spread `count` detectors round robin over the selected units. */
|
/** Spread `count` detectors round robin over the selected units. */
|
||||||
@@ -200,7 +205,7 @@ export function HardwarePicker({
|
|||||||
<Checkbox
|
<Checkbox
|
||||||
id={`${idPrefix}-${unit.device}`}
|
id={`${idPrefix}-${unit.device}`}
|
||||||
className="size-5 text-white accent-white data-[state=checked]:bg-selected data-[state=checked]:text-white"
|
className="size-5 text-white accent-white data-[state=checked]:bg-selected data-[state=checked]:text-white"
|
||||||
checked={devices.includes(unit.device)}
|
checked={selectedUnits.includes(unit.device)}
|
||||||
disabled={disabled || Boolean(claimedBy)}
|
disabled={disabled || Boolean(claimedBy)}
|
||||||
onCheckedChange={(checked) =>
|
onCheckedChange={(checked) =>
|
||||||
handleUnitToggle(unit.device, checked === true)
|
handleUnitToggle(unit.device, checked === true)
|
||||||
|
|||||||
@@ -21,10 +21,31 @@ export function hardwareForDevices(
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return hardware.find((entry) => {
|
return hardware.find((entry) =>
|
||||||
const known = new Set(entry.units.map((unit) => unit.device));
|
devices.every((device) => resolveUnitDevice(entry, device)),
|
||||||
return devices.every((device) => known.has(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}.`),
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user