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

Support get_raw_config_parameter_value #1300

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 26 additions & 3 deletions src/lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ import {
ControllerFirmwareUpdateResult,
Endpoint,
FirmwareUpdateResult,
ConfigValue,
SetValueResult,
SetValueStatus,
ZWaveNode,
} from "zwave-js";
import type { ConfigurationCCAPISetOptions } from "@zwave-js/cc";
import { SupervisionResult } from "@zwave-js/core";
import { IncomingCommandNodeSetRawConfigParameterValue } from "./node/incoming_message";
import { IncomingCommandEndpointSetRawConfigParameterValue } from "./endpoint/incoming_message";
import { SupervisionResult, MaybeNotKnown } from "@zwave-js/core";
import {
IncomingCommandNodeGetRawConfigParameterValue,
IncomingCommandNodeSetRawConfigParameterValue,
} from "./node/incoming_message";
import {
IncomingCommandEndpointGetRawConfigParameterValue,
IncomingCommandEndpointSetRawConfigParameterValue,
} from "./endpoint/incoming_message";
import { InvalidParamsPassedToCommandError } from "./error";

export type SetValueResultType =
Expand Down Expand Up @@ -84,3 +91,19 @@ export async function setRawConfigParameterValue(
const result = await nodeOrEndpoint.commandClasses.Configuration.set(options);
return { result };
}

export async function getRawConfigParameterValue(
message:
| IncomingCommandNodeGetRawConfigParameterValue
| IncomingCommandEndpointGetRawConfigParameterValue,
nodeOrEndpoint: ZWaveNode | Endpoint,
): Promise<{ value: MaybeNotKnown<ConfigValue> }> {
const value = await nodeOrEndpoint.commandClasses.Configuration.get(
message.parameter,
{
valueBitMask: message.bitMask,
allowUnexpectedResponse: message.allowUnexpectedResponse,
},
);
return { value };
}
1 change: 1 addition & 0 deletions src/lib/endpoint/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export enum EndpointCommand {
getCCVersion = "endpoint.get_cc_version",
getNodeUnsafe = "endpoint.get_node_unsafe",
setRawConfigParameterValue = "endpoint.set_raw_config_parameter_value",
getRawConfigParameterValue = "endpoint.get_raw_config_parameter_value",
}
11 changes: 10 additions & 1 deletion src/lib/endpoint/incoming_message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ export interface IncomingCommandEndpointSetRawConfigParameterValue
valueFormat?: ConfigValueFormat;
}

export interface IncomingCommandEndpointGetRawConfigParameterValue
extends IncomingCommandEndpointBase {
command: EndpointCommand.getRawConfigParameterValue;
parameter: number;
bitMask?: number;
allowUnexpectedResponse?: boolean;
}

export type IncomingMessageEndpoint =
| IncomingCommandEndpointInvokeCCAPI
| IncomingCommandEndpointSupportsCCAPI
Expand All @@ -68,4 +76,5 @@ export type IncomingMessageEndpoint =
| IncomingCommandEndpointIsCCSecure
| IncomingCommandEndpointGetCCVersion
| IncomingCommandEndpointGetNodeUnsafe
| IncomingCommandEndpointSetRawConfigParameterValue;
| IncomingCommandEndpointSetRawConfigParameterValue
| IncomingCommandEndpointGetRawConfigParameterValue;
8 changes: 7 additions & 1 deletion src/lib/endpoint/message_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { dumpNode } from "../state";
import { EndpointCommand } from "./command";
import { IncomingMessageEndpoint } from "./incoming_message";
import { EndpointResultTypes } from "./outgoing_message";
import { setRawConfigParameterValue } from "../common";
import {
getRawConfigParameterValue,
setRawConfigParameterValue,
} from "../common";
import { MessageHandler } from "../message_handler";

