Skip to content

Commit

Permalink
feat: add user configurable volume mutiplier
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmattmatt committed Dec 2, 2018
1 parent 732b1d9 commit 564bfbb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
13 changes: 12 additions & 1 deletion pioneer-avr-config.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
required: true,
validate: RED.validators.number()
},
volumeMultiplier: {
value: 0.4897959183673469,
required: false,
validate: v => v === undefined || typeof v === 'number',
},
name: {
value: '',
required: false,
Expand All @@ -33,6 +38,10 @@
<label for="node-config-input-port"><i class="icon-bookmark"></i> Port</label>
<input type="text" id="node-config-input-port" placeholder="8102">
</div>
<div class="form-row">
<label for="node-config-input-volume-multiplier"><i class="icon-bookmark"></i> Volume Multiplier</label>
<input type="text" id="node-config-input-volume-multiplier" placeholder="0.4897959183673469">
</div>
<div class="form-row">
<label for="node-config-input-name"><i class="icon-bookmark"></i> Name</label>
<input type="text" id="node-config-input-name">
Expand All @@ -41,12 +50,14 @@

<script type="text/x-red"
data-help-name="pioneer-avr-config">
<p>Configures a Yeelight connection to be used with "Yeelight Out" and "Yeelight State" nodes.</p>
<p>Configures a Pioneer AVR receiver connection to be used with "Pioneer Out" and "Pioneer State" nodes.</p>
<h3>Options</h3>
<dl class="message-properties">
<dt>Hostname <span class="property-type">string</span></dt>
<dd>an IP address or other hostname that points to a Pioneer receiver on the network</dd>
<dt>Port <span class="property-type">number</span></dt>
<dd>port number the receiver is accessible over, default being <code>8102</code></dd>
<dt>Volume Multiplier <span class="property-type">number</span></dt>
<dd>a factor to multiply volume values sent by the receiver by, default being <code>0.4897959183673469</code></dd>
</dl>
</script>
10 changes: 5 additions & 5 deletions src/PioneerAvrConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { Socket } from 'net';
const RECONNETION_INTERVAL_SECS = 5000;

export default function PioneerAvrConfig(RED) {
console.log('-------> HI FROM WITHIN THE MODULE');
return function(config) {
const { hostname, port } = config;
const { hostname, port, volumeMultiplier = 0.4897959183673469 } = config;
const node = this;
const host = `${hostname}:${port}`;
let reconnectionTimeout;
Expand Down Expand Up @@ -49,15 +48,15 @@ export default function PioneerAvrConfig(RED) {
};

const onError = error => {
console.error(`Error at ${host}`, error);
console.error(`pioneer-avr-config: Error at ${host}`, error);
clearTimeout(reconnectionTimeout);
reconnectionTimeout = setTimeout(startConnection, RECONNETION_INTERVAL_SECS);

setNodeStatus(states.error(error.code || 'unknown'));
};

const startConnection = () => {
node.log(`Connecting to Pioneer ${host}`);
node.log(`Connecting to ${host}`);
node.client = new Socket();
node.client.connect(
port,
Expand All @@ -75,14 +74,15 @@ export default function PioneerAvrConfig(RED) {

node.hostname = hostname;
node.port = port;
node.volumeMultiplier = volumeMultiplier;

if (hostname && port) {
startConnection();

node.on('close', () => {
node.log('Closing connection');
clearTimeout(reconnectionTimeout);
node.client.exit();
node.client.end();
});
}
})();
Expand Down
6 changes: 3 additions & 3 deletions src/PioneerAvrOut.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export default function PioneerAvrOut(RED) {
}

if (data.startsWith('VOL')) {
avrState.volume = parse(data.substring(3, 6));
avrState.volume = Math.round(
parse(data.substring(3, 6)) * node.serverConfig.volumeMultiplier
);
}

if (data.startsWith('MUT')) {
Expand Down Expand Up @@ -103,8 +105,6 @@ export default function PioneerAvrOut(RED) {
isBusy = true;
let msg = queue.shift();

// console.log('handling message', msg);

if (isJson(msg)) {
msg = JSON.parse(msg);
}
Expand Down

0 comments on commit 564bfbb

Please sign in to comment.