Skip to content

Commit

Permalink
feat(mqtt): allow to set options in multicast/broadcast requests (#3573)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando authored Feb 1, 2024
1 parent c09b638 commit 9ba5886
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
19 changes: 16 additions & 3 deletions api/lib/Gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2284,7 +2284,11 @@ export default class Gateway {
logger.error('Invalid valueId: ' + error)
return
}
await this._zwave.writeBroadcast(payload, payload.value)
await this._zwave.writeBroadcast(
payload,
payload.value,
payload.options,
)
}
}

Expand All @@ -2308,7 +2312,11 @@ export default class Gateway {
}

private async _onMulticastRequest(
payload: ZUIValueId & { nodes: number[]; value: any },
payload: ZUIValueId & {
nodes: number[]
value: any
options?: SetValueAPIOptions
},
): Promise<void> {
const nodes = payload.nodes
const valueId: ValueID = {
Expand Down Expand Up @@ -2336,7 +2344,12 @@ export default class Gateway {
return
}

await this._zwave.writeMulticast(nodes, valueId as ZUIValueId, value)
await this._zwave.writeMulticast(
nodes,
valueId as ZUIValueId,
value,
payload.options,
)
}

/**
Expand Down
17 changes: 13 additions & 4 deletions api/lib/ZwaveClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4046,12 +4046,16 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
/**
* Send broadcast write request
*/
async writeBroadcast(valueId: ValueID, value: unknown) {
async writeBroadcast(
valueId: ValueID,
value: unknown,
options?: SetValueAPIOptions,
) {
if (this.driverReady) {
try {
const broadcastNode = this._driver.controller.getBroadcastNode()

await broadcastNode.setValue(valueId, value)
await broadcastNode.setValue(valueId, value, options)
} catch (error) {
logger.error(
// eslint-disable-next-line @typescript-eslint/no-base-to-string
Expand All @@ -4068,13 +4072,18 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
/**
* Send multicast write request to a group of nodes
*/
async writeMulticast(nodes: number[], valueId: ZUIValueId, value: unknown) {
async writeMulticast(
nodes: number[],
valueId: ZUIValueId,
value: unknown,
options?: SetValueAPIOptions,
) {
if (this.driverReady) {
let fallback = false
try {
const multicastGroup =
this._driver.controller.getMulticastGroup(nodes)
await multicastGroup.setValue(valueId, value)
await multicastGroup.setValue(valueId, value, options)
} catch (error) {
fallback = error.code === ZWaveErrorCodes.CC_NotSupported
logger.error(
Expand Down
19 changes: 15 additions & 4 deletions docs/guide/mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,11 @@ Payload:
#### `writeBroadcast`

```ts
async writeBroadcast(valueId: ValueID, value: unknown): Promise<void>;
async writeBroadcast(
valueId: ValueID,
value: unknown,
options?: SetValueAPIOptions,
): Promise<void>;
```

Send broadcast write request.
Expand All @@ -2053,7 +2057,8 @@ Payload:
{
"args": [
valueId,
value
value,
options
]
}
```
Expand All @@ -2063,7 +2068,12 @@ Payload:
#### `writeMulticast`

```ts
async writeMulticast(nodes: number[], valueId: ZUIValueId, value: unknown): Promise<void>;
async writeMulticast(
nodes: number[],
valueId: ZUIValueId,
value: unknown,
options?: SetValueAPIOptions,
): Promise<void>;
```

Send multicast write request to a group of nodes.
Expand All @@ -2080,7 +2090,8 @@ Payload:
"args": [
nodes,
valueId,
value
value,
options
]
}
```
Expand Down
4 changes: 2 additions & 2 deletions genereteDocs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MethodDeclaration, Project, SourceFile } from 'ts-morph'
import { allowedApis } from './lib/ZwaveClient'
import { allowedApis } from './api/lib/ZwaveClient'
import { readFile, writeFile } from 'fs/promises'

import * as prettier from 'prettier'
Expand All @@ -22,7 +22,7 @@ export async function formatWithPrettier(
async function main() {
const program = new Project({ tsConfigFilePath: 'tsconfig.json' })

const fileName = './lib/ZwaveClient.ts'
const fileName = './api/lib/ZwaveClient.ts'
const docsFile = './docs/guide/mqtt.md'

const sourceFile = program.getSourceFileOrThrow(fileName)
Expand Down

0 comments on commit 9ba5886

Please sign in to comment.