-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathSpeakerAccessory.js
39 lines (32 loc) · 1.25 KB
/
SpeakerAccessory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const ActorAccessory = require('./ActorAccessory.js');
class SpeakerAccessory extends ActorAccessory {
constructor(log, url, accessToken, device, homebridge) {
const Service = homebridge.hap.Service;
const Characteristic = homebridge.hap.Characteristic;
super(log, url, accessToken, device, homebridge, Service.Speaker, Characteristic.Mute);
this.actorService.getCharacteristic(Characteristic.Volume)
.on('set', this.setVolume.bind(this))
.on('get', this.getVolume.bind(this));
this.volumeFunctionName = 'volume';
}
setState(value, callback) {
super.setState(value ? '1' : '0', callback);
}
setVolume(value, callback) {
this.volume = value;
this.callParticleFunction(this.volumeFunctionName, value,
(error, response, body) => this.callbackHelper(error, response, body, callback), true);
}
getVolume(callback) {
this.callParticleFunction(this.volumeFunctionName, '?', (error, response, body) => {
this.volume = parseInt(body, 10);
try {
callback(null, this.volume);
} catch (err) {
this.log(`Caught error ${err} when calling homebridge callback.`);
}
},
true);
}
}
module.exports = SpeakerAccessory;