UNPKG

homebridge-philips-hue-sync-box

Version:
83 lines 2.97 kB
import { BaseTvDevice } from './baseTv.js'; export class EntertainmentTvDevice 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 => { // Gets the ID of the group based on the index let groupId = null; let i = 1; for (const currentGroupId in this.state.hue.groups) { if (i === value) { groupId = currentGroupId; break; } i++; } // @ts-expect-error need to use self as a key const group = this.state.hue.groups[groupId]; if (!group || !groupId) { return; } // Saves the changes this.platform.log.debug('Switch entertainment area to ' + group.name); this.platform.client .updateHue({ groupId: groupId, }) .catch(e => { this.platform.log.error('Failed to switch entertainment area to ' + group.name, e); }); }); } updateTv() { // Gets the ID of the group based on the index let index = 1; for (const currentGroupId in this.state.hue.groups) { if (currentGroupId === this.state.hue.groupId) { break; } index++; } // Updates the input characteristic this.service.updateCharacteristic(this.platform.api.hap.Characteristic.ActiveIdentifier, index); } getSuffix() { return '-E'; } getServiceSubType() { return 'EntertainmentTVAccessory'; } getServiceName() { return 'Entertainment Area'; } getConfiguredNamePropertyName() { return 'entertainmentTvAccessoryConfiguredName'; } isLightbulbEnabled() { return this.platform.config.intensityTvAccessoryLightbulb; } createInputServices() { let i = 1; for (const groupId in this.state.hue.groups) { const group = this.state.hue.groups[groupId]; const name = group.name; const position = 'AREA ' + i; const entertainmentInputService = this.getInputService(name, position); // Adds the input as a linked service, which is important so that the input is properly displayed in the Home app this.service.addLinkedService(entertainmentInputService); this.inputServices.push(entertainmentInputService); i++; } } } //# sourceMappingURL=entertainmentTv.js.map