Commit 32679571 authored by Samuel Elliott's avatar Samuel Elliott

Use Homebridge’s logger

parent 6575e802
......@@ -100,12 +100,12 @@ class TVAccessory {
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));
this.apple_tv.on('connect', () => this.log('Connected to %s Apple TV', this.name));
this.apple_tv.on('close', () => this.log('Disconnected from %s Apple TV', this.name));
this.apple_tv.on('error', err => this.log.error(this.name + ' Apple TV error', err));
this.apple_tv.address = this.apple_tv.service.host;
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;
......@@ -133,7 +133,7 @@ class TVAccessory {
if (this.media_renderer_location) {
this.media_renderer_client = new UPnPClient(this.media_renderer_location);
this.media_renderer_client.on('error', err => console.error('[UPnP] Error', err));
this.media_renderer_client.on('error', err => this.log.error('[UPnP] Error', err));
this.media_renderer_client.subscribe('RenderingControl', this.handleMediaRendererEvent);
}
......@@ -291,11 +291,11 @@ class TVAccessory {
new Promise((rs, reject) => setTimeout(reject, 2000)),
]);
this.log(this.name + ' is on');
this.log.debug(this.name + ' is on');
return true;
} catch (err) {
this.log(this.name + ' is off');
this.log.debug(this.name + ' is off');
return false;
}
......@@ -315,7 +315,7 @@ class TVAccessory {
this.last_input_switched = this.apple_tv_input;
if (this.expose_television_service) this.tv_service.getCharacteristic(this.constructor.hap.Characteristic.ActiveIdentifier).updateValue(this.apple_tv_input);
} catch (err) {
console.error(err);
this.log.error(err);
throw err;
}
......
......@@ -4,7 +4,7 @@ const hap = require('hap-nodejs');
const {Accessory, Service, Characteristic, uuid} = hap;
const accessory_config = {
port: 51826,
// port: 51826,
username: 'A3:FB:3D:4D:2E:AC',
pincode: '031-45-154',
};
......@@ -19,6 +19,11 @@ const homebridge_config = {
const homebridge_plugin = require('..');
const accessory_types = {};
const log = function (...args) {
console.log(...args);
};
Object.setPrototypeOf(log, console);
homebridge_plugin({
hap,
user: {
......@@ -31,13 +36,13 @@ homebridge_plugin({
registerAccessory: (package, type, accessory) => {
accessory_types[package + '.' + type] = accessory_types[type] = accessory;
},
});
}, log);
if (!accessory_types[config.accessory]) {
throw new Error('Unknown accessory "' + config.accessory + '"');
}
const accessory_instance = new accessory_types[config.accessory](console.log, config);
const accessory_instance = new accessory_types[config.accessory](log, config);
const services = accessory_instance.getServices();
const accessory_uuid = uuid.generate('hap-nodejs:accessories:tv');
......
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