Don’t require tv_apps and tv_channels

parent cbb81e24
...@@ -31,7 +31,7 @@ Switching inputs works by iterating over a configured list of inputs. ...@@ -31,7 +31,7 @@ Switching inputs works by iterating over a configured list of inputs.
Turning the TV on Turning the TV on
--- ---
To turn the TV on you need another device capable of turning the TV on with HDMI CEC. To turn the TV on you need another device capable of turning the TV on with HDMI CEC or IR.
### Apple TV 4th generation ### Apple TV 4th generation
......
This diff is collapsed.
...@@ -3,6 +3,8 @@ const persist = require('node-persist'); ...@@ -3,6 +3,8 @@ const persist = require('node-persist');
const {VestelNetworkRemote, VestelFollowTV} = require('vestel-network-remote'); const {VestelNetworkRemote, VestelFollowTV} = require('vestel-network-remote');
const UPnPClient = require('@langovoi/upnp-device-client'); const UPnPClient = require('@langovoi/upnp-device-client');
let AppleTV;
const key_map = {}; const key_map = {};
module.exports = function (homebridge) { module.exports = function (homebridge) {
...@@ -13,6 +15,13 @@ module.exports = function (homebridge) { ...@@ -13,6 +15,13 @@ module.exports = function (homebridge) {
stringify: data => JSON.stringify(data, undefined, 4), stringify: data => JSON.stringify(data, undefined, 4),
}); });
try {
AppleTV = require('node-appletv');
} catch (err) {
console.error('Failed to load node-appletv', err);
console.log('node-appletv is not installed. You will not be able to use an Apple TV to turn a TV on.');
}
homebridge.registerAccessory('vestel-network-remote', 'TV', TVAccessory.use(homebridge, storage)); homebridge.registerAccessory('vestel-network-remote', 'TV', TVAccessory.use(homebridge, storage));
Object.assign(key_map, { Object.assign(key_map, {
...@@ -73,15 +82,13 @@ class TVAccessory { ...@@ -73,15 +82,13 @@ class TVAccessory {
this.expose_speaker_lightbulb_service = config.expose_speaker_lightbulb_service !== undefined this.expose_speaker_lightbulb_service = config.expose_speaker_lightbulb_service !== undefined
? config.expose_speaker_lightbulb_service : false; ? config.expose_speaker_lightbulb_service : false;
if (!this.expose_power_service && !this.expose_speaker_service && !this.expose_speaker_lightbulb_service && !this._setting_picture_mode.expose_television_service && !this.expose_television_speaker_service) { if (!this.expose_power_service && !this.expose_speaker_service && !this.expose_speaker_lightbulb_service && !this.expose_television_service && !this.expose_television_speaker_service) {
throw new Error('Trying to create a vestel-network-remote.TV accessory with no services'); throw new Error('Trying to create a vestel-network-remote.TV accessory with no services');
} }
// Connect to an Apple TV // Connect to an Apple TV
// This is used to turn the TV on // This is used to turn the TV on
if (config.apple_tv) { if (config.apple_tv && AppleTV) {
const AppleTV = require('node-appletv');
const credentials = typeof config.apple_tv === 'string' const credentials = typeof config.apple_tv === 'string'
? AppleTV.parseCredentials(config.apple_tv) : typeof config.apple_tv === 'array' ? AppleTV.parseCredentials(config.apple_tv) : typeof config.apple_tv === 'array'
? AppleTV.parseCredentials(config.apple_tv.join(':')) : new AppleTV.Credentials( ? AppleTV.parseCredentials(config.apple_tv.join(':')) : new AppleTV.Credentials(
...@@ -91,7 +98,7 @@ class TVAccessory { ...@@ -91,7 +98,7 @@ class TVAccessory {
Buffer.from(config.apple_tv.public_key, 'hex'), Buffer.from(config.apple_tv.public_key, 'hex'),
Buffer.from(config.apple_tv.encryption_key, 'hex') Buffer.from(config.apple_tv.encryption_key, 'hex')
); );
AppleTV.scan(credentials.uniqueIdentifier) AppleTV.scan(credentials.uniqueIdentifier)
.then(devices => { .then(devices => {
this.apple_tv = devices[0]; this.apple_tv = devices[0];
...@@ -126,13 +133,13 @@ class TVAccessory { ...@@ -126,13 +133,13 @@ class TVAccessory {
this.addInputSourceService(id, type); this.addInputSourceService(id, type);
} }
for (let [id, app_config] of Object.entries(config.tv_apps)) { for (let [id, app_config] of Object.entries(config.tv_apps || {})) {
this.addAppInputSourceService(id, app_config); this.addAppInputSourceService(id, app_config);
} }
const tv_channel_input_source_services = []; const tv_channel_input_source_services = [];
for (let channel_number of config.tv_channels) { for (let channel_number of config.tv_channels || []) {
const name = (this.getItemSync('CachedChannelNames') || {})[channel_number] || 'Channel ' + channel_number; const name = (this.getItemSync('CachedChannelNames') || {})[channel_number] || 'Channel ' + channel_number;
tv_channel_input_source_services.push(this.addAppInputSourceService(name, { tv_channel_input_source_services.push(this.addAppInputSourceService(name, {
...@@ -309,7 +316,7 @@ class TVAccessory { ...@@ -309,7 +316,7 @@ class TVAccessory {
get speaker_service() { get speaker_service() {
if (this._speaker_service) return this._speaker_service; if (this._speaker_service) return this._speaker_service;
const speaker_service = new this.constructor.hap.Service.Speaker(this.name); const speaker_service = new this.constructor.hap.Service.Speaker(this.name);
speaker_service.getCharacteristic(this.constructor.hap.Characteristic.Mute) speaker_service.getCharacteristic(this.constructor.hap.Characteristic.Mute)
......
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