UNPKG

homebridge-philips-hue-sync-box

Version:
67 lines 2.62 kB
import { BaseTvDevice } from './baseTv.js'; import { HDMI_INPUT_MAX, HDMI_INPUT_MIN } from '../lib/constants.js'; export class TvDevice extends BaseTvDevice { platform; accessory; state; mainAccessory; constructor(platform, accessory, state, mainAccessory) { super(platform, accessory, state, mainAccessory); this.platform = platform; this.accessory = accessory; this.state = state; this.mainAccessory = mainAccessory; this.service .getCharacteristic(this.platform.api.hap.Characteristic.ActiveIdentifier) .onSet(value => { const identifier = value; if (!Number.isInteger(identifier) || identifier < HDMI_INPUT_MIN || identifier > HDMI_INPUT_MAX) { this.platform.log.warn('Ignoring out-of-range HDMI input identifier: ' + identifier); return; } return this.updateExecution({ hdmiSource: 'input' + identifier, }); }); } updateTv() { this.platform.log.debug('Updated HDMI input to ' + this.state.execution.hdmiSource); this.service.updateCharacteristic(this.platform.api.hap.Characteristic.ActiveIdentifier, parseInt(this.state.execution.hdmiSource.replace('input', ''))); } getSuffix() { return '-T'; } getServiceSubType() { return 'TV'; } getServiceName() { return 'TV'; } getConfiguredNamePropertyName() { return 'tvAccessoryConfiguredName'; } isLightbulbEnabled() { return this.platform.config.tvAccessoryLightbulb; } createInputServices() { const services = []; for (let i = HDMI_INPUT_MIN; i <= HDMI_INPUT_MAX; i++) { // Sets the TV name const hdmiState = this.state.hdmi[`input${i}`]; const hdmiPosition = 'HDMI ' + i; const hdmiName = hdmiState.name ?? hdmiPosition; const hdmiInputService = this.getInputService(hdmiName, hdmiPosition); hdmiInputService .getCharacteristic(this.platform.api.hap.Characteristic.TargetVisibilityState) .onSet(this.setVisibility(hdmiInputService)); // Adds the input as a linked service, which is important so that the input is properly displayed in the Home app this.service.addLinkedService(hdmiInputService); services.push(hdmiInputService); } this.inputServices = services; this.updateSources(services); } } //# sourceMappingURL=tv.js.map