Commit dc2e3798 authored by Samuel Elliott's avatar Samuel Elliott

Set the current input to the connected Apple TV if it is playing

parent a3155782
......@@ -98,18 +98,32 @@ class TVAccessory {
Buffer.from(config.apple_tv.encryption_key, 'hex')
);
AppleTV.scan(credentials.uniqueIdentifier)
.then(devices => {
this.apple_tv = devices[0];
this.apple_tv.on('error', err => {
console.error(this.name + ' Apple TV error', err);
});
return this.apple_tv.openConnection(credentials);
})
.then(device => {
this.log('Connected to ' + config.name);
})
.catch(error => this.log(error));
AppleTV.scan(credentials.uniqueIdentifier).then(devices => {
this.apple_tv = devices[0];
this.apple_tv.on('error', err => {
console.error(this.name + ' Apple TV error', err);
});
return this.apple_tv.openConnection(credentials);
}).then(device => {
this.log('Connected to %s Apple TV', this.name);
// Switch to the Apple TV input when the Apple TV starts playing
device.on('nowPlaying', info => {
if (!info || info.playbackState !== 'playing') return;
this.last_input_switched = this.apple_tv_input;
if (this.expose_power_service) {
this.power_service.getCharacteristic(this.constructor.hap.Characteristic.On)
.updateValue(true);
}
if (this.expose_television_service) {
this.tv_service.getCharacteristic(this.constructor.hap.Characteristic.Active)
.updateValue(this.constructor.hap.Characteristic.Active.ACTIVE);
this.tv_service.getCharacteristic(this.constructor.hap.Characteristic.ActiveIdentifier)
.updateValue(this.apple_tv_input);
}
});
}).catch(error => this.log(error));
}
// Connect to the TV
......@@ -154,7 +168,7 @@ class TVAccessory {
}));
}
if (tv_channel_input_source_services.length) {
if (this.expose_television_service && tv_channel_input_source_services.length) {
this.followtv.getActiveChannelList().then(channels => {
const cached_channel_names = {};
......@@ -177,7 +191,9 @@ class TVAccessory {
});
}
this.apple_tv_input = config.apple_tv_input || this.input_source_services.findIndex(service => service.getCharacteristic(this.constructor.hap.Characteristic.InputSourceType) === this.constructor.hap.Characteristic.InputSourceType.HDMI) || 1;
this.apple_tv_input = config.apple_tv_input || this.input_source_services
.findIndex(service => service.getCharacteristic(this.constructor.hap.Characteristic.InputSourceType) ===
this.constructor.hap.Characteristic.InputSourceType.HDMI) || 1;
this.default_input = config.default_input || 0;
this.accessory_information_service = new this.constructor.hap.Service.AccessoryInformation();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment