diff --git a/pioneer-avr-config.html b/pioneer-avr-config.html
index ac313b2..a059a8e 100644
--- a/pioneer-avr-config.html
+++ b/pioneer-avr-config.html
@@ -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,
@@ -33,6 +38,10 @@
+
+
+
+
@@ -41,12 +50,14 @@
diff --git a/src/PioneerAvrConfig.js b/src/PioneerAvrConfig.js
index 19bf788..c7a4dfd 100644
--- a/src/PioneerAvrConfig.js
+++ b/src/PioneerAvrConfig.js
@@ -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;
@@ -49,7 +48,7 @@ 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);
@@ -57,7 +56,7 @@ export default function PioneerAvrConfig(RED) {
};
const startConnection = () => {
- node.log(`Connecting to Pioneer ${host}`);
+ node.log(`Connecting to ${host}`);
node.client = new Socket();
node.client.connect(
port,
@@ -75,6 +74,7 @@ export default function PioneerAvrConfig(RED) {
node.hostname = hostname;
node.port = port;
+ node.volumeMultiplier = volumeMultiplier;
if (hostname && port) {
startConnection();
@@ -82,7 +82,7 @@ export default function PioneerAvrConfig(RED) {
node.on('close', () => {
node.log('Closing connection');
clearTimeout(reconnectionTimeout);
- node.client.exit();
+ node.client.end();
});
}
})();
diff --git a/src/PioneerAvrOut.js b/src/PioneerAvrOut.js
index c0e3bf5..d6e85ef 100644
--- a/src/PioneerAvrOut.js
+++ b/src/PioneerAvrOut.js
@@ -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')) {
@@ -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);
}