Commit c89148ea authored by Samuel Elliott's avatar Samuel Elliott

Add disabling sources

parent 7c4d2601
......@@ -732,7 +732,20 @@ class TVAccessory {
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);
this.getInputSourceEnabledSync(id) ? 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 ?
this.constructor.hap.Characteristic.CurrentVisibilityState.SHOWN :
this.constructor.hap.Characteristic.CurrentVisibilityState.HIDDEN)).catch(callback))
.on('set', (visibility_state, callback) => this.setInputSourceEnabled(id,
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) ?
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);
......@@ -761,6 +774,21 @@ class TVAccessory {
await this.setItem('InputSource.' + id + '.ConfiguredName', name);
}
async getInputSourceEnabled(id) {
const enabled = await this.getItem('InputSource.' + id + '.Enabled');
return typeof enabled === 'boolean' ? enabled : true;
}
getInputSourceEnabledSync(id) {
const enabled = this.getItemSync('InputSource.' + id + '.Enabled');
return typeof enabled === 'boolean' ? enabled : true;
}
async setInputSourceEnabled(id, enabled) {
this.log('Setting enabled for Input Source service "%s" for %s', id, this.name);
await this.setItem('InputSource.' + id + '.Enabled', !!enabled);
}
//
// Television Speaker service
//
......
......@@ -7,6 +7,7 @@ const accessory_config = {
// port: 51826,
username: 'A3:FB:3D:4D:2E:AC',
pincode: '031-45-154',
category: Accessory.Categories.TELEVISION,
};
const config = require(process.argv[2] || './config');
......@@ -49,7 +50,7 @@ const accessory_instance = new accessory_types[config.accessory](log, config);
const services = accessory_instance.getServices();
const accessory_uuid = uuid.generate('hap-nodejs:accessories:tv');
const accessory = new Accessory('TV', accessory_uuid);
const accessory = new Accessory('TV', accessory_uuid, Accessory.Categories.TELEVISION);
for (let service of services) {
if (service instanceof Service.AccessoryInformation) {
......
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