mgcrea/node-tydom-client

More precisions needed in wiki / example

Closed this issue · 1 comments

Hi, still trying to understand how you use it.

I can output any data, it works with no issue. But, i ultimately want to use it with hassio.

How do you stay connected and receive data / send a the same time ?
Using two node ?

I'm really trying to interface it...

Thanks in advance.

You just need one node, once you are connected, you can listen for external events/messages or perform any request. You just have to keep your client object around to perform request when needed.

const client = createClient({username, password, hostname});

(async () => {
  console.log(`Connecting to "${hostname}"...`);
  const socket = await client.connect();
  // Get Tydom info
  const info = await client.get('/info');
  console.dir({info});
  // Turn a light on
  await client.put(`/devices/${MY_DEVICE_ID}/endpoints/${MY_DEVICE_ID}/data`, [
    {
      name: 'level',
      value: 100
    }
  ]);
  // Listen for external messages
  client.on('message', message => {
    console.dir({message});
  });
})();