Skip to content

Commit 564bfbb

Browse files
committed
feat: add user configurable volume mutiplier
1 parent 732b1d9 commit 564bfbb

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

pioneer-avr-config.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
required: true,
1212
validate: RED.validators.number()
1313
},
14+
volumeMultiplier: {
15+
value: 0.4897959183673469,
16+
required: false,
17+
validate: v => v === undefined || typeof v === 'number',
18+
},
1419
name: {
1520
value: '',
1621
required: false,
@@ -33,6 +38,10 @@
3338
<label for="node-config-input-port"><i class="icon-bookmark"></i> Port</label>
3439
<input type="text" id="node-config-input-port" placeholder="8102">
3540
</div>
41+
<div class="form-row">
42+
<label for="node-config-input-volume-multiplier"><i class="icon-bookmark"></i> Volume Multiplier</label>
43+
<input type="text" id="node-config-input-volume-multiplier" placeholder="0.4897959183673469">
44+
</div>
3645
<div class="form-row">
3746
<label for="node-config-input-name"><i class="icon-bookmark"></i> Name</label>
3847
<input type="text" id="node-config-input-name">
@@ -41,12 +50,14 @@
4150

4251
<script type="text/x-red"
4352
data-help-name="pioneer-avr-config">
44-
<p>Configures a Yeelight connection to be used with "Yeelight Out" and "Yeelight State" nodes.</p>
53+
<p>Configures a Pioneer AVR receiver connection to be used with "Pioneer Out" and "Pioneer State" nodes.</p>
4554
<h3>Options</h3>
4655
<dl class="message-properties">
4756
<dt>Hostname <span class="property-type">string</span></dt>
4857
<dd>an IP address or other hostname that points to a Pioneer receiver on the network</dd>
4958
<dt>Port <span class="property-type">number</span></dt>
5059
<dd>port number the receiver is accessible over, default being <code>8102</code></dd>
60+
<dt>Volume Multiplier <span class="property-type">number</span></dt>
61+
<dd>a factor to multiply volume values sent by the receiver by, default being <code>0.4897959183673469</code></dd>
5162
</dl>
5263
</script>

src/PioneerAvrConfig.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import { Socket } from 'net';
33
const RECONNETION_INTERVAL_SECS = 5000;
44

55
export default function PioneerAvrConfig(RED) {
6-
console.log('-------> HI FROM WITHIN THE MODULE');
76
return function(config) {
8-
const { hostname, port } = config;
7+
const { hostname, port, volumeMultiplier = 0.4897959183673469 } = config;
98
const node = this;
109
const host = `${hostname}:${port}`;
1110
let reconnectionTimeout;
@@ -49,15 +48,15 @@ export default function PioneerAvrConfig(RED) {
4948
};
5049

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

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

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

7675
node.hostname = hostname;
7776
node.port = port;
77+
node.volumeMultiplier = volumeMultiplier;
7878

7979
if (hostname && port) {
8080
startConnection();
8181

8282
node.on('close', () => {
8383
node.log('Closing connection');
8484
clearTimeout(reconnectionTimeout);
85-
node.client.exit();
85+
node.client.end();
8686
});
8787
}
8888
})();

src/PioneerAvrOut.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ export default function PioneerAvrOut(RED) {
7474
}
7575

7676
if (data.startsWith('VOL')) {
77-
avrState.volume = parse(data.substring(3, 6));
77+
avrState.volume = Math.round(
78+
parse(data.substring(3, 6)) * node.serverConfig.volumeMultiplier
79+
);
7880
}
7981

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

106-
// console.log('handling message', msg);
107-
108108
if (isJson(msg)) {
109109
msg = JSON.parse(msg);
110110
}

0 commit comments

Comments
 (0)