Skip to content

Commit 0e90001

Browse files
authored
Merge pull request #173 from OpenZWave/feature/revealBadValueId
make populateValueId raise meaningful errors
2 parents 0effbde + 8a5d45e commit 0e90001

File tree

7 files changed

+200
-182
lines changed

7 files changed

+200
-182
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Node.JS bindings for OpenZWave including management and security functions",
55
"main": "./lib/openzwave-shared.js",
66
"dependencies": {
7-
"nan": "2.5.0"
7+
"nan": "2.6.2"
88
},
99
"scripts": {
1010
"test": "node test.js",

src/openzwave-nodes.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,22 +98,18 @@ namespace OZW {
9898
{
9999
Nan::HandleScope scope;
100100
OpenZWave::ValueID* ozwvid = populateValueId(info);
101-
if (ozwvid == NULL) {
102-
Nan::ThrowTypeError("OpenZWave valueId not found");
103-
} else {
101+
if (ozwvid) {
104102
OpenZWave::Manager::Get()->PressButton(*ozwvid);
105103
}
106104
}
107-
105+
108106
// ===================================================================
109107
NAN_METHOD(OZW::ReleaseButton)
110108
// ===================================================================
111109
{
112110
Nan::HandleScope scope;
113111
OpenZWave::ValueID* ozwvid = populateValueId(info);
114-
if (ozwvid == NULL) {
115-
Nan::ThrowTypeError("OpenZWave valueId not found");
116-
} else {
112+
if (ozwvid) {
117113
OpenZWave::Manager::Get()->ReleaseButton(*ozwvid);
118114
}
119115
}

src/openzwave-polling.cc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ namespace OZW {
111111
Nan::HandleScope scope;
112112
CheckMinArgs(1, "valueId");
113113
OpenZWave::ValueID* ozwvid = populateValueId(info);
114-
if (ozwvid == NULL) {
115-
Nan::ThrowTypeError("OpenZWave valueId not found");
116-
} else {
114+
if (ozwvid) {
117115
bool b = OpenZWave::Manager::Get()->isPolled(*ozwvid);
118116
info.GetReturnValue().Set(Nan::New<Boolean>(b));
119117
}
@@ -127,9 +125,7 @@ namespace OZW {
127125
CheckMinArgs(1, "valueId");
128126
OpenZWave::ValueID* ozwvid = populateValueId(info);
129127
uint8 intensity;
130-
if (ozwvid == NULL) {
131-
Nan::ThrowTypeError("OpenZWave valueId not found");
132-
} else {
128+
if (ozwvid) {
133129
uint8 intensity_index = ( info[0]->IsObject() ) ? 1 : 4;
134130
intensity = info[intensity_index]->ToNumber()->Value();
135131
OpenZWave::Manager::Get()->SetPollIntensity (*ozwvid, intensity);
@@ -144,9 +140,7 @@ namespace OZW {
144140
Nan::HandleScope scope;
145141
CheckMinArgs(1, "valueId");
146142
OpenZWave::ValueID* ozwvid = populateValueId(info);
147-
if (ozwvid == NULL) {
148-
Nan::ThrowTypeError("OpenZWave valueId not found");
149-
} else {
143+
if (ozwvid) {
150144
uint8 i = OpenZWave::Manager::Get()->GetPollIntensity(*ozwvid);
151145
info.GetReturnValue().Set(Nan::New<Integer>(i));
152146
}

src/openzwave-scenes.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ namespace OZW {
120120
CheckMinArgs(2, "sceneid, value");
121121
uint8 sceneid = info[0]->ToNumber()->Value();
122122
OpenZWave::ValueID* vit = populateValueId(info, 1);
123-
if (vit == NULL) {
124-
Nan::ThrowTypeError("OpenZWave valueId not found");
125-
} else {
123+
if (vit) {
126124
uint8 valoffset = ( info[1]->IsObject() ) ? 2 : 5;
127125
switch ((*vit).GetType()) {
128126
case OpenZWave::ValueID::ValueType_Bool: {
@@ -190,9 +188,7 @@ namespace OZW {
190188
SceneInfo *scene;
191189
if ((scene = get_scene_info(sceneid))) {
192190
OpenZWave::ValueID* vit = populateValueId(info, 1);
193-
if (vit == NULL) {
194-
Nan::ThrowTypeError("OpenZWave valueId not found");
195-
} else {
191+
if (vit) {
196192
OpenZWave::Manager::Get()->RemoveSceneValue(sceneid, *vit);
197193
scene->values.remove(*vit);
198194
}

0 commit comments

Comments
 (0)