lmoe / node-denon-client

A handy node library which allows you to control and receive events of a Denon AVR.
GNU General Public License v3.0
9 stars 11 forks source link

Promises not resolved? #10

Open nneubauer opened 6 years ago

nneubauer commented 6 years ago

Hi,

maybe I am doing it wrong, but I am trying to:

this.avr.connect()
    .then(() => {
      this.log(`Tryin to get Input`);
      return this.avr.getInput()
    })
    .then((result) => {
      this.log(`Current input retrieved as: ${result}`);
      this.currentInput = result;
    })
    .catch((error) => {
      this.log('Error %s', error);
    });

I can see the first log message, so connect() seems to resolve, but getInput() never does seem to resolve so that the "Current input retrieved" log never appears. Curiously, also the Error log never appears. Nothing happens. (Probably the chain hangs...).

I have a X1400. Any ideas? I have the same with setPower. The receiver actually powers on but the .then() part never resolves even after the AVR is switched on.

markg85 commented 5 years ago

I seem to be hitting this issue too.

From the looks of it, sendCommand (in denon_client.js) never resolves in the return case. I just commented out the if statement there (thus it always resolves) and be done with it :) Here's how mine looks:

  /**
   * Sends a command to the Denon AVR
   *
   * @method sendCommand
   * @param  {string} command   [The command]
   * @param  {string} parameter [The parameter]
   * @return {Promise} [A response]
   */
  sendCommand(command, parameter, hook) {
    return new Promise((resolve) => {

      if (typeof hook === 'string') {
        this.once(hook, (result) => {
          resolve(result);
        });
      }

      return this
        .write(`${command}${parameter}`)
        .then(() => {
          // if (typeof hook === 'undefined') {
            resolve();
          // }
        });
    })
  }