Skip to content

Commit 43e801d

Browse files
committed
added type checks, added thermostat schedule calls
1 parent a592974 commit 43e801d

14 files changed

+371
-164
lines changed

README-api.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@ Modifying device state:
5050
/*
5151
* Set arbitrary values.
5252
*/
53+
// 1) by means of passing each individual ValueID constituent:
5354
zwave.setValue(nodeid, commandclass, instance, index, value);
5455
zwave.setValue(3, 37, 1, 0, true); // node 3: turn on
5556
zwave.setValue(3, 37, 1, 0, false); // node 3: turn off
56-
zwave.setValue(5, 38, 1, 0, 50); // dimmer 5: set to 50%
57+
// dimmer node 5: set to 50%
58+
zwave.setValue(5, 38, 1, 0, 50);
59+
// 2) or by passing the valueID object (emitted by ValueAdded event):
60+
zwave.setValue({ nodeid:5, class_id: 38, instance:1, index:0}, 50);
5761

5862
/*
5963
* Turn a binary switch on/off.

README-events.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,19 @@ their unique identifiers are:
3838

3939
* `COMMAND_CLASS_SWITCH_BINARY` (37)
4040
* `COMMAND_CLASS_SWITCH_MULTILEVEL` (38)
41-
* `COMMAND_CLASS_VERSION` (134)
4241

4342
Binary switches can be controlled with `.setNodeOn()` and `.setNodeOff()`.
4443
Dimmer (multi-level) devices can be set with `.setLevel()` (*if of course they
45-
support the **BASIC** command class, which is not supported by most dimmers!*
44+
support the **BASIC** command class, which is not always supported by most dimmers!*
4645
Use `setValue` instead)
4746

47+
* `COMMAND_CLASS_VERSION` (134)
48+
4849
The version class is informational only and cannot be controlled.
4950

5051
The `value` object differs between command classes, and contains all the useful
51-
information about values stored for the particular class.
52+
information about values stored for the particular class. You can use this object
53+
as the 1st argument in `setValue` to alter its state.
5254

5355
###### `.on('value changed', function(nodeid, commandclass, valueId){})` : A value has changed. Use this to keep track of value state across the network. When values are first discovered, the module enables polling on those values so that we will receive change messages. Prior to the 'node ready' event, there may be 'value changed' events even when no values were actually changed.
5456

README-example.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
The test program below connects to a Z-Wave network, scans for all nodes and
44
values, and prints out information about the network.
5-
**When the network has become ready**, the library will call 'scan complete'
6-
and the script will then issue a *beginControllerCommand*
7-
to the driver so as to add a new node to the ZWave network.
5+
6+
**When the network has become ready**, the library will call 'scan complete'
7+
and the script will then 1) issue a `setValue` command to set a dimmer (node 5)
8+
at 50%, and then issue a command to begin the inclusion process for a new zwave
9+
device. This means calling `beginControllerCommand` OR `addNode` depending on
10+
which version of the OpenZWave API you've linked against.
11+
812
Remember to hit `^C` to end the script.
913

1014
```js
@@ -122,8 +126,18 @@ zwave.on('notification', function(nodeid, notif) {
122126

123127
zwave.on('scan complete', function() {
124128
console.log('====> scan complete, hit ^C to finish.');
129+
// set dimmer node 5 to 50%
130+
//zwave.setValue(5,38,1,0,50);
131+
zwave.setValue( {nodeid:5, class_id: 38, instance:1, index:0}, 50);
125132
// Add a new device to the ZWave controller
126-
zwave.beginControllerCommand('AddDevice', true);
133+
if (zwave.hasOwnProperty('beginControllerCommand')) {
134+
// using legacy mode (OpenZWave version < 1.3) - no security
135+
zwave.beginControllerCommand('AddDevice', true);
136+
} else {
137+
// using new security API
138+
// set this to 'true' for secure devices eg. door locks
139+
zwave.addNode(false);
140+
}
127141
});
128142

129143
zwave.on('controller command', function(r,s) {
@@ -142,7 +156,7 @@ process.on('SIGINT', function() {
142156
Sample output from this program:
143157

144158
```sh
145-
$ nodejs test2.js
159+
$ nodejs test2.js
146160
initialising OpenZWave addon (/home/ekarak/src/node-openzwave-shared/lib/../build/Debug/openzwave_shared.node)
147161
scanning homeid=0xcafebabe...
148162
node2: nop

README-mgmt.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ which effectively replace the old `BeginControllerCommand`. There's also no
1515

1616
- zwave.addNode(doSecurity: boolean):
1717
Add a new device or controller with/without security. This is usually followed
18-
by starting the pair/unpair process on the device (eg by some inclusion button)
18+
by starting the pair/unpair process on the device (eg. pressing a special
19+
inclusion button or quickly pressing the manual operation button three times)
1920

2021
- zwave.removeNode():
2122
Remove a device or controller from the Z-Wave network. This is usually followed
@@ -66,32 +67,33 @@ which effectively replace the old `BeginControllerCommand`. There's also no
6667

6768

6869
## Legacy mode (`BeginControllerCommand`)
69-
If your OZW version is 1.2 or earlier, use `BeginControllerCommand` for doing
70-
all management stuff with your ZWave network. This
71-
as it allows for performing management functions on the ZWave network.
72-
- The first argument is the command name, and its the only mandatory arg ,which can be any of the following:
70+
If your OZW version is 1.2 or earlier, use `beginControllerCommand` for doing
71+
all management stuff with your ZWave network. This command has the following format:
72+
73+
`zwave.beginControllerCommand("command", highpower, node1, node2)`
74+
75+
- The first argument is the command name, and its the *only mandatory*, which can be any of the following:
7376

7477
```
75-
["AddDevice"]
76-
["CreateNewPrimary"]
77-
["ReceiveConfiguration"]
78-
["RemoveDevice"]
79-
["RemoveFailedNode"]
80-
["HasNodeFailed"]
81-
["ReplaceFailedNode"]
82-
["TransferPrimaryRole"]
83-
["RequestNetworkUpdate"]
84-
["RequestNodeNeighborUpdate"]
85-
["AssignReturnRoute"]
86-
["DeleteAllReturnRoutes"]
87-
["SendNodeInformation"]
88-
["ReplicationSend"]
89-
["CreateButton"]
90-
["DeleteButton"]
78+
"AddDevice"
79+
"CreateNewPrimary"
80+
"ReceiveConfiguration"
81+
"RemoveDevice"
82+
"RemoveFailedNode"
83+
"HasNodeFailed"
84+
"ReplaceFailedNode"
85+
"TransferPrimaryRole"
86+
"RequestNetworkUpdate"
87+
"RequestNodeNeighborUpdate"
88+
"AssignReturnRoute"
89+
"DeleteAllReturnRoutes"
90+
"SendNodeInformation"
91+
"ReplicationSend"
92+
"CreateButton"
93+
"DeleteButton"
9194
```
9295

93-
94-
- The second argument is a boolean ("highpower") - should be true/false
96+
- The second argument ("highpower") is a boolean and tells OpenZWave to use low or high power mode - should be true/false. You shouldn't use high power for inclusions though.
9597
- The third argument is the first ZWave node to be passed to the command (if applicable for the command)
9698
- The fourth argument is the second ZWave node to be passed to the command
9799

package.json

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "openzwave-shared",
3-
"version": "1.1.5",
3+
"version": "1.1.6",
44
"description": "Node.JS bindings for OpenZWave including management and security functions",
55
"main": "./lib/openzwave-shared.js",
6-
"dependencies" : {
7-
"nan" : "~2.0.9"
6+
"dependencies": {
7+
"nan": "^2.0.9"
88
},
99
"scripts": {
1010
"test": "node test.js",
@@ -16,20 +16,22 @@
1616
"url": "git://github.com/OpenZWave/node-openzwave-shared.git"
1717
},
1818
"keywords": [
19-
"zwave", "z-wave",
19+
"zwave",
20+
"z-wave",
2021
"home automation",
21-
"openzwave", "open-zwave"
22+
"openzwave",
23+
"open-zwave"
2224
],
2325
"author": "Elias Karakoulakis <[email protected]>",
2426
"contributors": [
25-
"Jonathan Perkin (http://www.perkin.org.uk/)" ,
26-
"Thibaut CONSTANT",
27-
"davide-lr",
27+
"Jonathan Perkin (http://www.perkin.org.uk/)",
28+
"Thibaut CONSTANT",
29+
"davide-lr",
2830
"Luke Hertert (http://werul.com)"
2931
],
3032
"license": {
31-
"type": "ISC",
32-
"url": "http://opensource.org/licenses/ISC"
33+
"type": "ISC",
34+
"url": "http://opensource.org/licenses/ISC"
3335
},
3436
"gypfile": true
3537
}

src/openzwave-nodes.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ namespace OZW {
9696
{
9797
Nan::HandleScope scope;
9898
OpenZWave::ValueID* ozwvid = getZwaveValueID(info);
99-
if (ozwvid != NULL) {
99+
if (ozwvid == NULL) {
100+
Nan::ThrowTypeError("OpenZWave valueId not found");
101+
} else {
100102
OpenZWave::Manager::Get()->PressButton(*ozwvid);
101103
}
102104
}

src/openzwave-polling.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ namespace OZW {
108108
{
109109
Nan::HandleScope scope;
110110
OpenZWave::ValueID* ozwvid = getZwaveValueID(info);
111-
if (ozwvid != NULL) {
111+
if (ozwvid == NULL) {
112+
Nan::ThrowTypeError("OpenZWave valueId not found");
113+
} else {
112114
bool b = OpenZWave::Manager::Get()->isPolled(*ozwvid);
113115
info.GetReturnValue().Set(Nan::New<Boolean>(b));
114116
}
@@ -121,7 +123,9 @@ namespace OZW {
121123
Nan::HandleScope scope;
122124
OpenZWave::ValueID* ozwvid = getZwaveValueID(info);
123125
uint8 intensity;
124-
if (ozwvid != NULL) {
126+
if (ozwvid == NULL) {
127+
Nan::ThrowTypeError("OpenZWave valueId not found");
128+
} else {
125129
uint8 intensity_index = ( info[0]->IsObject() ) ? 1 : 4;
126130
intensity = info[intensity_index]->ToNumber()->Value();
127131
OpenZWave::Manager::Get()->SetPollIntensity (*ozwvid, intensity);
@@ -135,7 +139,9 @@ namespace OZW {
135139
{
136140
Nan::HandleScope scope;
137141
OpenZWave::ValueID* ozwvid = getZwaveValueID(info);
138-
if (ozwvid != NULL) {
142+
if (ozwvid == NULL) {
143+
Nan::ThrowTypeError("OpenZWave valueId not found");
144+
} else {
139145
uint8 i = OpenZWave::Manager::Get()->GetPollIntensity(*ozwvid);
140146
info.GetReturnValue().Set(Nan::New<Integer>(i));
141147
}

src/openzwave-scenes.cc

Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -124,61 +124,62 @@ namespace OZW {
124124

125125
uint8 sceneid = info[0]->ToNumber()->Value();
126126
OpenZWave::ValueID* vit = getZwaveValueID(info, 1);
127-
uint8 valoffset = ( info[1]->IsObject() ) ? 2 : 5;
128-
if (vit != NULL) {
129-
130-
switch ((*vit).GetType()) {
131-
case OpenZWave::ValueID::ValueType_Bool: {
132-
//bool val; OpenZWave::Manager::Get()->GetValueAsBool(*vit, &val);
133-
bool val = info[valoffset]->ToBoolean()->Value();
134-
OpenZWave::Manager::Get()->AddSceneValue(sceneid, *vit, val);
135-
break;
136-
}
137-
case OpenZWave::ValueID::ValueType_Byte: {
138-
//uint8 val; OpenZWave::Manager::Get()->GetValueAsByte(*vit, &val);
139-
uint8 val = info[valoffset]->ToInteger()->Value();
140-
OpenZWave::Manager::Get()->AddSceneValue(sceneid, *vit, val);
141-
break;
142-
}
143-
case OpenZWave::ValueID::ValueType_Decimal: {
144-
//float val; OpenZWave::Manager::Get()->GetValueAsFloat(*vit, &val);
145-
float val = info[valoffset]->ToNumber()->NumberValue();
146-
OpenZWave::Manager::Get()->AddSceneValue(sceneid, *vit, val);
147-
break;
148-
}
149-
case OpenZWave::ValueID::ValueType_Int: {
150-
//uint32 val; OpenZWave::Manager::Get()->GetValueAsInt(*vit, &val);
151-
int32 val = info[valoffset]->ToInteger()->Value();
152-
OpenZWave::Manager::Get()->AddSceneValue(sceneid, *vit, val);
153-
break;
154-
}
155-
case OpenZWave::ValueID::ValueType_List: {
156-
//std::string val; OpenZWave::Manager::Get()->GetValueListSelection(*vit, &val);
157-
std::string val = (*String::Utf8Value(info[valoffset]->ToString()));
158-
OpenZWave::Manager::Get()->AddSceneValue(sceneid, *vit, val);
159-
break;
160-
}
161-
case OpenZWave::ValueID::ValueType_Short: {
162-
//int16_t val; OpenZWave::Manager::Get()->GetValueAsShort(*vit, &val);
163-
uint16 val = info[valoffset]->ToInteger()->Value();
164-
OpenZWave::Manager::Get()->AddSceneValue(sceneid, *vit, val);
165-
break;
166-
}
167-
case OpenZWave::ValueID::ValueType_String: {
168-
//std::string val; OpenZWave::Manager::Get()->GetValueAsString(*vit, &val);
169-
std::string val = (*String::Utf8Value(info[valoffset]->ToString()));
170-
OpenZWave::Manager::Get()->AddSceneValue(sceneid, *vit, val);
171-
break;
172-
}
173-
case OpenZWave::ValueID::ValueType_Schedule: {
174-
break;
175-
}
176-
case OpenZWave::ValueID::ValueType_Button: {
177-
break;
178-
}
179-
case OpenZWave::ValueID::ValueType_Raw: {
180-
break;
181-
}
127+
if (vit == NULL) {
128+
Nan::ThrowTypeError("OpenZWave valueId not found");
129+
} else {
130+
uint8 valoffset = ( info[1]->IsObject() ) ? 2 : 5;
131+
switch ((*vit).GetType()) {
132+
case OpenZWave::ValueID::ValueType_Bool: {
133+
//bool val; OpenZWave::Manager::Get()->GetValueAsBool(*vit, &val);
134+
bool val = info[valoffset]->ToBoolean()->Value();
135+
OpenZWave::Manager::Get()->AddSceneValue(sceneid, *vit, val);
136+
break;
137+
}
138+
case OpenZWave::ValueID::ValueType_Byte: {
139+
//uint8 val; OpenZWave::Manager::Get()->GetValueAsByte(*vit, &val);
140+
uint8 val = info[valoffset]->ToInteger()->Value();
141+
OpenZWave::Manager::Get()->AddSceneValue(sceneid, *vit, val);
142+
break;
143+
}
144+
case OpenZWave::ValueID::ValueType_Decimal: {
145+
//float val; OpenZWave::Manager::Get()->GetValueAsFloat(*vit, &val);
146+
float val = info[valoffset]->ToNumber()->NumberValue();
147+
OpenZWave::Manager::Get()->AddSceneValue(sceneid, *vit, val);
148+
break;
149+
}
150+
case OpenZWave::ValueID::ValueType_Int: {
151+
//uint32 val; OpenZWave::Manager::Get()->GetValueAsInt(*vit, &val);
152+
int32 val = info[valoffset]->ToInteger()->Value();
153+
OpenZWave::Manager::Get()->AddSceneValue(sceneid, *vit, val);
154+
break;
155+
}
156+
case OpenZWave::ValueID::ValueType_List: {
157+
//std::string val; OpenZWave::Manager::Get()->GetValueListSelection(*vit, &val);
158+
std::string val = (*String::Utf8Value(info[valoffset]->ToString()));
159+
OpenZWave::Manager::Get()->AddSceneValue(sceneid, *vit, val);
160+
break;
161+
}
162+
case OpenZWave::ValueID::ValueType_Short: {
163+
//int16_t val; OpenZWave::Manager::Get()->GetValueAsShort(*vit, &val);
164+
uint16 val = info[valoffset]->ToInteger()->Value();
165+
OpenZWave::Manager::Get()->AddSceneValue(sceneid, *vit, val);
166+
break;
167+
}
168+
case OpenZWave::ValueID::ValueType_String: {
169+
//std::string val; OpenZWave::Manager::Get()->GetValueAsString(*vit, &val);
170+
std::string val = (*String::Utf8Value(info[valoffset]->ToString()));
171+
OpenZWave::Manager::Get()->AddSceneValue(sceneid, *vit, val);
172+
break;
173+
}
174+
case OpenZWave::ValueID::ValueType_Schedule: {
175+
break;
176+
}
177+
case OpenZWave::ValueID::ValueType_Button: {
178+
break;
179+
}
180+
case OpenZWave::ValueID::ValueType_Raw: {
181+
break;
182+
}
182183
}
183184
}
184185
}
@@ -192,9 +193,11 @@ namespace OZW {
192193
SceneInfo *scene;
193194
if ((scene = get_scene_info(sceneid))) {
194195
OpenZWave::ValueID* vit = getZwaveValueID(info, 1);
195-
if (vit != NULL) {
196-
OpenZWave::Manager::Get()->RemoveSceneValue(sceneid, *vit);
197-
scene->values.remove(*vit);
196+
if (vit == NULL) {
197+
Nan::ThrowTypeError("OpenZWave valueId not found");
198+
} else {
199+
OpenZWave::Manager::Get()->RemoveSceneValue(sceneid, *vit);
200+
scene->values.remove(*vit);
198201
}
199202
}
200203
}

0 commit comments

Comments
 (0)