Skip to content
Open
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
13 changes: 0 additions & 13 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,6 @@
"target_name": "openzwave",
"sources": [
"src/openzwave.cc"
],
"include_dirs": [
"deps/open-zwave/cpp/src"
"deps/open-zwave/cpp/hidapi/hidapi",
"deps/open-zwave/cpp/src",
"deps/open-zwave/cpp/src/command_classes",
"deps/open-zwave/cpp/src/platform",
"deps/open-zwave/cpp/src/platform/unix",
"deps/open-zwave/cpp/src/value_classes",
"deps/open-zwave/cpp/tinyxml"
],
"dependencies": [
"deps/open-zwave/libopenzwave.gyp:libopenzwave"
]
}
]
Expand Down
34 changes: 24 additions & 10 deletions src/openzwave.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
#include <node.h>
#include <v8.h>

#include "Manager.h"
#include "Node.h"
#include "Notification.h"
#include "Options.h"
#include "Value.h"
#include <Manager.h>
#include <Node.h>
#include <Notification.h>
#include <Options.h>
#include <value_classes/Value.h>

using namespace v8;
using namespace node;
Expand Down Expand Up @@ -601,16 +601,18 @@ Handle<Value> OZW::SetName(const Arguments& args)
/*
* Switch a COMMAND_CLASS_SWITCH_BINARY on/off
*/
void set_switch(uint8_t nodeid, bool state)
void set_switch(uint8_t nodeid, bool state, uint8_t instance)
{
NodeInfo *node;
std::list<OpenZWave::ValueID>::iterator vit;

if ((node = get_node_info(nodeid))) {
for (vit = node->values.begin(); vit != node->values.end(); ++vit) {
if ((*vit).GetCommandClassId() == 0x25) {
OpenZWave::Manager::Get()->SetValue(*vit, state);
break;
if ( ! instance || (*vit).GetInstance() == instance ) {
OpenZWave::Manager::Get()->SetValue(*vit, state);
break;
}
}
}
}
Expand All @@ -620,7 +622,13 @@ Handle<Value> OZW::SwitchOn(const Arguments& args)
HandleScope scope;

uint8_t nodeid = args[0]->ToNumber()->Value();
set_switch(nodeid, true);
uint8_t instance = 0;

if ( args.Length() > 1 ) {
instance = args[1]->ToNumber()->Value();
}

set_switch(nodeid, true, instance);

return scope.Close(Undefined());
}
Expand All @@ -629,7 +637,13 @@ Handle<Value> OZW::SwitchOff(const Arguments& args)
HandleScope scope;

uint8_t nodeid = args[0]->ToNumber()->Value();
set_switch(nodeid, false);
uint8_t instance = 0;

if ( args.Length() > 1 ) {
instance = args[1]->ToNumber()->Value();
}

set_switch(nodeid, false, instance);

return scope.Close(Undefined());
}
Expand Down