Skip to content

Commit

Permalink
refactor: move device classes from config into code
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Jun 13, 2024
1 parent ae9d458 commit 445a887
Show file tree
Hide file tree
Showing 18 changed files with 660 additions and 966 deletions.
26 changes: 0 additions & 26 deletions docs/api/config-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,32 +55,6 @@ Looks up the property definition for a given indicator property id

> [!NOTE] `loadIndicators` must be used first.
### `loadDeviceClasses`

```ts
loadDeviceClasses(): Promise<void>;
```

Loads the device classes config which is used to lookup basic, generic and specific device classes.

### `lookupBasicDeviceClass`

```ts
lookupBasicDeviceClass(basic: number): BasicDeviceClass;
```

### `lookupGenericDeviceClass`

```ts
lookupGenericDeviceClass(generic: number): GenericDeviceClass;
```

### `lookupSpecificDeviceClass`

```ts
lookupSpecificDeviceClass(generic: number, specific: number): SpecificDeviceClass;
```

### `loadDeviceIndex`

```ts
Expand Down
66 changes: 30 additions & 36 deletions packages/cc/src/cc/MultiChannelCC.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import type { GenericDeviceClass, SpecificDeviceClass } from "@zwave-js/config";
import {
type ApplicationNodeInformation,
CommandClasses,
type GenericDeviceClass,
type IZWaveNode,
type MaybeNotKnown,
type MessageOrCCLogEntry,
MessagePriority,
type MessageRecord,
type SpecificDeviceClass,
ZWaveError,
ZWaveErrorCodes,
encodeApplicationNodeInformation,
encodeBitMask,
getCCName,
getGenericDeviceClass,
getSpecificDeviceClass,
parseApplicationNodeInformation,
parseBitMask,
validatePayload,
Expand Down Expand Up @@ -248,15 +251,13 @@ export class MultiChannelCCAPI extends CCAPI {
this.commandOptions,
);
if (response) {
const generic = this.applHost.configManager
.lookupGenericDeviceClass(
response.genericDeviceClass,
);
const specific = this.applHost.configManager
.lookupSpecificDeviceClass(
response.genericDeviceClass,
response.specificDeviceClass,
);
const generic = getGenericDeviceClass(
response.genericDeviceClass,
);
const specific = getSpecificDeviceClass(
response.genericDeviceClass,
response.specificDeviceClass,
);
return {
isDynamic: response.isDynamic,
wasRemoved: response.wasRemoved,
Expand Down Expand Up @@ -968,19 +969,17 @@ export class MultiChannelCCCapabilityReport extends MultiChannelCC
}

public toLogEntry(applHost: ZWaveApplicationHost): MessageOrCCLogEntry {
const generic = applHost.configManager.lookupGenericDeviceClass(
this.genericDeviceClass,
);
const specific = applHost.configManager.lookupSpecificDeviceClass(
this.genericDeviceClass,
this.specificDeviceClass,
);
return {
...super.toLogEntry(applHost),
message: {
"endpoint index": this.endpointIndex,
"generic device class": generic.label,
"specific device class": specific.label,
"generic device class": getGenericDeviceClass(
this.genericDeviceClass,
).label,
"specific device class": getSpecificDeviceClass(
this.genericDeviceClass,
this.specificDeviceClass,
).label,
"is dynamic end point": this.isDynamic,
"supported CCs": this.supportedCCs
.map((cc) => `\n· ${getCCName(cc)}`)
Expand Down Expand Up @@ -1120,15 +1119,13 @@ export class MultiChannelCCEndPointFindReport extends MultiChannelCC {
return {
...super.toLogEntry(applHost),
message: {
"generic device class":
applHost.configManager.lookupGenericDeviceClass(
this.genericClass,
).label,
"specific device class":
applHost.configManager.lookupSpecificDeviceClass(
this.genericClass,
this.specificClass,
).label,
"generic device class": getGenericDeviceClass(
this.genericClass,
).label,
"specific device class": getSpecificDeviceClass(
this.genericClass,
this.specificClass,
).label,
"found endpoints": this.foundEndpoints.join(", "),
"# of reports to follow": this.reportsToFollow,
},
Expand Down Expand Up @@ -1175,14 +1172,11 @@ export class MultiChannelCCEndPointFind extends MultiChannelCC {
...super.toLogEntry(applHost),
message: {
"generic device class":
applHost.configManager.lookupGenericDeviceClass(
this.genericClass,
).label,
"specific device class":
applHost.configManager.lookupSpecificDeviceClass(
this.genericClass,
this.specificClass,
).label,
getGenericDeviceClass(this.genericClass).label,
"specific device class": getSpecificDeviceClass(
this.genericClass,
this.specificClass,
).label,
},
};
}
Expand Down
Loading

0 comments on commit 445a887

Please sign in to comment.