automategreen / home-controller

A node package to control Insteon home automation devices
MIT License
96 stars 29 forks source link

Confused about link() #88

Open ctgreybeard opened 5 years ago

ctgreybeard commented 5 years ago

I'm confused about the link API and the examples given.

The API says insteon.link([device,] [options,] [callback])

An example shows insteon.link('AABBCC', '112233', {group: 2}, function(error, link) {...

The API only has one device, the example shows two.

I am trying to link two devices, one may be the gateway, what is the proper form of the link? I believe I may use "gw" for the gateway but in many case the gateway isn't one of the devices being linked.

My code has:

      hub.link(link.addr1, link.addr2, (err, link) => {
...

but I get an error:

/home/debian/Projects/superlinker/node_modules/home-controller/lib/Insteon/utils.js:105
  value = value.toString(16).toUpperCase();

In this case I was trying to link gw->0D3158

ctgreybeard commented 5 years ago

I've condensed my program to what I think should be a correct 'minimum' but it does not work:

/*
 * Test home-controller linking
 */

var Insteon = require("home-controller").Insteon;
var hub = new Insteon();
var util = require("util");

hub.serial("/dev/ttyS4", () => {
  console.log("Hub connected");
  hub.on("close", () => {
    console.log("Hub closed.");
  });
  hub.link('gw', '0B5B8F', function (err, link) {
    console.log("Err: %s, Link:\n%s", err, util.inspect(link));
    hub.close();
  });
});

The error I receive is:

╰─➤  node linktest.js                                                                                                  1 ↵
Hub connected
(node:14401) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'toString' of undefined
    at toByte (/home/debian/Projects/superlinker/node_modules/home-controller/lib/Insteon/utils.js:105:17)
    at link (/home/debian/Projects/superlinker/node_modules/home-controller/lib/Insteon/index.js:1131:9)
    at Insteon.link (/home/debian/Projects/superlinker/node_modules/home-controller/lib/Insteon/index.js:1084:15)
    at hub.serial (/home/debian/Projects/superlinker/linktest.js:15:7)
    at SerialPort.<anonymous> (/home/debian/Projects/superlinker/node_modules/home-controller/lib/Insteon/index.js:142:32)
    at SerialPort.emit (events.js:202:15)
    at binding.open.then (/home/debian/Projects/superlinker/node_modules/serialport/lib/serialport.js:234:10)
(node:14401) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14401) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
ctgreybeard commented 5 years ago

I have been digging farther and once I use a single Insteon address for link() it completes but with varying results. I believe that my older (some are quite old) devices don't link using this. I'm going to see if I can find out what the differences might be.

siburny commented 5 years ago

It is very possible that older devices do not support full range of Insteon messages/API.

I personally always link devices using the physical buttons.