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.
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
......
This diff is collapsed.
......@@ -3,6 +3,8 @@ const persist = require('node-persist');
const {VestelNetworkRemote, VestelFollowTV} = require('vestel-network-remote');
const UPnPClient = require('@langovoi/upnp-device-client');
let AppleTV;
const key_map = {};
module.exports = function (homebridge) {
......@@ -13,6 +15,13 @@ module.exports = function (homebridge) {
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));
Object.assign(key_map, {
......@@ -73,15 +82,13 @@ class TVAccessory {
this.expose_speaker_lightbulb_service = config.expose_speaker_lightbulb_service !== undefined
? 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');
}
// Connect to an Apple TV
// This is used to turn the TV on
if (config.apple_tv) {
const AppleTV = require('node-appletv');
if (config.apple_tv && AppleTV) {
const credentials = typeof config.apple_tv === 'string'
? AppleTV.parseCredentials(config.apple_tv) : typeof config.apple_tv === 'array'
? AppleTV.parseCredentials(config.apple_tv.join(':')) : new AppleTV.Credentials(
......@@ -126,13 +133,13 @@ class TVAccessory {
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);
}
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;
tv_channel_input_source_services.push(this.addAppInputSourceService(name, {
......
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