From b80ad30263743e86eb28ba319d3cfb3f802e1258 Mon Sep 17 00:00:00 2001 From: Robert Vorthman Date: Sun, 4 Dec 2016 16:10:48 +0000 Subject: [PATCH] made mapMaxVolumeTo100 an option, fixed volume calculations, fake power state defaults to on so that brightness will update in Home app --- Readme.md | 29 +++++++++++++++++++++++++---- index.js | 27 +++++++++++++++++++++------ package.json | 2 +- 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/Readme.md b/Readme.md index e40e4d1..9f39a88 100644 --- a/Readme.md +++ b/Readme.md @@ -38,7 +38,23 @@ iOS 10 adds HomeKit shortcuts to the iOS Control Center, so you can adjust the v # Configuration -Add the plugin as an accessory to have it control the main zone for your AVR. If your receiver supports a 2nd zone, add +Add as an accessory by editing the homebridge config.json file. + +## Simple Example + +``` +"accessories": [ + { + "accessory": "marantz-volume", + "name": "Stereo Volume", + "host": "192.168.1.15" + } +] +``` + +## Multiple Zones Example + +If your receiver supports a 2nd zone, add the plugin a second time with `"zone":2` in the accessory properties, the same host, and a different name. Configuration sample: @@ -63,13 +79,18 @@ Configuration sample: ] ``` - -In this example, the receiver has two zones, the volume control works for both zones (named "Stereo Volume" and "Outside Volume"), +In the above example, the receiver has two zones, the volume control works for both zones (named "Stereo Volume" and "Outside Volume"), and the power control works is ignored for the main zone and is enabled for the second zone. +## Additional Configuration Details + +The option `maxVolume` defaults to 70 unless otherwise specified as a values between 0 and 100. + +Setting `"mapMaxVolumeTo100":true` will remap the volume percentages that appear in the Home app so that the configured maxVolume will appear as 100% in the Home app. For example, if the maxVolume is 70%, then setting the stereo volume brightness to 50% would set the receiver's volume to 35%. Adjusting the stereo volume knob to 70 will appear as 100% brightness in the Home app. This option could confuse some users to it defaults to off `false`, but it does give the user finer volume control especially when sliding the brightness slider up and down in the Home app. + # Special Thanks This plugin was built upon code from the following homebridge plugins https://www.npmjs.com/package/homebridge-fakebulb by schemish -https://www.npmjs.com/package/homebridge-denon by stfnhmplr +https://www.npmjs.com/package/homebridge-denon by stfnhmplr \ No newline at end of file diff --git a/index.js b/index.js index 52bc93f..6674c13 100644 --- a/index.js +++ b/index.js @@ -37,7 +37,7 @@ function ReceiverVolume(log, config) { this.zoneName = this.zone === 1 ? "MainZone" : "Zone2"; if (!this.controlPower) { - this.fakePowerState = 0; + this.fakePowerState = 1; //default to on so that brightness will update in HomeKit apps } } @@ -94,10 +94,11 @@ ReceiverVolume.prototype.setPowerOn = function(powerOn, callback) { ReceiverVolume.prototype.setBrightness = function(newLevel, callback) { if(this.mapMaxVolumeTo100){ - var volumeMultiplier = 98/this.maxVolume; //Denon/Marantz percentage maxes at 98 in receiver settings + var volumeMultiplier = this.maxVolume/100; var newVolume = volumeMultiplier * newLevel; }else{ - var newVolume = Math.max(newLevel, this.maxVolume); + //cap to max volume set in homebridge config.json + var newVolume = Math.min(newLevel, this.maxVolume); } //cap newVolume. //Denon/Marantz percentage maxes at 98 in receiver settings @@ -110,14 +111,28 @@ ReceiverVolume.prototype.setBrightness = function(newLevel, callback) { //cap between -80 and 0 relativeVolume = Math.max(-80.0, Math.min(0.0, relativeVolume)); - + this.setControl('Volume', relativeVolume, callback); } ReceiverVolume.prototype.getBrightness = function(callback) { this.getStatus(function(status) { - var volume = -status.MasterVolume[0].value[0] / 80.0 * 100.0; - callback(null, volume); + + if(status){ + var volume = parseInt(status.MasterVolume[0].value[0]) + 80; + this.log("Get receiver volume %s ", volume); + + if(this.mapMaxVolumeTo100){ + volume = volume * (100/this.maxVolume); + } + + + callback(null, volume); + }else{ + this.log("Unable to get receiver status"); + callback(null); + } + }.bind(this)); } diff --git a/package.json b/package.json index 00d0362..69bd3c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homebridge-marantz-volume", - "version": "1.2.2", + "version": "1.3.0", "description": "Homebridge plugin to control Denon or Marantz receiver volume with Siri commands", "main": "index.js", "repository": {