From 4c151218a687186b630bf4e7baee45562b92d39b Mon Sep 17 00:00:00 2001 From: Ingo Fischer Date: Mon, 27 Jan 2025 16:21:20 +0100 Subject: [PATCH] Prefer the Preferred type --- README.md | 1 + src/main.ts | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2610c5c..c4d907c 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ With the ioBroker Matter Adapter, it is possible to map the following use cases: ### __WORK IN PROGRESS__ * (@Apollon77) Fixed Thermostat limit initialization and Mode error * (@Apollon77) Fixed Matter Event handling when mapped to an ioBroker state (e.g.GenericSwitch) +* (@Apollon77) Fixed Device type detection by really preferring the preferred type ### 0.4.9 (2025-01-26) * (@Apollon77) Enhanced error and invalid devices display for UI diff --git a/src/main.ts b/src/main.ts index 8a4276e..b01eba3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -83,7 +83,6 @@ export class MatterAdapter extends utils.Adapter { readonly #bridges = new Map(); #controller?: MatterController; #sendControllerUpdateTimeout?: NodeJS.Timeout; - #detector: ChannelDetector; #_guiSubscribes: { clientId: string; ts: number }[] | null = null; readonly #matterEnvironment: Environment; #stateTimeout?: NodeJS.Timeout; @@ -130,7 +129,6 @@ export class MatterAdapter extends utils.Adapter { this.#deviceManagement = new MatterAdapterDeviceManagement(this); this.#matterEnvironment = Environment.default; - this.#detector = new ChannelDetector(); this.t = (word: string, ..._args: (string | number | boolean | null)[]): string => word; this.getText = (_word: string, ..._args: (string | number | boolean | null)[]): ioBroker.Translated => ({}) as ioBroker.Translated; @@ -813,8 +811,16 @@ export class MatterAdapter extends utils.Adapter { _usedIdsOptional: usedIds, ignoreIndicators, excludedTypes: [Types.info], + allowedTypes: preferredType ? [preferredType as Types] : undefined, + //ignoreCache: true }; - const controls = this.#detector.detect(options); + + const detector = new ChannelDetector(); + let controls = detector.detect(options); + if (!controls?.length) { + delete options.allowedTypes; + controls = detector.detect(options); + } if (controls?.length) { let controlsToCheck = controls.filter((control: PatternControl) => control.states.some(({ id: foundId }) => foundId === id),