UNPKG

@petro-kushchak/homebridge-homepod-radio

Version:

Homebridge accessory for streaming radio to Homepod Mini and Apple TV

55 lines 2.58 kB
import { PLUGIN_MANUFACTURER, PLUGIN_MODEL } from './platformConstants.js'; export class HomepodRadioSwitchAccessory { platform; accessory; streamer; service; informationService; constructor(platform, accessory, streamer) { this.platform = platform; this.accessory = accessory; this.streamer = streamer; this.service = this.accessory.getService(this.platform.Service.Switch) || this.accessory.addService(this.platform.Service.Switch); this.service .getCharacteristic(this.platform.Characteristic.On) .on("get" /* CharacteristicEventTypes.GET */, (callback) => { this.platform.logger.debug(`[${this.streamer.streamerName()} Radio Switch] GET ON`); callback(undefined, this.streamer.isPlaying()); }) .on("set" /* CharacteristicEventTypes.SET */, (value, callback) => { this.platform.logger.info(`[${this.streamer.streamerName()} Radio Switch] SET ON: ${value}`); if (value) { this.streamer.startPlaying(); } else { this.streamer.stopPlaying(); } callback(); }); this.informationService = this.accessory.getService(this.platform.Service.AccessoryInformation) || this.accessory.addService(this.platform.Service.AccessoryInformation); this.informationService .setCharacteristic(this.platform.Characteristic.Manufacturer, PLUGIN_MANUFACTURER) .setCharacteristic(this.platform.Characteristic.Model, PLUGIN_MODEL) .setCharacteristic(this.platform.Characteristic.SerialNumber, this.platform.platformConfig.serialNumber) .setCharacteristic(this.platform.Characteristic.Name, this.streamer.streamerName() + ' Switch'); // This will do its best to keep the actual outputs status up to date with Homekit. setInterval(async () => { this.service .getCharacteristic(this.platform.Characteristic.On) .updateValue(this.streamer.isPlaying()); }, 3000); this.platform.logger.info(`[${this.streamer.streamerName()} Radio Switch] Finished initializing`); } /* * This method is called directly after creation of this instance. * It should return all services which should be added to the accessory. */ getServices() { return [this.informationService, this.service]; } } //# sourceMappingURL=platformRadioSwitchAccessory.js.map