Commit 2446c798 authored by Samuel Elliott's avatar Samuel Elliott

Use input source type, device type and name for saved configured name and enabled flag

parent 274199de
......@@ -12,7 +12,7 @@ module.exports = function (homebridge) {
storage.initSync({
dir: homebridge.user.persistPath(),
stringify: data => JSON.stringify(data, undefined, 4),
stringify: data => JSON.stringify(data, undefined, 4) + '\n',
});
try {
......@@ -292,7 +292,7 @@ class TVAccessory {
tv_channel_input_source_services.push(this.addAppInputSourceService(name, {
name,
input_source_type: this.constructor.hap.Characteristic.InputSourceType.TUNER,
input_source_type: 'TUNER',
channel_number,
}));
}
......@@ -707,8 +707,6 @@ class TVAccessory {
}
addInputSourceService(id, config, type, subtype) {
const input_service = new this.constructor.hap.Service.InputSource(config.name, config.name || id);
if (!type) {
if (typeof config === 'object') type = config.input_source_type;
if (config instanceof Array) type = config[0];
......@@ -718,6 +716,14 @@ class TVAccessory {
if (config instanceof Array) subtype = config[1];
}
const identifier = type + (subtype ? '.' + subtype : '') + '.' + (config.name || id);
const input_service = new this.constructor.hap.Service.InputSource(config.name, identifier);
const index = this.input_source_services.length;
this.input_source_services.push(input_service);
this.tv_service.addLinkedService(input_service);
if (typeof config !== 'object') config = {};
input_service.config = config;
......@@ -730,38 +736,35 @@ class TVAccessory {
}
input_service.getCharacteristic(this.constructor.hap.Characteristic.ConfiguredName)
.on('get', callback => this.getInputSourceName(id).then(data => callback(undefined, data)).catch(callback))
.on('set', (name, callback) => this.setInputSourceName(id, name).then(data => callback(undefined, data)).catch(callback))
.updateValue(this.getInputSourceNameSync(id));
.on('get', callback => this.getInputSourceName(identifier).then(data => callback(undefined, data)).catch(callback))
.on('set', (name, callback) => this.setInputSourceName(identifier, name).then(data => callback(undefined, data)).catch(callback))
.updateValue(this.getInputSourceNameSync(identifier));
input_service.setCharacteristic(this.constructor.hap.Characteristic.IsConfigured,
this.constructor.hap.Characteristic.IsConfigured.CONFIGURED);
input_service.setCharacteristic(this.constructor.hap.Characteristic.CurrentVisibilityState,
this.getInputSourceEnabledSync(id) ? this.constructor.hap.Characteristic.CurrentVisibilityState.SHOWN :
this.getInputSourceEnabledSync(identifier) ? this.constructor.hap.Characteristic.CurrentVisibilityState.SHOWN :
this.constructor.hap.Characteristic.CurrentVisibilityState.HIDDEN);
input_service.getCharacteristic(this.constructor.hap.Characteristic.TargetVisibilityState)
.on('get', callback => this.getInputSourceEnabled(id).then(enabled => callback(null, enabled ?
.on('get', callback => this.getInputSourceEnabled(identifier).then(enabled => callback(null, enabled ?
this.constructor.hap.Characteristic.CurrentVisibilityState.SHOWN :
this.constructor.hap.Characteristic.CurrentVisibilityState.HIDDEN)).catch(callback))
.on('set', (visibility_state, callback) => this.setInputSourceEnabled(id,
.on('set', (visibility_state, callback) => this.setInputSourceEnabled(identifier,
visibility_state === this.constructor.hap.Characteristic.TargetVisibilityState.SHOWN
).then(data => callback(null, data)).then(() =>
input_service.setCharacteristic(this.constructor.hap.Characteristic.CurrentVisibilityState, visibility_state)).catch(callback))
.updateValue(this.getInputSourceEnabledSync(id) ?
.updateValue(this.getInputSourceEnabledSync(identifier) ?
this.constructor.hap.Characteristic.CurrentVisibilityState.SHOWN :
this.constructor.hap.Characteristic.CurrentVisibilityState.HIDDEN);
input_service.setCharacteristic(this.constructor.hap.Characteristic.Identifier, this.input_source_services.length);
this.input_source_services.push(input_service);
this.tv_service.addLinkedService(input_service);
input_service.setCharacteristic(this.constructor.hap.Characteristic.Identifier, index);
return input_service;
}
addAppInputSourceService(id, config) {
if (config.input_source_type === undefined) config.input_source_type = this.constructor.hap.Characteristic.InputSourceType.APPLICATION;
if (config.input_source_type === undefined) config.input_source_type = 'APPLICATION';
return this.addInputSourceService(id, config);
}
......
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