Skip to content

Commit dd035e6

Browse files
authored
Merge pull request #174 from OpenZWave/feature/refactor-polling
Feature/refactor polling
2 parents 0e90001 + fbab11b commit dd035e6

File tree

4 files changed

+51
-58
lines changed

4 files changed

+51
-58
lines changed

README-api.md

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,26 @@ minutes!) to scan the ZWave network and set up its data structures.
4545
So, be sure to register a "scan complete" callback, and after it gets called,
4646
you can safely start issuing commands to your ZWave devices.
4747

48-
Modifying device state:
48+
**Controlling zwave valueIDs** is usually done by passing the ValueID as a
49+
Javascipt object or as 4 discrete integer arguments:
50+
- 1: ZWave Node Id,
51+
- 2: Command Class,
52+
- 3: Instance and
53+
- 4: Index
54+
55+
For example if Zwave Node #3 is a binary switch, to turn it on and off, use
56+
command class 37:
57+
4958
```js
50-
/*
51-
* Set arbitrary values.
52-
*/
53-
// 1) by means of passing each individual ValueID constituent:
54-
zwave.setValue(nodeid, commandclass, instance, index, value);
55-
zwave.setValue(3, 37, 1, 0, true); // node 3: turn on
56-
zwave.setValue(3, 37, 1, 0, false); // node 3: turn off
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({ node_id:5, class_id: 38, instance:1, index:0}, 50);
59+
zwave.setValue(3, 37, 1, 0, true); // node 3: turn on
60+
zwave.setValue(3, 37, 1, 0, false); // node 3: turn off
61+
```
62+
63+
Another example: if Zwave Node #5 is a dimmer, use class 38:
64+
65+
```js
66+
zwave.setValue(5, 38, 1, 0, 50); // 1) passing each individual ValueID constituent:
67+
zwave.setValue({ node_id:5, class_id: 38, instance:1, index:0}, 50); // 2) or a valueID object (emitted by ValueAdded event):
6168

6269
/*
6370
* Turn a binary switch on/off.
@@ -94,13 +101,13 @@ zwave.setNodeName(nodeid, name); // arbitrary name string
94101

95102
Polling a device for changes (not all devices require this):
96103
```js
97-
zwave.enablePoll(nodeid, commandclass, intensity);
98-
zwave.disablePoll(nodeid, commandclass);
99-
zwave.setPollInterval(nodeid, )
100-
zwave.getPollInterval();
101-
zwave.isPolled();
102-
zwave.setPollIntensity();
103-
zwave.getPollIntensity();
104+
zwave.enablePoll({valueId}, intensity);
105+
zwave.disablePoll({valueId});
106+
zwave.setPollInterval(intervalMillisecs) // set the polling interval in msec
107+
zwave.getPollInterval(); // return the polling interval
108+
zwave.setPollIntensity({valueId}, intensity); // Set the frequency of polling (0=none, 1=every time through the list, 2-every other time, etc)
109+
zwave.getPollIntensity({valueId});
110+
zwave.isPolled({valueId});
104111
```
105112

106113
Association groups management:

README-example.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ zwave.on('node added', function(nodeid) {
4242
};
4343
});
4444

45-
zwave.on('value added', function(nodeid, comclass, value) {
45+
zwave.on('value added', function(nodeid, comclass, valueId) {
4646
if (!nodes[nodeid]['classes'][comclass])
4747
nodes[nodeid]['classes'][comclass] = {};
48-
nodes[nodeid]['classes'][comclass][value.index] = value;
48+
nodes[nodeid]['classes'][comclass][valueId.index] = value;
4949
});
5050

5151
zwave.on('value changed', function(nodeid, comclass, value) {
@@ -85,16 +85,17 @@ zwave.on('node ready', function(nodeid, nodeinfo) {
8585
nodeinfo.type,
8686
nodeinfo.loc);
8787
for (comclass in nodes[nodeid]['classes']) {
88-
switch (comclass) {
88+
console.log('node%d: class %d', nodeid, comclass);
89+
switch (comclass) {
8990
case 0x25: // COMMAND_CLASS_SWITCH_BINARY
9091
case 0x26: // COMMAND_CLASS_SWITCH_MULTILEVEL
91-
zwave.enablePoll(nodeid, comclass);
92+
var valueIds = nodes[nodeid]['classes'][comclass];
93+
for (valueId in valueIds) {
94+
zwave.enablePoll(valueId);
9295
break;
93-
}
94-
var values = nodes[nodeid]['classes'][comclass];
95-
console.log('node%d: class %d', nodeid, comclass);
96-
for (idx in values)
97-
console.log('node%d: %s=%s', nodeid, values[idx]['label'], values[idx]['value']);
96+
}
97+
console.log('node%d: %s=%s', nodeid, values[idx]['label'], values[idx]['value']);
98+
}
9899
}
99100
});
100101

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openzwave-shared",
3-
"version": "1.3.4",
3+
"version": "1.4.0",
44
"description": "Node.JS bindings for OpenZWave including management and security functions",
55
"main": "./lib/openzwave-shared.js",
66
"dependencies": {
@@ -38,7 +38,10 @@
3838
"Adam Rensel",
3939
"David Moxey",
4040
"Bart Bakker",
41-
"vectah0"
41+
"vectah0",
42+
"yybd",
43+
"Rob Huehn",
44+
"Michael Franken"
4245
],
4346
"license": {
4447
"type": "ISC",

src/openzwave-polling.cc

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,30 +53,20 @@ namespace OZW {
5353
OpenZWave::Manager::Get()->SetPollInterval (intervalMillisecs, false);
5454
}
5555

56-
5756
/*
58-
* Enable/Disable polling on a COMMAND_CLASS basis.
57+
* Enable/Disable polling on a ValueID
5958
*/
6059
// ===================================================================
6160
NAN_METHOD(OZW::EnablePoll)
6261
// ===================================================================
6362
{
6463
Nan::HandleScope scope;
65-
CheckMinArgs(2, "nodeid, commandclass");
66-
uint8 nodeid = info[0]->ToNumber()->Value();
67-
uint8 comclass = info[1]->ToNumber()->Value();
68-
uint8 intensity = (info.Length() > 2) ? info[2]->ToNumber()->Value() : 1;
69-
70-
NodeInfo *node;
71-
std::list<OpenZWave::ValueID>::iterator vit;
64+
CheckMinArgs(2, "valueId_object, intensity");
65+
OpenZWave::ValueID* vit = populateValueId(info);
7266
bool b = false;
73-
if ((node = get_node_info(nodeid))) {
74-
for (vit = node->values.begin(); vit != node->values.end(); ++vit) {
75-
if ((*vit).GetCommandClassId() == comclass) {
76-
b = OpenZWave::Manager::Get()->EnablePoll((*vit), intensity);
77-
break;
78-
}
79-
}
67+
if (vit) {
68+
uint8 intensity = (info.Length() > 4) ? info[4]->ToNumber()->Value() : 1;
69+
b = OpenZWave::Manager::Get()->EnablePoll((*vit), intensity);
8070
}
8171
info.GetReturnValue().Set(Nan::New<Boolean>(b));
8272
}
@@ -86,19 +76,11 @@ namespace OZW {
8676
// ===================================================================
8777
{
8878
Nan::HandleScope scope;
89-
CheckMinArgs(2, "nodeid, commandclass");
90-
uint8 nodeid = info[0]->ToNumber()->Value();
91-
uint8 comclass = info[1]->ToNumber()->Value();
92-
NodeInfo *node;
93-
std::list<OpenZWave::ValueID>::iterator vit;
79+
CheckMinArgs(1, "valueId");
80+
OpenZWave::ValueID* vit = populateValueId(info);
9481
bool b = false;
95-
if ((node = get_node_info(nodeid))) {
96-
for (vit = node->values.begin(); vit != node->values.end(); ++vit) {
97-
if ((*vit).GetCommandClassId() == comclass) {
98-
b = OpenZWave::Manager::Get()->DisablePoll((*vit));
99-
break;
100-
}
101-
}
82+
if (vit) {
83+
b = OpenZWave::Manager::Get()->DisablePoll((*vit));
10284
}
10385
info.GetReturnValue().Set(Nan::New<Boolean>(b));
10486
}

0 commit comments

Comments
 (0)