From f8f3b858dd796cd37f41b99617b546e8778ce042 Mon Sep 17 00:00:00 2001 From: AlCalzone Date: Wed, 17 Jul 2024 10:01:16 +0200 Subject: [PATCH] fix: unknown and unused specific device class (#7023) --- packages/core/src/registries/DeviceClasses.ts | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/packages/core/src/registries/DeviceClasses.ts b/packages/core/src/registries/DeviceClasses.ts index 0bc35b383d33..ce7a3660e3ed 100644 --- a/packages/core/src/registries/DeviceClasses.ts +++ b/packages/core/src/registries/DeviceClasses.ts @@ -7,19 +7,19 @@ export enum BasicDeviceClass { "Routing End Node" = 0x04, } -interface GenericDeviceClassDefinition { - readonly label: string; +interface DeviceClassProperties { readonly zwavePlusDeviceType?: string; readonly requiresSecurity?: boolean; readonly maySupportBasicCC?: boolean; +} + +interface GenericDeviceClassDefinition extends DeviceClassProperties { + readonly label: string; readonly specific: Record; } -interface SpecificDeviceClassDefinition { +interface SpecificDeviceClassDefinition extends DeviceClassProperties { readonly label: string; - readonly zwavePlusDeviceType?: string; - readonly requiresSecurity?: boolean; - readonly maySupportBasicCC?: boolean; } export interface GenericDeviceClass { @@ -506,13 +506,21 @@ export function getSpecificDeviceClass( ): SpecificDeviceClass { const genericClass: GenericDeviceClassDefinition | undefined = (deviceClasses as any)[generic]; - // @ts-expect-error We're in the false branch of the conditional type - if (!genericClass) return getUnknownSpecificDeviceClass(specific); + if (!genericClass) { + return getUnknownSpecificDeviceClass( + getUnknownGenericDeviceClass(generic), + specific, + ); + } const specificClass: SpecificDeviceClassDefinition | undefined = genericClass.specific[specific]; - // @ts-expect-error We're in the false branch of the conditional type - if (!specificClass) return getUnknownSpecificDeviceClass(specific); + if (!specificClass) { + return getUnknownSpecificDeviceClass( + genericClass, + specific, + ); + } return { key: specific, @@ -529,7 +537,7 @@ export function getSpecificDeviceClass( } function getUnknownSpecificDeviceClass( - genericClass: GenericDeviceClassDefinition, + genericClass: DeviceClassProperties, specific: number, ): SpecificDeviceClass { if (specific === 0) {