UNPKG

homebridge-virtual-accessories

Version:
196 lines 7.92 kB
import { Accessory } from './accessory.js'; /** * InputSource - Accessory implementation */ export class InputSource extends Accessory { static ACCESSORY_TYPE_NAME = 'InputSource'; static OTHER = 0; // Characteristic.InputSourceType.OTHER static HOME_SCREEN = 1; // Characteristic.InputSourceType.HOME_SCREEN static TUNER = 2; // Characteristic.InputSourceType.TUNER static HDMI = 3; // Characteristic.InputSourceType.HDMI static COMPOSITE_VIDEO = 4; // Characteristic.InputSourceType.COMPOSITE_VIDEO static S_VIDEO = 5; // Characteristic.InputSourceType.S_VIDEO static COMPONENT_VIDEO = 6; // Characteristic.InputSourceType.COMPONENT_VIDEO static DVI = 7; // Characteristic.InputSourceType.DVI static AIRPLAY = 8; // Characteristic.InputSourceType.AIRPLAY static USB = 9; // Characteristic.InputSourceType.USB static APPLICATION = 10; // Characteristic.InputSourceType.APPLICATION static NOT_CONFIGURED = 0; // Characteristic.IsConfigured.NOT_CONFIGURED static CONFIGURED = 1; // Characteristic.IsConfigured.CONFIGURED static SHOWN = 0; // Characteristic.CurrentVisibilityState.SHOWN static HIDDEN = 1; // Characteristic.CurrentVisibilityState.HIDDEN states = { InputSourceConfiguredName: '', InputSourceType: InputSource.HDMI, InputSourceIsConfigured: true, InputSourceCurrentVisibilityState: InputSource.SHOWN, InputSourceIdentifier: 0, }; constructor(platform, accessory, accessoryConfiguration) { super(platform, accessory, accessoryConfiguration); const inputName = this.accessoryConfiguration.inputSource.name; // First configure the device based on the accessory details this.states.InputSourceConfiguredName = inputName; this.states.InputSourceType = this.accessoryConfiguration.inputSource.inputSourceType; this.states.InputSourceIdentifier = this.accessoryConfiguration.inputSource.identifier; // set accessory information this.service = this.accessory.getService(inputName) || this.accessory.addService(this.platform.Service.InputSource, inputName, accessory.UUID + inputName); this.service.setCharacteristic(this.platform.Characteristic.Name, inputName); // register handlers this.service.getCharacteristic(this.platform.Characteristic.ConfiguredName) .onSet(this.setConfiguredName.bind(this)) .onGet(this.getConfiguredName.bind(this)); this.service.getCharacteristic(this.platform.Characteristic.InputSourceType) .onGet(this.getInputSourceType.bind(this)); this.service.getCharacteristic(this.platform.Characteristic.IsConfigured) .onSet(this.setIsConfigured.bind(this)) .onGet(this.getIsConfigured.bind(this)); this.service.getCharacteristic(this.platform.Characteristic.CurrentVisibilityState) .onGet(this.getCurrentVisibilityState.bind(this)); this.service.getCharacteristic(this.platform.Characteristic.Identifier) .onGet(this.getIdentifier.bind(this)); } // Handlers async setConfiguredName(value) { // this.states.InputSourceConfiguredName = value as string; const configuredName = value; this.log.info(`[${this.accessoryConfiguration.accessoryName}] Setting Configured Name: ${configuredName}`); } async getConfiguredName() { const configuredName = this.states.InputSourceConfiguredName; this.log.debug(`[${this.accessoryConfiguration.accessoryName}] Getting Configured Name: ${configuredName}`); return configuredName; } async getInputSourceType() { const inputSourceType = this.states.InputSourceType; this.log.debug(`[${this.accessoryConfiguration.accessoryName}] Getting Input Source Type: ${InputSource.getTypeName(inputSourceType)}`); return inputSourceType; } async setIsConfigured(value) { // this.states.InputSourceIsConfigured = value as boolean; const isConfigured = value; this.log.info(`[${this.accessoryConfiguration.accessoryName}] Setting Is Configured: ${isConfigured}`); } async getIsConfigured() { const isConfigured = this.states.InputSourceIsConfigured; this.log.debug(`[${this.accessoryConfiguration.accessoryName}] Getting Is Configured: ${isConfigured}`); return isConfigured; } async getCurrentVisibilityState() { const currentVisibilityState = this.states.InputSourceCurrentVisibilityState; this.log.debug(`[${this.accessoryConfiguration.accessoryName}] Getting Current Visibility State: ${InputSource.getVisibilityName(currentVisibilityState)}`); return currentVisibilityState; } async getIdentifier() { const identifier = this.states.InputSourceIdentifier; this.log.debug(`[${this.accessoryConfiguration.accessoryName}] Getting Identifier: ${identifier}`); return identifier; } getJsonState() { return JSON.stringify({}); } getAccessoryTypeName() { return InputSource.ACCESSORY_TYPE_NAME; } static getTypeName(event) { let eventName; switch (event) { case undefined: { eventName = 'undefined'; break; } case InputSource.OTHER: { eventName = 'OTHER'; break; } case InputSource.HOME_SCREEN: { eventName = 'HOME SCREEN'; break; } case InputSource.TUNER: { eventName = 'TUNER'; break; } case InputSource.HDMI: { eventName = 'HDMI'; break; } case InputSource.COMPOSITE_VIDEO: { eventName = 'COMPOSITE VIDEO'; break; } case InputSource.S_VIDEO: { eventName = 'S VIDEO'; break; } case InputSource.COMPONENT_VIDEO: { eventName = 'COMPONENT VIDEO'; break; } case InputSource.DVI: { eventName = 'DVI'; break; } case InputSource.AIRPLAY: { eventName = 'AIRPLAY'; break; } case InputSource.USB: { eventName = 'USB'; break; } case InputSource.APPLICATION: { eventName = 'APPLICATION'; break; } default: { eventName = event.toString(); } } return eventName; } static getConfiguredName(event) { let eventName; switch (event) { case undefined: { eventName = 'undefined'; break; } case InputSource.NOT_CONFIGURED: { eventName = 'NOT CONFIGURED'; break; } case InputSource.CONFIGURED: { eventName = 'CONFIGURED'; break; } default: { eventName = event.toString(); } } return eventName; } static getVisibilityName(event) { let eventName; switch (event) { case undefined: { eventName = 'undefined'; break; } case InputSource.SHOWN: { eventName = 'SHOWN'; break; } case InputSource.HIDDEN: { eventName = 'HIDDEN'; break; } default: { eventName = event.toString(); } } return eventName; } } //# sourceMappingURL=virtualAccessoryInputSource.js.map