feat(devicemanager): add selector-based device APIs, selectFeature helper, convenience discovery methods, and ESCL scan completion fallback

This commit is contained in:
2026-01-09 17:18:48 +00:00
parent d72ea96ec5
commit 82a99cdfb8
6 changed files with 224 additions and 6 deletions

View File

@@ -246,12 +246,35 @@ export class UniversalDevice extends plugins.events.EventEmitter {
}
/**
* Get a feature by type
* Get a feature by type (returns undefined if not available)
*/
public getFeature<T extends Feature>(type: TFeatureType): T | undefined {
return this._features.get(type) as T | undefined;
}
/**
* Select a feature by type (throws if not available).
* Use this when you expect the device to have this feature and want fail-fast behavior.
*
* @param type The feature type to select
* @returns The feature instance
* @throws Error if the device does not have this feature
*
* @example
* ```typescript
* const scanFeature = device.selectFeature<ScanFeature>('scan');
* await scanFeature.connect();
* const result = await scanFeature.scan({ source: 'flatbed' });
* ```
*/
public selectFeature<T extends Feature>(type: TFeatureType): T {
const feature = this._features.get(type) as T | undefined;
if (!feature) {
throw new Error(`Device '${this.name}' does not have feature '${type}'`);
}
return feature;
}
/**
* Get all features
*/