Skip to content

Commit

Permalink
fix: expose values for some controlled CCs (#1849)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Feb 23, 2021
1 parent 0ccf574 commit aff7946
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/zwave-js/src/lib/node/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,13 +604,21 @@ export class ZWaveNode extends Endpoint {
/** Returns a list of all value names that are defined on all endpoints of this node */
public getDefinedValueIDs(): TranslatedValueID[] {
let ret: ValueID[] = [];
const allowControlled: CommandClasses[] = [
CommandClasses["Scene Activation"],
];
for (const endpoint of this.getAllEndpoints()) {
for (const [cc, info] of endpoint.implementedCommandClasses) {
// Don't return value IDs which are only controlled
if (!info.isSupported) continue;
const ccInstance = endpoint.createCCInstanceUnsafe(cc);
if (ccInstance) {
ret.push(...ccInstance.getDefinedValueIDs());
// Only expose value IDs for CCs that are supported
// with some exceptions that are controlled
if (
info.isSupported ||
(info.isControlled && allowControlled.includes(cc))
) {
const ccInstance = endpoint.createCCInstanceUnsafe(cc);
if (ccInstance) {
ret.push(...ccInstance.getDefinedValueIDs());
}
}
}
}
Expand Down
38 changes: 38 additions & 0 deletions packages/zwave-js/src/lib/test/cc/sceneActivationValueID.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { CommandClasses } from "@zwave-js/core";
import type { ThrowingMap } from "../../controller/Controller";
import type { Driver } from "../../driver/Driver";
import { ZWaveNode } from "../../node/Node";
import { createAndStartDriver } from "../utils";

describe("regression tests", () => {
let driver: Driver;

beforeEach(async () => {
({ driver } = await createAndStartDriver());

driver["_controller"] = {
ownNodeId: 1,
isFunctionSupported: () => true,
nodes: new Map(),
} as any;
});

afterEach(async () => {
await driver.destroy();
driver.removeAllListeners();
});

it("a node that controls the Scene Activation CC should include the scene ID in getDefinedValueIDs()", async () => {
const node2 = new ZWaveNode(2, driver);
node2.addCC(CommandClasses["Scene Activation"], {
isControlled: true,
});
(driver.controller.nodes as ThrowingMap<number, ZWaveNode>).set(
2,
node2,
);

const valueIDs = node2.getDefinedValueIDs();
expect(valueIDs.some((v) => v.property === "sceneId")).toBeTrue();
});
});

0 comments on commit aff7946

Please sign in to comment.