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

Add support for a default_input configuration option #11

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,23 @@ Next step: Check what happens if the AVR is reset or is temporary not available.
# Configuration

Example accessory config (needs to be added to the homebridge config.json):

```
"accessories": [
{
"accessory": "OnkyoAVR",
"name": "My Onkyo",
"ip_address": "10.0.1.23",
"model" : "TX-NR609",
"poll_status_interval": "900"
"poll_status_interval": "900",
"default_input": "sat"
}
]
```

`default_input` is optional. If it not supplied, the previous input will be persisted. If a valid option is supplied, a request to set the input to the specified source will be made when the unit is turned on. The valid options depend on the unit. As a rule of thumb try to use the values as they are printed on the remote.
Examples of values:
- VCR
- SAT
- DVD

36 changes: 33 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ function HttpStatusAccessory(log, config)
this.name = config["name"];
this.model = config["model"];
this.poll_status_interval = config["poll_status_interval"] || "0";

this.defaultInputNeedsSetting = false;
this.defaultInput = config["default_input"];

this.state = false;
this.interval = parseInt( this.poll_status_interval);
Expand All @@ -43,7 +46,6 @@ function HttpStatusAccessory(log, config)
this.eiscp.on('debug', this.eventDebug.bind(this));
this.eiscp.on('error', this.eventError.bind(this));
this.eiscp.on('connect', this.eventConnect.bind(this));
this.eiscp.on('connect', this.eventConnect.bind(this));
this.eiscp.on('system-power', this.eventSystemPower.bind(this));
this.eiscp.on('volume', this.eventVolume.bind(this));
this.eiscp.on('close', this.eventClose.bind(this));
Expand Down Expand Up @@ -103,6 +105,25 @@ eventSystemPower: function( response)
if (this.switchService ) {
this.switchService.getCharacteristic(Characteristic.On).setValue(this.state, null, "statuspoll");
}

// If the AVR has just been turned on, apply the Input default
if (this.defaultInputNeedsSetting) {
this.log("Attempting to set the input selector to "+this.defaultInput);
if (this.state && this.defaultInput) {
this.log("Setting input selector to "+this.defaultInput);
var that = this;
this.eiscp.command("input-selector="+this.defaultInput, function(error, response) {
if (error) {
that.log( "Error while setting input: %s", error);
}
});
}

this.defaultInputNeedsSetting = false;
}
else {
this.log("Default input doesn't need setting");
}
},

eventVolume: function( response)
Expand Down Expand Up @@ -146,7 +167,13 @@ setPowerState: function(powerOn, callback, context) {
that.switchService.getCharacteristic(Characteristic.On).setValue(powerOn, null, "statuspoll");
}
}
else {
if (that.defaultInput) {
that.defaultInputNeedsSetting = true;
}
}
}.bind(this) );

} else {
this.log("setPowerState - actual mode, power state: %s, switching to OFF", that.state);
this.eiscp.command("system-power=standby", function(error, response) {
Expand All @@ -155,9 +182,12 @@ setPowerState: function(powerOn, callback, context) {
that.state = false;
that.log( "setPowerState - PWR OFF: ERROR - current state: %s", that.state);
if (that.switchService ) {
that.switchService.getCharacteristic(Characteristic.On).setValue(powerOn, null, "statuspoll");
that.switchService.getCharacteristic(Characteristic.On).setValue(that.state, null, "statuspoll");
}
}

that.defaultInputNeedsSetting = false;

}.bind(this) );
}
},
Expand Down Expand Up @@ -188,7 +218,7 @@ getPowerState: function(callback, context) {
that.state = false;
that.log( "getPowerState - PWR QRY: ERROR - current state: %s", that.state);
if (that.switchService ) {
that.switchService.getCharacteristic(Characteristic.On).setValue(powerOn, null, "statuspoll");
that.switchService.getCharacteristic(Characteristic.On).setValue(that.state, null, "statuspoll");
}
}
}.bind(this) );
Expand Down