Skip to content

Commit

Permalink
feat: add compat flag to remove support of CCs (#1531)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Jan 30, 2021
1 parent d7d4848 commit 12b148f
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/development/config-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,27 @@ If a device does not report some CCs in its NIF, this can be used to add them. T
}
```

### `commandClasses.remove`

If a device reports support for a CCs but does not correctly support it, this can be used to remove them. This property has the following shape:

```json
"compat": {
"commandClasses": {
"remove": {
// Removes the CC Anti-Theft from the node and all endpoints
"0x5d": {
"endpoints": "*"
},
// Removes the CC Battery from the node (endpoint 0) and endpoint 2
"0x80": {
"endpoints": [0, 2]
}
}
}
}
```

### `disableBasicMapping`

By default, received `Basic` commands are mapped to a more appropriate CC. Setting `disableBasicMapping` to `true` disables this feature.
Expand Down
25 changes: 25 additions & 0 deletions maintenance/schemas/device-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,31 @@
}
},
"additionalProperties": false
},
"remove": {
"type": "object",
"patternProperties": {
"^(0x)?[0-9a-f]+$": {
"type": "object",
"properties": {
"endpoints": {
"anyOf": [
{ "const": "*" },
{
"type": "array",
"items": {
"type": "integer",
"minimum": 0
},
"minItems": 1
}
]
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
},
"additionalProperties": false
Expand Down
11 changes: 11 additions & 0 deletions packages/config/config/devices/0x000c/hs-wd200_0.0-5.9.json
Original file line number Diff line number Diff line change
Expand Up @@ -643,5 +643,16 @@
}
]
}
},
"compat": {
"commandClasses": {
"remove": {
"0x6c": {
// The device reports that it supports Supervision, but it does not support all
// commands supervision-encapsulated
"endpoints": "*"
}
}
}
}
}
11 changes: 11 additions & 0 deletions packages/config/config/devices/0x000c/hs-wd200_5.11.json
Original file line number Diff line number Diff line change
Expand Up @@ -643,5 +643,16 @@
}
]
}
},
"compat": {
"commandClasses": {
"remove": {
"0x6c": {
// The device reports that it supports Supervision, but it does not support all
// commands supervision-encapsulated
"endpoints": "*"
}
}
}
}
}
57 changes: 57 additions & 0 deletions packages/config/src/CompatConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,67 @@ All values in compat option commandClasses.add must be objects`,
}
this.addCCs = addCCs;
}

if (definition.commandClasses.remove != undefined) {
if (!isObject(definition.commandClasses.remove)) {
throwInvalidConfig(
"devices",
`config/devices/${filename}:
error in compat option commandClasses.remove`,
);
} else if (
!Object.keys(definition.commandClasses.remove).every((k) =>
hexKeyRegex2Digits.test(k),
)
) {
throwInvalidConfig(
"devices",
`config/devices/${filename}:
All keys in compat option commandClasses.remove must be 2-digit hex numbers!`,
);
}

const removeCCs = new Map<
CommandClasses,
"*" | readonly number[]
>();
for (const [cc, info] of Object.entries(
definition.commandClasses.remove,
)) {
if (isObject(info) && "endpoints" in info) {
if (
info.endpoints === "*" ||
(isArray(info.endpoints) &&
info.endpoints.every(
(i) => typeof i === "number",
))
) {
removeCCs.set(parseInt(cc), info.endpoints as any);
} else {
throwInvalidConfig(
"devices",
`config/devices/${filename}:
Compat option commandClasses.remove has an invalid "endpoints" property. Only "*" and numeric arrays are allowed!`,
);
}
} else {
throwInvalidConfig(
"devices",
`config/devices/${filename}:
All values in compat option commandClasses.remove must be objects with an "endpoints" property!`,
);
}
}
this.removeCCs = removeCCs;
}
}
}

public readonly addCCs?: ReadonlyMap<CommandClasses, CompatAddCC>;
public readonly removeCCs?: ReadonlyMap<
CommandClasses,
"*" | readonly number[]
>;
public readonly disableBasicMapping?: boolean;
public readonly overrideFloatEncoding?: {
size?: number;
Expand Down
15 changes: 15 additions & 0 deletions packages/zwave-js/src/lib/node/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,21 @@ version: ${this.version}`;
}
}
}
// And remove those that it marks as unsupported
const removeCCs = this.deviceConfig.compat?.removeCCs;
if (removeCCs) {
for (const [cc, endpoints] of removeCCs) {
if (endpoints === "*") {
for (const ep of this.getAllEndpoints()) {
ep.removeCC(cc);
}
} else {
for (const ep of endpoints) {
this.getEndpoint(ep)?.removeCC(cc);
}
}
}
}
}

await this.setInterviewStage(InterviewStage.OverwriteConfig);
Expand Down

0 comments on commit 12b148f

Please sign in to comment.