diff --git a/src/callbacks.cc b/src/callbacks.cc index dde1dd03..67250b7b 100644 --- a/src/callbacks.cc +++ b/src/callbacks.cc @@ -183,27 +183,70 @@ namespace OZW { Local < Object > cbinfo = Nan::New(); // switch (notif->type) { - case OpenZWave::Notification::Type_DriverReady: - // the driver is ready, set our global homeid - homeid = notif->homeid; - emitinfo[0] = Nan::New("driver ready").ToLocalChecked(); - emitinfo[1] = Nan::New(homeid); - emit_cb->Call(2, emitinfo); + case OpenZWave::Notification::Type_ValueAdded: { + OpenZWave::ValueID value = notif->values.front(); + Local valobj = zwaveValue2v8Value(value); + + if ((node = get_node_info(notif->nodeid))) { + mutex::scoped_lock sl(znodes_mutex); + node->values.push_back(value); + } + + emitinfo[0] = Nan::New("value added").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = Nan::New(value.GetCommandClassId()); + emitinfo[3] = valobj; + emit_cb->Call(4, emitinfo); break; - case OpenZWave::Notification::Type_DriverFailed: - emitinfo[0] = Nan::New("driver failed").ToLocalChecked(); - emit_cb->Call(1, emitinfo); + } + case OpenZWave::Notification::Type_ValueRemoved: { + OpenZWave::ValueID value = notif->values.front(); + std::list::iterator vit; + if ((node = get_node_info(notif->nodeid))) { + for (vit = node->values.begin(); vit != node->values.end(); ++vit) { + if ((*vit) == notif->values.front()) { + node->values.erase(vit); + break; + } + } + } + emitinfo[0] = Nan::New("value removed").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = Nan::New(value.GetCommandClassId()); + emitinfo[3] = Nan::New(value.GetInstance()); + emitinfo[4] = Nan::New(value.GetIndex()); + emit_cb->Call(5, emitinfo); break; - /* - * NodeNew is triggered when a node is discovered which is not + } + case OpenZWave::Notification::Type_ValueChanged: { + OpenZWave::ValueID value = notif->values.front(); + Local valobj = zwaveValue2v8Value(value); + emitinfo[0] = Nan::New("value changed").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = Nan::New(value.GetCommandClassId()); + emitinfo[3] = valobj; + emit_cb->Call(4, emitinfo); + break; + } + case OpenZWave::Notification::Type_ValueRefreshed: { + OpenZWave::ValueID value = notif->values.front(); + Local valobj = zwaveValue2v8Value(value); + emitinfo[0] = Nan::New("value refreshed").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = Nan::New(value.GetCommandClassId()); + emitinfo[3] = valobj; + emit_cb->Call(4, emitinfo); + break; + } + case OpenZWave::Notification::Type_NodeNew: + /* NodeNew is triggered when a node is discovered which is not * found in the OpenZWave XML file. As we do not use that file * simply ignore those notifications for now. * * NodeAdded is when we actually have a new node to set up. */ - case OpenZWave::Notification::Type_NodeNew: break; - case OpenZWave::Notification::Type_NodeAdded: + case OpenZWave::Notification::Type_NodeAdded: { node = new NodeInfo(); node->homeid = notif->homeid; node->nodeid = notif->nodeid; @@ -216,11 +259,9 @@ namespace OZW { emitinfo[1] = Nan::New(notif->nodeid); emit_cb->Call(2, emitinfo); break; - /* - * Ignore intermediate notifications about a node status, we - * wait until the node is ready before retrieving information. - */ - case OpenZWave::Notification::Type_NodeRemoved: + } + + case OpenZWave::Notification::Type_NodeRemoved: { { mutex::scoped_lock sl(znodes_mutex); znodes.erase(notif->nodeid); @@ -229,8 +270,14 @@ namespace OZW { emitinfo[1] = Nan::New(notif->nodeid); emit_cb->Call(2, emitinfo); break; - case OpenZWave::Notification::Type_NodeProtocolInfo: + } + case OpenZWave::Notification::Type_NodeProtocolInfo: { + /* + * Ignore intermediate notifications about a node status, we + * wait until the node is ready before retrieving information. + */ break; + } case OpenZWave::Notification::Type_NodeNaming: { getV8ValueForZWaveNode(mgr, cbinfo, notif->homeid, notif->nodeid); emitinfo[0] = Nan::New("node naming").ToLocalChecked(); @@ -239,15 +286,17 @@ namespace OZW { emit_cb->Call(3, emitinfo); break; } - case OpenZWave::Notification::Type_PollingEnabled: - if ((node = get_node_info(notif->nodeid))) { - node->polled = true; - emitinfo[0] = Nan::New("polling enabled").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emit_cb->Call(2, emitinfo); - } + case OpenZWave::Notification::Type_NodeEvent: { + OpenZWave::ValueID value = notif->values.front(); + Local valobj = zwaveValue2v8Value(value); + emitinfo[0] = Nan::New("node event").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = Nan::New(notif->event); + emitinfo[3] = valobj; + emit_cb->Call(4, emitinfo); break; - case OpenZWave::Notification::Type_PollingDisabled: + } + case OpenZWave::Notification::Type_PollingDisabled: { if ((node = get_node_info(notif->nodeid))) { node->polled = false; emitinfo[0] = Nan::New("polling disabled").ToLocalChecked(); @@ -255,67 +304,64 @@ namespace OZW { emit_cb->Call(2, emitinfo); } break; - /* - * Node values. - */ - case OpenZWave::Notification::Type_ValueAdded: { - OpenZWave::ValueID value = notif->values.front(); - Local valobj = zwaveValue2v8Value(value); - + } + case OpenZWave::Notification::Type_PollingEnabled: { if ((node = get_node_info(notif->nodeid))) { - mutex::scoped_lock sl(znodes_mutex); - node->values.push_back(value); + node->polled = true; + emitinfo[0] = Nan::New("polling enabled").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emit_cb->Call(2, emitinfo); } - - emitinfo[0] = Nan::New("value added").ToLocalChecked(); + break; + } + case OpenZWave::Notification::Type_SceneEvent:{ + emitinfo[0] = Nan::New("scene event").ToLocalChecked(); emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = Nan::New(value.GetCommandClassId()); - emitinfo[3] = valobj; - emit_cb->Call(4, emitinfo); + emitinfo[2] = Nan::New(notif->sceneid); + emit_cb->Call(3, emitinfo); break; } - case OpenZWave::Notification::Type_ValueChanged: { - OpenZWave::ValueID value = notif->values.front(); - Local valobj = zwaveValue2v8Value(value); - emitinfo[0] = Nan::New("value changed").ToLocalChecked(); + case OpenZWave::Notification::Type_CreateButton: { + emitinfo[0] = Nan::New("create button").ToLocalChecked(); emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = Nan::New(value.GetCommandClassId()); - emitinfo[3] = valobj; - emit_cb->Call(4, emitinfo); + emitinfo[2] = Nan::New(notif->buttonid); + emit_cb->Call(3, emitinfo); break; } - case OpenZWave::Notification::Type_ValueRefreshed: { - OpenZWave::ValueID value = notif->values.front(); - Local valobj = zwaveValue2v8Value(value); - emitinfo[0] = Nan::New("value refreshed").ToLocalChecked(); + case OpenZWave::Notification::Type_DeleteButton: { + emitinfo[0] = Nan::New("delete button").ToLocalChecked(); emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = Nan::New(value.GetCommandClassId()); - emitinfo[3] = valobj; - emit_cb->Call(4, emitinfo); + emitinfo[2] = Nan::New(notif->buttonid); + emit_cb->Call(3, emitinfo); break; } - case OpenZWave::Notification::Type_ValueRemoved: { - OpenZWave::ValueID value = notif->values.front(); - std::list::iterator vit; - if ((node = get_node_info(notif->nodeid))) { - for (vit = node->values.begin(); vit != node->values.end(); ++vit) { - if ((*vit) == notif->values.front()) { - node->values.erase(vit); - break; - } - } - } - emitinfo[0] = Nan::New("value removed").ToLocalChecked(); + case OpenZWave::Notification::Type_ButtonOn: { + emitinfo[0] = Nan::New("button on").ToLocalChecked(); emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = Nan::New(value.GetCommandClassId()); - emitinfo[3] = Nan::New(value.GetInstance()); - emitinfo[4] = Nan::New(value.GetIndex()); - emit_cb->Call(5, emitinfo); + emitinfo[2] = Nan::New(notif->buttonid); + emit_cb->Call(3, emitinfo); + break; + } + case OpenZWave::Notification::Type_ButtonOff: { + emitinfo[0] = Nan::New("button off").ToLocalChecked(); + emitinfo[1] = Nan::New(notif->nodeid); + emitinfo[2] = Nan::New(notif->buttonid); + emit_cb->Call(3, emitinfo); + break; + } + case OpenZWave::Notification::Type_DriverReady: { + // the driver is ready, set our global homeid + homeid = notif->homeid; + emitinfo[0] = Nan::New("driver ready").ToLocalChecked(); + emitinfo[1] = Nan::New(homeid); + emit_cb->Call(2, emitinfo); + break; + } + case OpenZWave::Notification::Type_DriverFailed: { + emitinfo[0] = Nan::New("driver failed").ToLocalChecked(); + emit_cb->Call(1, emitinfo); break; } - /* - *Now node can accept commands. - */ case OpenZWave::Notification::Type_EssentialNodeQueriesComplete: { getV8ValueForZWaveNode(mgr, cbinfo, notif->homeid, notif->nodeid); emitinfo[0] = Nan::New("node available").ToLocalChecked(); @@ -345,23 +391,7 @@ namespace OZW { emitinfo[0] = Nan::New("scan complete").ToLocalChecked(); emit_cb->Call(1, emitinfo); break; - case OpenZWave::Notification::Type_NodeEvent: { - OpenZWave::ValueID value = notif->values.front(); - Local valobj = zwaveValue2v8Value(value); - emitinfo[0] = Nan::New("node event").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = Nan::New(notif->event); - emitinfo[3] = valobj; - emit_cb->Call(4, emitinfo); - break; - } - case OpenZWave::Notification::Type_SceneEvent:{ - emitinfo[0] = Nan::New("scene event").ToLocalChecked(); - emitinfo[1] = Nan::New(notif->nodeid); - emitinfo[2] = Nan::New(notif->sceneid); - emit_cb->Call(3, emitinfo); - break; - } + case OpenZWave::Notification::Type_Notification: emitinfo[0] = Nan::New("notification").ToLocalChecked(); emitinfo[1] = Nan::New(notif->nodeid);