Page 1 of 1

How to retrieve object instance in module?

Posted: 08 Nov 2014 17:13
by Vantskruv
I'm scripting a new module, where you in the UI select a device from the list.
How do you get an instance of the selected device? See the code below for an example:

Code: Select all

TZ68_Fix.prototype.init = function (config) {
    TZ68_Fix.super_.prototype.init.call(this, config);

    var self = this;

    //var dev = zway.devices[7]; // Ok this lines works, but it is not dynamic.
    //Example of what I want to do.
    //config.device is set in the UI, this is the device I want to control
    //Below line returns undefined. Which is the correct method?
    var dev = this.controller.devices.get(config.device);

    //Output the value config.device to logfile.
    console.log("TZ68 device: " + config.device); 
    dev.data.nodeInfoFrame.bind(function(type)
    {
        if(type == 0x41) dev.SwitchBinary.Get();
    });
};
Edit:
Is there any method to call in the controller-class? I.e:

Code: Select all

this.controller.nodeInfoFrame(config.device, function(type){
    if(type == 0x41) SwitchBinary.Get();
});