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

feat: add option to emit "value update" events after setValue #3751

Merged
merged 1 commit into from
Nov 18, 2021
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
56 changes: 28 additions & 28 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,40 @@
"typescriptreact"
],
"files.exclude": {
"node_modules/": false,
"coverage/": false,
"node_modules/": true,
"coverage/": true,
".*": false,
"**/node_modules/": false,
".nyc_output": false,
"**/coverage/": false,
"**/*.map": false,
"**/zwave-js-*.tgz": false,
"build": false,
"*.d.ts": false,
"*.map": false,
"**/build": false,
"**/*.tsbuildinfo": false,
"packages/zwave-js/**/fingerprint.txt": false,
"node_modules/zwave-js/**/fingerprint.txt": false,
".husky/_/**/*": false,
"packages/config/config/devices/index.json": false,
"packages/*/package-lock.json": false,
".yarn/*": false,
"**/node_modules/": true,
".nyc_output": true,
"**/coverage/": true,
"**/*.map": true,
"**/zwave-js-*.tgz": true,
"build": true,
"*.d.ts": true,
"*.map": true,
"**/build": true,
"**/*.tsbuildinfo": true,
"packages/zwave-js/**/fingerprint.txt": true,
"node_modules/zwave-js/**/fingerprint.txt": true,
".husky/_/**/*": true,
"packages/config/config/devices/index.json": true,
"packages/*/package-lock.json": true,
".yarn/*": true,
".yarn/patches": false,
".yarn/releases": false,
".yarn/plugins": false,
".yarn/sdks": false,
".yarn/versions": false,
"**/.pnp.*": false,
"**/*.test.js": false,
"packages/*/cache": false,
"**/.tmp": false,
"**/.tmpoh/": false,
"**/.tmpozw/": false,
"**/.tmpzwa/": false,
"**/.secrets": false,
"**/.test-payloads": false,
"(!test)/cache": false
"**/.pnp.*": true,
"**/*.test.js": true,
"packages/*/cache": true,
"**/.tmp": true,
"**/.tmpoh/": true,
"**/.tmpozw/": true,
"**/.tmpzwa/": true,
"**/.secrets": true,
"**/.test-payloads": true,
"(!test)/cache": true
},
"files.associations": {
"**/config/**/*.json": "jsonc"
Expand Down
4 changes: 4 additions & 0 deletions docs/api/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ This method automatically figures out which commands to send to the node, so you
- The required Command Class is not implemented in this library yet
- The API for the required Command Class is not implemented in this library yet

> [!ATTENTION] By default, the driver assumes to be talking to a single application. In this scenario a successful `setValue` call is enough for the application to know that the value was changed and update its own cache or UI. Therefore, the `"value updated"` event is not emitted after `setValue` unless the change was verified by the device.
>
> To get `"value updated"` events nonetheless, set the driver option `emitValueUpdateAfterSetValue` to `true`.

The `options` bag contains options that influence the resulting commands, for example a transition duration. Each implementation will choose the options that are relevant for it, so you can use the same options everywhere.

<!-- #import SetValueAPIOptions from "zwave-js" -->
Expand Down
11 changes: 11 additions & 0 deletions packages/zwave-js/src/lib/driver/ZWaveOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ export interface ZWaveOptions {
*/
disableOptimisticValueUpdate?: boolean;

/**
* By default, the driver assumes to be talking to a single application. In this scenario a successful `setValue` call
* is enough for the application to know that the value was changed and update its own cache or UI.
*
* Therefore, the `"value updated"` event is not emitted after `setValue` unless the change was verified by the device.
* To get `"value updated"` events nonetheless, set this option to `true`.
*
* Default: `false`
*/
emitValueUpdateAfterSetValue?: boolean;

/**
* Soft Reset is required after some commands like changing the RF region or restoring an NVM backup.
* Because it may be problematic in certain environments, we provide the user with an option to opt out.
Expand Down
8 changes: 7 additions & 1 deletion packages/zwave-js/src/lib/node/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,13 @@ export class ZWaveNode extends Endpoint implements SecurityClassOwner {
);
if (api.isSetValueOptimistic(valueId)) {
// If the call did not throw, assume that the call was successful and remember the new value
this._valueDB.setValue(valueId, value, { noEvent: true });
this._valueDB.setValue(
valueId,
value,
!!this.driver.options.emitValueUpdateAfterSetValue
? undefined
: { noEvent: true },
);
}

return true;
Expand Down