UNPKG

homebridge-denon-speaker

Version:

Denon and Marantz AVR support as Speaker for Homebridge: https://github.com/nfarina/homebridge

99 lines 3.41 kB
"use strict"; /** * created by stfnhmplr on 28.01.16. * control your Denon AVR via http with node.js */ Object.defineProperty(exports, "__esModule", { value: true }); exports.DenonLib = void 0; const xml2js_1 = require("xml2js"); // The Denon AVR reports volume in dB from -80 to +18; HomeKit expects 0–98. const DENON_VOLUME_OFFSET = 80; class DenonLib { ip; url_main_zone_xml = '/goform/formMainZone_MainZoneXmlStatus.xml'; constructor(ip) { this.ip = ip; } async callHttp(url) { try { const response = await globalThis.fetch(url); return response.text(); } catch (error) { throw new Error(`HTTP error: ${error}`); } } async xml2DenonStatus(xml) { try { const jsResult = await (0, xml2js_1.parseStringPromise)(xml); return { zone: jsResult.item.Zone[0].value[0].trim(), powerState: jsResult.item.Power[0].value[0] === 'ON', inputSelected: jsResult.item.InputFuncSelect[0].value[0], surroundMode: jsResult.item.SurrMode[0].value[0], volumeState: parseInt(jsResult.item.MasterVolume[0].value[0]) + DENON_VOLUME_OFFSET, muteState: jsResult.item.Mute[0].value[0] === 'on', model: jsResult.item.Model[0].value[0], }; } catch (error) { throw new Error(`Erreur lors du parsing XML: ${error}`); } } async getModelInfo() { try { const status = await this.getStatus(); return { brand: 'Denon', model: status.model || 'AVR', }; } catch (error) { return { brand: 'Denon', model: 'AVR', }; } } async setPowerState(wantedPowerState) { try { const command = wantedPowerState ? 'ON' : 'OFF'; await this.callHttp(`http://${this.ip}/MainZone/index.put.asp?cmd0=PutZone_OnOff/${command}`); return wantedPowerState; } catch (error) { throw new Error(`Erreur lors du changement d'état: ${error}`); } } async setMuteState(wantedMuteState) { try { const command = wantedMuteState ? 'ON' : 'OFF'; await this.callHttp(`http://${this.ip}/MainZone/index.put.asp?cmd0=PutVolumeMute/${command}`); return wantedMuteState; } catch (error) { throw new Error(`Erreur lors du changement du mute: ${error}`); } } async setVolume(wantedVolumeState) { try { const vol = (+wantedVolumeState - DENON_VOLUME_OFFSET).toFixed(1); await this.callHttp(`http://${this.ip}/goform/formiPhoneAppVolume.xml?1+${vol}`); return wantedVolumeState; } catch (error) { throw new Error(`Erreur lors du changement de volume: ${error}`); } } async getStatus() { try { const xmlData = await this.callHttp(`http://${this.ip}${this.url_main_zone_xml}`); return this.xml2DenonStatus(xmlData); } catch (error) { throw new Error(`Erreur lors de la récupération du status: ${error}`); } } } exports.DenonLib = DenonLib; //# sourceMappingURL=denon-lib.js.map