Commit 86df3463 authored by Samuel Elliott's avatar Samuel Elliott

Fix configured names

parent c3602003
......@@ -436,8 +436,11 @@ class TVAccessory {
const tv_service = new this.constructor.hap.Service.Television(this.name);
tv_service.getCharacteristic(this.constructor.hap.Characteristic.Active)
.on('get', callback => this.getPowerState().then(data => callback(undefined, data ? this.constructor.hap.Characteristic.Active.ACTIVE : this.constructor.hap.Characteristic.Active.INACTIVE)).catch(callback))
.on('set', (on, callback) => this.setPowerState(on === this.constructor.hap.Characteristic.Active.ACTIVE ? true : false).then(data => callback(undefined, data)).catch(callback));
.on('get', callback => this.getPowerState().then(data => callback(undefined, data ?
this.constructor.hap.Characteristic.Active.ACTIVE :
this.constructor.hap.Characteristic.Active.INACTIVE)).catch(callback))
.on('set', (on, callback) => this.setPowerState(on === this.constructor.hap.Characteristic.Active.ACTIVE ?
true : false).then(data => callback(undefined, data)).catch(callback));
tv_service.getCharacteristic(this.constructor.hap.Characteristic.ActiveIdentifier)
.on('get', callback => this.getInputIdentifier().then(data => callback(undefined, data)).catch(callback))
......@@ -445,9 +448,12 @@ class TVAccessory {
tv_service.getCharacteristic(this.constructor.hap.Characteristic.ConfiguredName)
.on('get', callback => this.getConfiguredName().then(data => callback(undefined, data)).catch(callback))
.on('set', (name, callback) => this.setConfiguredName(name).then(data => callback(undefined, data)).catch(callback));
.on('set', (name, callback) => this.setConfiguredName(name).then(data => callback(undefined, data)).catch(callback))
.updateValue(this.getConfiguredNameSync());
tv_service.setCharacteristic(this.constructor.hap.Characteristic.SleepDiscoveryMode, this.apple_tv ? this.constructor.hap.Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE : this.constructor.hap.Characteristic.SleepDiscoveryMode.NOT_DISCOVERABLE);
tv_service.setCharacteristic(this.constructor.hap.Characteristic.SleepDiscoveryMode, this.apple_tv ?
this.constructor.hap.Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE :
this.constructor.hap.Characteristic.SleepDiscoveryMode.NOT_DISCOVERABLE);
tv_service.getCharacteristic(this.constructor.hap.Characteristic.RemoteKey)
.on('set', (key, callback) => this.sendRemoteKey(key).then(data => callback(undefined, data)).catch(callback));
......@@ -504,6 +510,10 @@ class TVAccessory {
return await this.getItem('ConfiguredName');
}
getConfiguredNameSync() {
return this.getItemSync('ConfiguredName');
}
async setConfiguredName(name) {
this.log('Setting configured name for Television service for ' + this.name + ': ' + name);
await this.setItem('ConfiguredName', name);
......@@ -514,7 +524,8 @@ class TVAccessory {
throw new Error('Unsupported remote key');
}
const name = Object.keys(this.constructor.hap.Characteristic.RemoteKey)[Object.values(this.constructor.hap.Characteristic.RemoteKey).findIndex(value => value === key)];
const name = Object.keys(this.constructor.hap.Characteristic.RemoteKey)
[Object.values(this.constructor.hap.Characteristic.RemoteKey).findIndex(value => value === key)];
this.log('Sending key ' + key_map[key] + ' (' + name + ': ' + key + ') to ' + this.name);
......@@ -544,18 +555,23 @@ class TVAccessory {
if (typeof config !== 'object') config = {};
input_service.config = config;
input_service.setCharacteristic(this.constructor.hap.Characteristic.InputSourceType, typeof type === 'number' ? type : this.constructor.hap.Characteristic.InputSourceType[type]);
input_service.setCharacteristic(this.constructor.hap.Characteristic.InputSourceType,
typeof type === 'number' ? type : this.constructor.hap.Characteristic.InputSourceType[type]);
if (subtype) {
input_service.setCharacteristic(this.constructor.hap.Characteristic.InputDeviceType, typeof subtype === 'number' ? subtype : this.constructor.hap.Characteristic.InputDeviceType[subtype]);
input_service.setCharacteristic(this.constructor.hap.Characteristic.InputDeviceType,
typeof subtype === 'number' ? subtype : this.constructor.hap.Characteristic.InputDeviceType[subtype]);
}
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));
.on('set', (name, callback) => this.setInputSourceName(id, name).then(data => callback(undefined, data)).catch(callback))
.updateValue(this.getInputSourceNameSync(id));
input_service.setCharacteristic(this.constructor.hap.Characteristic.IsConfigured, this.constructor.hap.Characteristic.IsConfigured.CONFIGURED);
input_service.setCharacteristic(this.constructor.hap.Characteristic.CurrentVisibilityState, this.constructor.hap.Characteristic.CurrentVisibilityState.SHOWN);
input_service.setCharacteristic(this.constructor.hap.Characteristic.IsConfigured,
this.constructor.hap.Characteristic.IsConfigured.CONFIGURED);
input_service.setCharacteristic(this.constructor.hap.Characteristic.CurrentVisibilityState,
this.constructor.hap.Characteristic.CurrentVisibilityState.SHOWN);
input_service.setCharacteristic(this.constructor.hap.Characteristic.Identifier, this.input_source_services.length);
......@@ -586,6 +602,10 @@ class TVAccessory {
return await this.getItem('InputSource.' + id + '.ConfiguredName');
}
getInputSourceNameSync(id) {
return this.getItemSync('InputSource.' + id + '.ConfiguredName');
}
async setInputSourceName(id, name) {
this.log('Setting configured name for Input Source service "' + id + '" for ' + this.name + ': ' + name);
await this.setItem('InputSource.' + id + '.ConfiguredName', name);
......@@ -606,7 +626,8 @@ class TVAccessory {
.on('get', callback => this.getVolume().then(data => callback(undefined, data)).catch(callback))
.on('set', (volume, callback) => this.setVolume(volume).then(data => callback(undefined, data)).catch(callback));
speaker_service.setCharacteristic(this.constructor.hap.Characteristic.VolumeControlType, this.constructor.hap.Characteristic.VolumeControlType.ABSOLUTE);
speaker_service.setCharacteristic(this.constructor.hap.Characteristic.VolumeControlType,
this.constructor.hap.Characteristic.VolumeControlType.ABSOLUTE);
return Object.defineProperty(this, 'tv_speaker_service', {configurable: true, value: speaker_service}).tv_speaker_service;
}
......
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