Binding to Level Change in vDev
Posted: 03 Jan 2016 20:45
Thanx to maros I finally managed to make some progress in my attempt to write a module which will transmit level-change events to a nodejs app I've written.
It turns out that in addition to writing a module you have to instantiate it through the ZWay web UI by adding an instance of the app to the server. This is obvious in hindsight, but I don't recall seeing any mention anywhere in the online docs about needing to do this.
So I now have a userModule which loads and initializes itself.
Unfortunately, it isn't recognizing level change events. Here's the code for init():
Apologies for all the log statements, but I needed to see the program execution, and I don't know how to set up a debug environment to walk through the code.
The problem appears to be in the underNook.on(... statement. The log shows that underNook is found, and that the call to underNook.on() completes. But no events are ever caught (i.e., the log statements inside the callback never get called).
Have I defined the event name wrong? There isn't any documentation I could find on event names, so I simply extended a generic example from the docs.
It turns out that in addition to writing a module you have to instantiate it through the ZWay web UI by adding an instance of the app to the server. This is obvious in hindsight, but I don't recall seeing any mention anywhere in the online docs about needing to do this.
So I now have a userModule which loads and initializes itself.
Unfortunately, it isn't recognizing level change events. Here's the code for init():
Code: Select all
UDPEventRaiser.prototype.init = function( config ) {
// Next line is predefined by Z-Way
UDPEventRaiser.super_.prototype.init.call( this, config );
this.log( 'initializing UDPEventRaiser...' );
var self = this;
var underNook;
if ( this.controller.devices ) {
this.log( 'this.controller.devices defined' );
this.controller.devices.each( function ( vDev ) {
self.log( vDev.id );
} );
underNook = this.controller.devices.get( 'ZWayVDev_zway_16-0-38' );
if ( underNook ) {
self.log( 'found underNook' );
underNook.on( 'change:metrics:level', function ( vDev ) {
self.log( 'got underNook level change event' );
var level = vDev.get( 'metrics:level' );
if ( !level ) level = 'undefined';
self.log( vDev.id + ' level changed to ' + level );
} );
self.log( 'set level change listener on underNook' );
}
else self.log( 'underNook is NOT defined' );
}
else this.log( 'this.controller.devices NOT defined' );
}
The problem appears to be in the underNook.on(... statement. The log shows that underNook is found, and that the call to underNook.on() completes. But no events are ever caught (i.e., the log statements inside the callback never get called).
Have I defined the event name wrong? There isn't any documentation I could find on event names, so I simply extended a generic example from the docs.