const isBufferObject = (obj: any): boolean => {
Expand Down Expand Up @@ -101,6 +104,9 @@ export class EndpointMessageHandler implements MessageHandler {
case EndpointCommand.setRawConfigParameterValue: {
return setRawConfigParameterValue(message, endpoint);
}
case EndpointCommand.getRawConfigParameterValue: {
return getRawConfigParameterValue(message, endpoint);
}
default: {
throw new UnknownCommandError(command);
}
Expand Down
5 changes: 4 additions & 1 deletion src/lib/endpoint/outgoing_message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SupervisionResult } from "@zwave-js/core";
import { SupervisionResult, MaybeNotKnown, ConfigValue } from "@zwave-js/core";
import { EndpointCommand } from "./command";
import { NodeState } from "../state";

Expand All @@ -11,4 +11,7 @@ export interface EndpointResultTypes {
[EndpointCommand.getCCVersion]: { version: number };
[EndpointCommand.getNodeUnsafe]: { node: NodeState | undefined };
[EndpointCommand.setRawConfigParameterValue]: { result?: SupervisionResult };
[EndpointCommand.getRawConfigParameterValue]: {
value: MaybeNotKnown<ConfigValue>;
};
}
1 change: 1 addition & 0 deletions src/lib/node/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum NodeCommand {
abortFirmwareUpdate = "node.abort_firmware_update",
pollValue = "node.poll_value",
setRawConfigParameterValue = "node.set_raw_config_parameter_value",
getRawConfigParameterValue = "node.get_raw_config_parameter_value",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to document the new command in the Readme and API schema for schema 39.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh damn, should we have bumped the schema version aswell?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was already bumped in another PR in the release, so that's fine. We can just adjust the docs without a new release.

refreshValues = "node.refresh_values",
refreshCCValues = "node.refresh_cc_values",
ping = "node.ping",
Expand Down
9 changes: 9 additions & 0 deletions src/lib/node/incoming_message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ export interface IncomingCommandNodeSetRawConfigParameterValue
valueFormat?: ConfigValueFormat;
}

export interface IncomingCommandNodeGetRawConfigParameterValue
extends IncomingCommandNodeBase {
command: NodeCommand.getRawConfigParameterValue;
parameter: number;
bitMask?: number;
allowUnexpectedResponse?: boolean;
MindFreeze marked this conversation as resolved.
Show resolved Hide resolved
}

export interface IncomingCommandNodeRefreshValues
extends IncomingCommandNodeBase {
command: NodeCommand.refreshValues;
Expand Down Expand Up @@ -265,6 +273,7 @@ export type IncomingMessageNode =
| IncomingCommandGetFirmwareUpdateCapabilitiesCached
| IncomingCommandNodePollValue
| IncomingCommandNodeSetRawConfigParameterValue
| IncomingCommandNodeGetRawConfigParameterValue
| IncomingCommandNodeRefreshValues
| IncomingCommandNodeRefreshCCValues
| IncomingCommandNodePing
Expand Down
4 changes: 4 additions & 0 deletions src/lib/node/message_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { NodeResultTypes } from "./outgoing_message";
import { dumpNode } from "..";
import {
firmwareUpdateOutgoingMessage,
getRawConfigParameterValue,
setRawConfigParameterValue,
setValueOutgoingMessage,
} from "../common";
Expand Down Expand Up @@ -117,6 +118,9 @@ export class NodeMessageHandler implements MessageHandler {
case NodeCommand.setRawConfigParameterValue: {
return setRawConfigParameterValue(message, node);
}
case NodeCommand.getRawConfigParameterValue: {
return getRawConfigParameterValue(message, node);
}
case NodeCommand.refreshValues: {
await node.refreshValues();
return {};
Expand Down
4 changes: 4 additions & 0 deletions src/lib/node/outgoing_message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
RouteHealthCheckSummary,
TranslatedValueID,
ValueMetadata,
ConfigValue,
} from "zwave-js";
import {
MaybeNotKnown,
Expand All @@ -31,6 +32,9 @@ export interface NodeResultTypes {
};
[NodeCommand.pollValue]: { value?: any };
[NodeCommand.setRawConfigParameterValue]: { result?: SupervisionResult };
[NodeCommand.getRawConfigParameterValue]: {
value: MaybeNotKnown<ConfigValue>;
};
[NodeCommand.refreshValues]: Record<string, never>;
[NodeCommand.refreshCCValues]: Record<string, never>;
[NodeCommand.ping]: { responded: boolean };
Expand Down