this.on('close', () => { this.debug('remove event listeners'); tvService.getCharacteristic(Characteristic.Active) .removeListener('set', setActive); tvService.getCharacteristic(Characteristic.ActiveIdentifier) .removeListener('set', setActiveIdentifier); tvService.getCharacteristic(Characteristic.RemoteKey) .removeListener('set', setRemoteKey); tvService.getCharacteristic(Characteristic.PowerModeSelection) .removeListener('set', setPowerModeSelection); speakerService.getCharacteristic(Characteristic.VolumeSelector) .removeListener('set', setVolumeSelector); });
this.on('input', msg => { switch (msg.topic) { case 'InputSource': { let identifier = msg.payload; if (typeof msg.payload === 'string') { config.inputsources.forEach((src, i) => { if (msg.payload === src.name) { identifier = i + 1; } }); } if (config.inputsources[identifier - 1]) { this.debug('set ActiveIdentifier ' + identifier + ' (payload was ' + msg.payload + ')'); this.status({shape: 'dot', fill: 'blue', text: config.inputsources[identifier - 1].name}); tvService.updateCharacteristic(Characteristic.ActiveIdentifier, identifier); } break; } default: this.debug('set Active ' + msg.payload); this.status({shape: msg.payload ? 'dot' : 'ring', fill: msg.payload ? 'blue' : 'grey'}); tvService.updateCharacteristic(Characteristic.Active, msg.payload ? 1 : 0); } });