From 32a7b94758b664bf19e6ff0c48eca1a0efef238b Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Mon, 14 Oct 2024 08:12:28 +0300 Subject: [PATCH 1/2] Support `get_raw_config_parameter_value` --- src/lib/common.ts | 29 +++++++++++++++++++++++++--- src/lib/endpoint/command.ts | 1 + src/lib/endpoint/incoming_message.ts | 11 ++++++++++- src/lib/endpoint/message_handler.ts | 8 +++++++- src/lib/endpoint/outgoing_message.ts | 5 ++++- src/lib/node/command.ts | 1 + src/lib/node/incoming_message.ts | 9 +++++++++ src/lib/node/message_handler.ts | 4 ++++ src/lib/node/outgoing_message.ts | 4 ++++ 9 files changed, 66 insertions(+), 6 deletions(-) diff --git a/src/lib/common.ts b/src/lib/common.ts index 4eca3efef..820cf2078 100644 --- a/src/lib/common.ts +++ b/src/lib/common.ts @@ -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 = @@ -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 }> { + const value = await nodeOrEndpoint.commandClasses.Configuration.get( + message.parameter, + { + valueBitMask: message.bitMask, + allowUnexpectedResponse: message.allowUnexpectedResponse, + }, + ); + return { value }; +} diff --git a/src/lib/endpoint/command.ts b/src/lib/endpoint/command.ts index fa10a8615..e2136b03f 100644 --- a/src/lib/endpoint/command.ts +++ b/src/lib/endpoint/command.ts @@ -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", } diff --git a/src/lib/endpoint/incoming_message.ts b/src/lib/endpoint/incoming_message.ts index 2da08898c..8e1a5cfd6 100644 --- a/src/lib/endpoint/incoming_message.ts +++ b/src/lib/endpoint/incoming_message.ts @@ -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 @@ -68,4 +76,5 @@ export type IncomingMessageEndpoint = | IncomingCommandEndpointIsCCSecure | IncomingCommandEndpointGetCCVersion | IncomingCommandEndpointGetNodeUnsafe - | IncomingCommandEndpointSetRawConfigParameterValue; + | IncomingCommandEndpointSetRawConfigParameterValue + | IncomingCommandEndpointGetRawConfigParameterValue; diff --git a/src/lib/endpoint/message_handler.ts b/src/lib/endpoint/message_handler.ts index 91a01fc26..88b40e95b 100644 --- a/src/lib/endpoint/message_handler.ts +++ b/src/lib/endpoint/message_handler.ts @@ -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 => { @@ -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); } diff --git a/src/lib/endpoint/outgoing_message.ts b/src/lib/endpoint/outgoing_message.ts index 51f76490b..59e4947c3 100644 --- a/src/lib/endpoint/outgoing_message.ts +++ b/src/lib/endpoint/outgoing_message.ts @@ -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"; @@ -11,4 +11,7 @@ export interface EndpointResultTypes { [EndpointCommand.getCCVersion]: { version: number }; [EndpointCommand.getNodeUnsafe]: { node: NodeState | undefined }; [EndpointCommand.setRawConfigParameterValue]: { result?: SupervisionResult }; + [EndpointCommand.getRawConfigParameterValue]: { + value: MaybeNotKnown; + }; } diff --git a/src/lib/node/command.ts b/src/lib/node/command.ts index f769ee8a8..e36cfed27 100644 --- a/src/lib/node/command.ts +++ b/src/lib/node/command.ts @@ -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", refreshValues = "node.refresh_values", refreshCCValues = "node.refresh_cc_values", ping = "node.ping", diff --git a/src/lib/node/incoming_message.ts b/src/lib/node/incoming_message.ts index f11438d96..b49daf5f0 100644 --- a/src/lib/node/incoming_message.ts +++ b/src/lib/node/incoming_message.ts @@ -94,6 +94,14 @@ export interface IncomingCommandNodeSetRawConfigParameterValue valueFormat?: ConfigValueFormat; } +export interface IncomingCommandNodeGetRawConfigParameterValue + extends IncomingCommandNodeBase { + command: NodeCommand.getRawConfigParameterValue; + parameter: number; + bitMask?: number; + allowUnexpectedResponse?: boolean; +} + export interface IncomingCommandNodeRefreshValues extends IncomingCommandNodeBase { command: NodeCommand.refreshValues; @@ -265,6 +273,7 @@ export type IncomingMessageNode = | IncomingCommandGetFirmwareUpdateCapabilitiesCached | IncomingCommandNodePollValue | IncomingCommandNodeSetRawConfigParameterValue + | IncomingCommandNodeGetRawConfigParameterValue | IncomingCommandNodeRefreshValues | IncomingCommandNodeRefreshCCValues | IncomingCommandNodePing diff --git a/src/lib/node/message_handler.ts b/src/lib/node/message_handler.ts index f7b4c833b..0503fe534 100644 --- a/src/lib/node/message_handler.ts +++ b/src/lib/node/message_handler.ts @@ -18,6 +18,7 @@ import { NodeResultTypes } from "./outgoing_message"; import { dumpNode } from ".."; import { firmwareUpdateOutgoingMessage, + getRawConfigParameterValue, setRawConfigParameterValue, setValueOutgoingMessage, } from "../common"; @@ -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 {}; diff --git a/src/lib/node/outgoing_message.ts b/src/lib/node/outgoing_message.ts index 8d3c03cb4..ce47ac442 100644 --- a/src/lib/node/outgoing_message.ts +++ b/src/lib/node/outgoing_message.ts @@ -5,6 +5,7 @@ import { RouteHealthCheckSummary, TranslatedValueID, ValueMetadata, + ConfigValue, } from "zwave-js"; import { MaybeNotKnown, @@ -31,6 +32,9 @@ export interface NodeResultTypes { }; [NodeCommand.pollValue]: { value?: any }; [NodeCommand.setRawConfigParameterValue]: { result?: SupervisionResult }; + [NodeCommand.getRawConfigParameterValue]: { + value: MaybeNotKnown; + }; [NodeCommand.refreshValues]: Record; [NodeCommand.refreshCCValues]: Record; [NodeCommand.ping]: { responded: boolean }; From 9d929348d67e10054a931a0dd755fd4ca4fd60ef Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Thu, 17 Oct 2024 09:41:45 +0300 Subject: [PATCH 2/2] remove allowUnexpectedResponse --- src/lib/common.ts | 1 - src/lib/endpoint/incoming_message.ts | 1 - src/lib/node/incoming_message.ts | 1 - 3 files changed, 3 deletions(-) diff --git a/src/lib/common.ts b/src/lib/common.ts index 820cf2078..6b819146a 100644 --- a/src/lib/common.ts +++ b/src/lib/common.ts @@ -102,7 +102,6 @@ export async function getRawConfigParameterValue( message.parameter, { valueBitMask: message.bitMask, - allowUnexpectedResponse: message.allowUnexpectedResponse, }, ); return { value }; diff --git a/src/lib/endpoint/incoming_message.ts b/src/lib/endpoint/incoming_message.ts index 8e1a5cfd6..577b7f527 100644 --- a/src/lib/endpoint/incoming_message.ts +++ b/src/lib/endpoint/incoming_message.ts @@ -65,7 +65,6 @@ export interface IncomingCommandEndpointGetRawConfigParameterValue command: EndpointCommand.getRawConfigParameterValue; parameter: number; bitMask?: number; - allowUnexpectedResponse?: boolean; } export type IncomingMessageEndpoint = diff --git a/src/lib/node/incoming_message.ts b/src/lib/node/incoming_message.ts index b49daf5f0..c174d73c3 100644 --- a/src/lib/node/incoming_message.ts +++ b/src/lib/node/incoming_message.ts @@ -99,7 +99,6 @@ export interface IncomingCommandNodeGetRawConfigParameterValue command: NodeCommand.getRawConfigParameterValue; parameter: number; bitMask?: number; - allowUnexpectedResponse?: boolean; } export interface IncomingCommandNodeRefreshValues