Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: include default value in Color Switch CC mocks #7071

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/testing/src/CCSpecificCapabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export interface ConfigurationCCCapabilities {
}

export interface ColorSwitchCCCapabilities {
supportedColorComponents: ColorComponent[];
/** Supported colors and their default values */
colorComponents: Partial<Record<ColorComponent, number | undefined>>;
}

export interface NotificationCCCapabilities {
Expand Down
15 changes: 10 additions & 5 deletions packages/zwave-js/src/lib/node/mockCCBehaviors/ColorSwitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from "@zwave-js/testing";

const defaultCapabilities: ColorSwitchCCCapabilities = {
supportedColorComponents: [],
colorComponents: {},
};

const STATE_KEY_PREFIX = "ColorSwitch_";
Expand All @@ -37,7 +37,11 @@ const respondToColorSwitchSupportedGet: MockNodeBehavior = {
};
const cc = new ColorSwitchCCSupportedReport(self.host, {
nodeId: controller.host.ownNodeId,
supportedColorComponents: capabilities.supportedColorComponents,
supportedColorComponents: Object.keys(
capabilities.colorComponents,
).map(
(c) => parseInt(c),
),
});
return { action: "sendCC", cc };
}
Expand Down Expand Up @@ -69,12 +73,13 @@ const respondToColorSwitchGet: MockNodeBehavior = {
),
};
const component = receivedCC.colorComponent;
if (capabilities.supportedColorComponents.includes(component)) {
if (component in capabilities.colorComponents) {
const cc = new ColorSwitchCCReport(self.host, {
nodeId: controller.host.ownNodeId,
colorComponent: component,
currentValue:
(self.state.get(StateKeys.component(component))
?? capabilities.colorComponents[component]
?? 0) as number,
});
return { action: "sendCC", cc };
Expand All @@ -97,7 +102,7 @@ const respondToColorSwitchStartLevelChange: MockNodeBehavior = {
};

const component = receivedCC.colorComponent;
if (capabilities.supportedColorComponents.includes(component)) {
if (component in capabilities.colorComponents) {
// TODO: A proper simulation should gradually transition the value. We just set it to the target value.
self.state.set(
StateKeys.component(component),
Expand All @@ -124,7 +129,7 @@ const respondToColorSwitchStopLevelChange: MockNodeBehavior = {
};

const component = receivedCC.colorComponent;
if (capabilities.supportedColorComponents.includes(component)) {
if (component in capabilities.colorComponents) {
return { action: "ok" };
} else {
return { action: "fail" };
Expand Down
Loading