Skip to content

Commit

Permalink
fix: unknown and unused specific device class (#7023)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Jul 17, 2024
1 parent e63cfae commit f8f3b85
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions packages/core/src/registries/DeviceClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number, SpecificDeviceClassDefinition>;
}

interface SpecificDeviceClassDefinition {
interface SpecificDeviceClassDefinition extends DeviceClassProperties {
readonly label: string;
readonly zwavePlusDeviceType?: string;
readonly requiresSecurity?: boolean;
readonly maySupportBasicCC?: boolean;
}

export interface GenericDeviceClass {
Expand Down Expand Up @@ -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,
Expand All @@ -529,7 +537,7 @@ export function getSpecificDeviceClass(
}

function getUnknownSpecificDeviceClass(
genericClass: GenericDeviceClassDefinition,
genericClass: DeviceClassProperties,
specific: number,
): SpecificDeviceClass {
if (specific === 0) {
Expand Down

0 comments on commit f8f3b85

Please sign in to comment.