Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Lightbulb to Fan via config option #16

Merged
merged 4 commits into from
Jul 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 20 additions & 8 deletions index.js
Expand Up @@ -17,6 +17,7 @@ function ReceiverVolume(log, config) {
this.host = config['host'];
this.zone = (config['zone'] || 1) | 0; // default to 1, and make sure its an integer
this.controlPower = !!config['controlPower']; // default to false, and make sure its a bool
this.useFan = !!config['useFan']; // default to false, and make sure its a bool
this.controlMute = !!config['controlMute'] && this.controlPower === false;
this.mapMaxVolumeTo100 = !!config['mapMaxVolumeTo100'];

Expand Down Expand Up @@ -97,6 +98,7 @@ ReceiverVolume.prototype.setPowerOn = function(powerOn, callback) {
this.setControl('Mute', command, callback);
} else {
this.fakePowerState = powerOn ? 1 : 0;
//this.fakePowerState = 1;
this.log("Set receiver %s volume power state to %s", this.zoneName, this.fakePowerState);
callback(null);
}
Expand Down Expand Up @@ -148,17 +150,27 @@ ReceiverVolume.prototype.getBrightness = function(callback) {
}

ReceiverVolume.prototype.getServices = function() {
var lightbulbService = new Service.Lightbulb(this.name);

if (this.useFan) {
var lightbulbService = new Service.Fan(this.name);
}
else {
var lightbulbService = new Service.Lightbulb(this.name);
}
lightbulbService
.getCharacteristic(Characteristic.On)
.on('get', this.getPowerOn.bind(this))
.on('set', this.setPowerOn.bind(this));

lightbulbService
.addCharacteristic(new Characteristic.Brightness())
.on('get', this.getBrightness.bind(this))
.on('set', this.setBrightness.bind(this));

if (this.useFan) {
lightbulbService
.addCharacteristic(new Characteristic.RotationSpeed())
.on('get', this.getBrightness.bind(this))
.on('set', this.setBrightness.bind(this));
}
else {
lightbulbService
.addCharacteristic(new Characteristic.Brightness())
.on('get', this.getBrightness.bind(this))
.on('set', this.setBrightness.bind(this));
}
return [lightbulbService];
}