Skip to content

Commit

Permalink
V9 (#283)
Browse files Browse the repository at this point in the history
* Docs and Package

* First Draft

* Update APIChange-v9.md

* Update APIChange-v9.md

* Update APIChange-v9.md

* Update APIChange-v9.md

* Update APIChange-v9.md

* Update APIChange-v9.md

* Update APIChange-v9.md

* Update APIChange-v9.md

* Update APIChange-v9.md

* Update APIChange-v9.md

* Update APIChange-v9.md

* Update APIChange-v9.md

* Update APIChange-v9.md

* Guide

* Clean up

* extras

* Woah!

* Fix CMDF

* Fix scan issues

* Few fixes

* Update zwave-js.js

* Wrong API

* Update APIChange-v9.md

* Update APIChange-v9.md

* Update APIChange-v9.md

* Update APIChange-v9.md

* Update APIChange-v9.md

* Update APIChange-v9.md

* getValueTimestamp

* Update CHANGELOG.md

* Update CHANGELOG.md

* date format

* Update CHANGELOG.md

* Update package.json
  • Loading branch information
marcus-j-davies authored Oct 15, 2023
1 parent c6bf1d5 commit 8c03d5d
Show file tree
Hide file tree
Showing 8 changed files with 337 additions and 80 deletions.
File renamed without changes.
117 changes: 117 additions & 0 deletions APIChange-v9.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# New API (9.0.0) Migration Guide

V9 begins the take down of the old API introduced in v4.

The old APIs are now set for removal and will be removed in V10.
Below, I set out the changes that you will need to make - and I suggest you make these changes after updating to V9.

without further ado.

Every command is now designed to be a consistant format, and the `payload` below will be the new format.
The reason for this change, is to make it easier for you (and me), to identify parts of the payload.

Previously, setting a value using the Value API for instance, will involve sending an array of objects without any clue as to what they really are, this new format will address that.



## Notes

During this transition, the following APIs will be available using the new format : `DRIVER`, `ASSOCIATIONS`
However, these will form part of the combined `CONTROLLER` API when V10 lands.

The properties `responseThroughEvent` and `forceUpdate` will be supported in the new message format (at the root of `payload`)
but support for them will be removed in V10 (please see change log)

The `Node` API will be available in V10 and will house the `setName`, `setLocation` methods as well as a few new one 😃



```javascript
cmd:{
api: 'CONTROLLER' | 'VALUE' | 'CC' | 'NODE', /* The API you want to use */
method: string /* The method you are executing on this API */
},
cmdProperties:{

nodeId: number, /* The target Node ID */

/* CC API */
commandClass: number, /* The Command class ID (CC) */
method: string, /* The CC's method you want to execute (CC) */
endpoint: number, /* The endpoint you wish to target (CC) */

/* CC, CONTROLLER API */
args: any[], /* The args for the command you are calling (CC, CONTROLLER) */

/* VALUE API */
valueId: object, /* The ValueID you are targeting (VALUE) */
setValueOptions: object, /* Set Value Options (VALUE) */

/* VALUE, NODE API */
value: any, /* The Value you are providing (VALUE, NODE) */

}
```

## Right!! so what do i do (we'll use the Wake Up CC for demonstration)
```javascript
/* This */
let Message = {
payload: {
node: 37,
mode: "CCAPI",
class: "Wake Up",
method: "setInterval",
params: [3600]
}
}
return Message;

/* Is now this */
let Message = {
payload: {
cmd: {
api: 'CC',
method: 'invokeCCAPI'
},
cmdProperties: {
nodeId: 37,
commandClass: 0x84,
method: 'setInterval',
args: [3600]
}
}
}
return Message;
```

```javascript
/* And this */
let Message = {
payload: {
node: 5,
mode: "ValueAPI",
method: "setValue",
params: [<ValueID>,3600]
}
}
return Message;

/* Is now this */
let Message = {
payload: {
cmd: {
api: 'VALUE',
method: 'setValue'
},
cmdProperties: {
nodeId: 5,
valueId: <ValueID>,
value: 3600
}
}
}
return Message;
```


26 changes: 25 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# node-red-contrib-zwave-js Change Log

- 9.0.0

**Breaking Changes**
- The min node version is now 18
- If you execute certain methods your self, the following have been renamed
- `beginHealingNetwork` -> `beginRebuildingRoutes`
- `stopHealingNetwork` -> `stopRebuildingRoutes`
- `healNode` -> `rebuildNodeRoutes`

**New Features**
- Added `getValueTimestamp` to the `Value API` - args will be the single Value ID
The event will be `VALUE_TIMESTAMP`

**Changes**
- Bump ZWave JS to v12
- The `lastSeen` property will now use the Drivers internal value, which is persistant between reboots

**Deprecations**
- The old message format has now been deprecated, and support will be removed in V10.
[PLEASE SEE MIGRATION GUIDE](/APIChange-v9.md)
- Support for `responseThroughEvent` will be removed in V10 (all methods will return in v10)
- Support for `forceUpdate` will be removed in V10 (you will be requied to manage this your self if using the CC API)
- Support for `getLastEvents` will be removed in V10 (the introdcution of the persistant `lastSeen` value and `getValueTimestamp` has made this somewhat bloatware)

- 8.2.1

**Changes**
Expand Down Expand Up @@ -418,7 +442,7 @@
- Bump Z-Wave JS to 7.12.1

- 4.0.0 **Possible Breaking Changes**, **Deprecation Warnings**
- MAJOR API Transition : [PLEASE SEE MIGRATION GUIDE](/APIChange.md)
- MAJOR API Transition : [PLEASE SEE MIGRATION GUIDE](/APIChange-v4.md)
- Added Node Firmware Update UI
- Added Network Map UI
- Added Association Group Managment UI
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"name": "node-red-contrib-zwave-js",
"version": "8.2.1",
"version": "9.0.0",
"license": "MIT",
"description": "The most powerful, high performing and highly polished Z-Wave node for Node-RED based on Z-Wave JS. If you want a fully featured Z-Wave framework in your Node-RED instance, you have found it.",
"dependencies": {
"limiter": "^2.1.0",
"lodash": "^4.17.21",
"winston": "^3.10.0",
"winston-transport": "^4.5.0",
"zwave-js": "^11.14.1"
"winston": "^3.11.0",
"winston-transport": "^4.6.0",
"zwave-js": "^12.1.1"
},
"devDependencies": {
"eslint": "^8.49.0",
"eslint": "^8.51.0",
"prettier": "^3.0.3"
},
"scripts": {
"validate": "node-red-dev validate -o validation_result.json"
},
"engines": {
"node": ">=14.13.0"
"node": ">=18.0.0"
},
"keywords": [
"node-red",
Expand Down Expand Up @@ -61,4 +61,4 @@
"url": "https://github.com/zwave-js/node-red-contrib-zwave-js/issues"
},
"homepage": "https://github.com/zwave-js/node-red-contrib-zwave-js#readme"
}
}
39 changes: 20 additions & 19 deletions resources/UITab/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,19 @@ const DCs = {
name: 'unprovisionAllSmartStart',
noWait: false
},
healNode: {
rebuildNodeRoutes: {
API: 'ControllerAPI',
name: 'healNode',
name: 'rebuildNodeRoutes',
noWait: true
},
beginHealingNetwork: {
beginRebuildingRoutes: {
API: 'ControllerAPI',
name: 'beginHealingNetwork',
name: 'beginRebuildingRoutes',
noWait: false
},
stopHealingNetwork: {
stopRebuildingRoutes: {
API: 'ControllerAPI',
name: 'stopHealingNetwork',
name: 'stopRebuildingRoutes',
noWait: false
},
hardReset: {
Expand Down Expand Up @@ -1889,11 +1889,11 @@ const ZwaveJsUI = (function () {

function StartNodeHeal() {
ControllerCMD(
DCs.healNode.API,
DCs.healNode.name,
DCs.rebuildNodeRoutes.API,
DCs.rebuildNodeRoutes.name,
undefined,
[HoveredNode.nodeId],
DCs.healNode.noWait
DCs.rebuildNodeRoutes.noWait
).catch((err) => {
modalAlert(err.responseText || err.message, 'Could not start Node heal.');
throw new Error(err.responseText || err.message);
Expand All @@ -1902,11 +1902,11 @@ const ZwaveJsUI = (function () {

function StartHeal() {
ControllerCMD(
DCs.beginHealingNetwork.API,
DCs.beginHealingNetwork.name,
DCs.beginRebuildingRoutes.API,
DCs.beginRebuildingRoutes.name,
undefined,
undefined,
DCs.beginHealingNetwork.noWait
DCs.beginRebuildingRoutes.noWait
).catch((err) => {
modalAlert(
err.responseText || err.message,
Expand All @@ -1918,11 +1918,11 @@ const ZwaveJsUI = (function () {

function StopHeal() {
ControllerCMD(
DCs.stopHealingNetwork.API,
DCs.stopHealingNetwork.name,
DCs.stopRebuildingRoutes.API,
DCs.stopRebuildingRoutes.name,
undefined,
undefined,
DCs.stopHealingNetwork.noWait
DCs.stopRebuildingRoutes.noWait
).catch((err) => {
console.error(err);
});
Expand Down Expand Up @@ -2230,15 +2230,15 @@ const ZwaveJsUI = (function () {
},
{
id: 'controller-option-menu-start-heal',
label: 'Begin Network Heal',
label: 'Begin Rebuilding Routes',
onselect: function () {
IsDriverReady();
StartHeal();
}
},
{
id: 'controller-option-menu-stop-heal',
label: 'Stop Network Heal',
label: 'Stop Rebuilding Routes',
onselect: function () {
IsDriverReady();
StopHeal();
Expand Down Expand Up @@ -3179,7 +3179,7 @@ const ZwaveJsUI = (function () {
marginRight: '1px'
});
Heal.append('<i class="fa fa-medkit fa-lg"></i>');
RED.popover.tooltip(Heal, 'Heal Node');
RED.popover.tooltip(Heal, 'Rebuild Node Routes');
BA.append(Heal);

const Associations = $('<button>');
Expand Down Expand Up @@ -3570,7 +3570,8 @@ const ZwaveJsUI = (function () {

const Child = renderPropertyElement(Prop);
propertyList
.treeList('data')[Index].treeList.addChild({ element: Child });
.treeList('data')
[Index].treeList.addChild({ element: Child });

if (Writeable && Type !== 'any') {
const icon = Child.prev();
Expand Down
64 changes: 26 additions & 38 deletions zwave-js/cmd-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,28 +122,18 @@ module.exports = function (RED) {
}
}

const RM = {};
RM.mode = 'ValueAPI';
RM.method = config.vapiMode;
RM.node = NodeID;
RM.params = [];
RM.params.push(ValueID);
if (config.vapiMode === 'setValue') {
RM.params.push(Value);
if (Options !== undefined) {
RM.params.push(Options);
const RM = {
cmd: {
api: 'VALUE',
method: config.vapiMode
},
cmdProperties: {
nodeId: NodeID,
value: Value,
valueId: ValueID,
setValueOptions: Options
}
}

if (RM.params.length < 1) {
delete RM['params'];
}

Object.keys(RM).forEach((K) => {
if (typeof RM[K] === 'undefined') {
delete RM[K];
}
});
};

msg.payload = RM;

Expand Down Expand Up @@ -218,23 +208,21 @@ module.exports = function (RED) {
}
}

const RM = {};
RM.mode = 'CCAPI';
RM.cc = config.cc;
RM.method = config.method;
RM.responseThroughEvent = NoEvent !== true;
RM.node = NodeID;
RM.endpoint = Endpoint;
RM.params = Params;
if (ForceUpdate !== undefined) {
RM.forceUpdate = ForceUpdate;
}

Object.keys(RM).forEach((K) => {
if (typeof RM[K] === 'undefined') {
delete RM[K];
}
});
const RM = {
cmd: {
api: 'CC',
method: 'invokeCCAPI'
},
cmdProperties: {
nodeId: NodeID,
endpoint: Endpoint,
commandClass: config.cc,
method: config.method,
args: Params
},
responseThroughEvent: NoEvent !== true,
forceUpdate: ForceUpdate
};

msg.payload = RM;

Expand Down
Loading

0 comments on commit 8c03d5d

Please sign in to comment.