kazcangi / homebridge-pioneer-avr

Pioneer AVR TV plugin for Homebridge
MIT License
9 stars 14 forks source link

Cannot generate setupURI on an accessory that isn't published yet #28

Closed holuspokus closed 1 year ago

holuspokus commented 1 year ago

edit: the problem was the Promise resolve was not working. nodejs v18.15.0, macOS

telnet-avr.js:28

'use strict';

const net = require('net');
const ReadWriteLock = require('rwlock');

const PORT = 23;
const HOST = '127.0.0.1';

class TelnetAvr {
 constructor(host, port) {
  this.host = host || HOST;
  this.port = port || PORT;
  this.lock = new ReadWriteLock();
 }

 sendMessage(message, callback) {
  var me = this;
   me.lock.writeLock((release) => {
    var socket = net.Socket();
    socket.setTimeout(200000, () => socket.destroy());
    socket.once('connect', () => socket.setTimeout(2000));
    socket.connect(me.port, me.host, () => {
     // socket.write(message+'\r');
     require('deasync').sleep(10);
     socket.write(message+'\r');
     if (!message.startsWith('?')) {
      callback(null, message + ':SENT');
      socket.end();
     }
    });

    socket.on('close', () => {
     require('deasync').sleep(1000);
     release();
    });

    socket.on('data', (d) => {
      try{
       let data = d
        .toString()
        .replace('\n', '')
        .replace('\r', '')
        .trim();

       callback(null, data);
     } catch (e) {
         console.error(e)
     }

     socket.end();
    });

    socket.on('error', (err) => {
     callback(err, null);
    });
   });
 }
}
module.exports = TelnetAvr;