UNPKG

@george.talusan/homebridge-eufy-robovac

Version:
106 lines 3.31 kB
; export class SpeakerPlatformAccessory { platform; accessory; volume = 0; constructor(platform, accessory) { this.platform = platform; this.accessory = accessory; const displayName = this.accessory.context.displayName; this.accessory.getService(this.platform.Service.AccessoryInformation) .setCharacteristic(this.platform.Characteristic.Manufacturer, 'Eufy') .setCharacteristic(this.platform.Characteristic.Model, 'Robovac') .setCharacteristic(this.platform.Characteristic.SerialNumber, 'Default-Serial'); const main = this.accessory.getService(`${displayName}`) || this.accessory.addService(this.platform.Service.Speaker, `${displayName}`, 'volume'); main.getCharacteristic(this.platform.Characteristic.Active) .onSet(this.setActive.bind(this)) .onGet(this.getActive.bind(this)); main.getCharacteristic(this.platform.Characteristic.Volume) .onSet(this.setVolume.bind(this)) .onGet(this.getVolume.bind(this)); main.getCharacteristic(this.platform.Characteristic.Mute) .onSet(this.setMute.bind(this)) .onGet(this.getMute.bind(this)); const updateVolumeLevel = () => { if (!this.connected()) { return; } try { this.volume = this.platform.robovac.volume(); main.updateCharacteristic(this.platform.Characteristic.Volume, this.volume); } catch (error) { this.platform.log.error(error); } }; this.platform.robovac.on('tuya.data', updateVolumeLevel); this.platform.robovac.on('event', (event) => { if (event.command === 'volume') { updateVolumeLevel(); } }); } connected() { if (!this.platform.connected) { this.platform.log.warn('not connected'); } return this.platform.connected; } async setActive() { } async getActive() { return true; } async setVolume(value) { if (!this.connected()) { return; } if (this.volume === value) { return; } try { await this.platform.robovac.setVolume(value); } catch (error) { this.platform.log.error(error); } } async getVolume() { if (!this.connected()) { return 0; } try { return this.volume; } catch (error) { this.platform.log.error(error); return 0; } } async setMute(value) { if (!this.connected()) { return; } try { const on = value; await this.platform.robovac.setVolume(on ? 0 : this.volume); } catch (error) { this.platform.log.error(error); } } async getMute() { if (!this.connected()) { return false; } try { return this.volume === 0; } catch (error) { this.platform.log.error(error); return false; } } } //# sourceMappingURL=speakerAccessory.js.map