homebridge / HAP-NodeJS

Node.js implementation of the HomeKit Accessory Protocol (HAP)
Apache License 2.0
2.68k stars 630 forks source link

Service.Speaker not working #308

Closed LukeTim closed 8 years ago

LukeTim commented 8 years ago

I have modified a homebridge plugin to use the speaker service in order to control the mute and volume of my Pioneer AVR, however when I launch homebridge I am told that Speaker.Service is not a function:

TypeError: Service.Speaker is not a function
    at new VSX (/usr/local/lib/node_modules/homebridge-vsx/index.js:24:26)
    at Server._loadAccessories (/usr/local/lib/node_modules/homebridge/lib/server.js:244:29)
    at Server.run (/usr/local/lib/node_modules/homebridge/lib/server.js:72:38)
    at module.exports (/usr/local/lib/node_modules/homebridge/lib/cli.js:40:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/homebridge/bin/homebridge:17:22)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)

I am using it in this way:

function VSX(log, config) {
  this.log = log;
  this.name = config.name;
  this.HOST = config.ip;
  this.PORT = 23;

  this.switch_service = new Service.Switch(this.name);
  this.speaker_service = new Service.Speaker(this.name);

  this.switch_service.getCharacteristic(Characteristic.On)
    .on("set", this.setOn.bind(this))
    .on("get", this.getOn.bind(this));

  this.speaker_service.getCharacteristic(Characteristic.Mute)
    .on("set", this.setMute.bind(this))
    .on("get", this.getMute.bind(this));

  this.speaker_service.getCharacteristic(Characteristic.Volume)
    .on("set", this.setVolume.bind(this))
    .on("get", this.getVolume.bind(this));

  //this.service.getCharacteristic(InputCharacteristic)
    //.on("set", this.setInput.bind(this))
    //.on("get", this.getInput.bind(this));
}

Service.Switch works perfectly fine. Any ideas what's wrong?

LukeTim commented 8 years ago

Nevermind. Turns out Homebridge uses an old version of HAP-NodeJS. I was looking at the globally installed version of HAP-NodeJS which was not missing this service.