How to retrieve object instance in module?

Discussions about Z-Way software and Z-Wave technology in general
Post Reply
Vantskruv
Posts: 13
Joined: 06 Nov 2014 18:26

How to retrieve object instance in module?

Post 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();
});
ScheduleSun - a sunset/sunrise module
viewtopic.php?f=3424&t=20801
Post Reply