node-red-contrib-denon
Advanced tools
Sorry, the diff of this file is not supported yet
+35
-23
@@ -7,7 +7,7 @@ <script type="text/x-red" data-template-name="denon-controller"> | ||
| <div class="form-row"> | ||
| <label for="node-config-input-host"><i class="icon-bookmark"></i> denon Host</label> | ||
| <label for="node-config-input-host"><i class="icon-bookmark"></i> Denon Host</label> | ||
| <input type="text" id="node-config-input-host"> | ||
| </div> | ||
| <div class="form-row"> | ||
| <label for="node-config-input-port"><i class="icon-bookmark"></i> denon Port</label> | ||
| <label for="node-config-input-port"><i class="icon-bookmark"></i> Denon Port</label> | ||
| <input type="text" id="node-config-input-port"> | ||
@@ -47,16 +47,39 @@ </div> | ||
| <p> | ||
| Use this to <b>send</b> JSON RPC commands to a Denon player.<br/> | ||
| Use this to <b>send</b> commands to a Denon AVRs.<br/> | ||
| <b>msg.payload</b> must be a JavaScript object or a string | ||
| </p> | ||
| <p> | ||
| For example, simple string (command does not hav arguments): <code>Input.Home</code><br/> | ||
| For example, simple string (command does not has arguments): <code>PWON</code> | ||
| </p> | ||
| <p> | ||
| If topic if filled, it will be handled as command nad payload will be an argument, for example msg object may contain fields:<br/> | ||
| <pre>{ | ||
| "topic": "SetVolumeDB", | ||
| "payload" : -60.5 | ||
| }</pre> | ||
| </p> | ||
| Or Javascript object (command + parameters): | ||
| <pre>{ | ||
| "cmd": "Player.Stop", | ||
| "cmd": "SetVolumeDB", | ||
| "args" :{ | ||
| "playerid": 0 | ||
| } | ||
| "volume": 0 | ||
| }</pre> | ||
| <p> | ||
| <h2>Supported commands:</h2> | ||
| <ul> | ||
| <li>All from official <a href="https://github.com/estbeetoo/node-red-contrib-denon/blob/master/doc/AVR3312CI_AVR3312_PROTOCOL_V7.6.0.pdf">Denon AVR protocol</a></li> | ||
| <li> | ||
| SetVolumeDB<br/> | ||
| Params: | ||
| <code>volume</code>: | ||
| <ul> | ||
| <li>type: <b>float</b></li> | ||
| <li>range: from <b>-80.0</b> to <b>+1.0</b></li> | ||
| </ul> | ||
| </li> | ||
| </ul> | ||
| </p> | ||
| }</pre> | ||
| </p> | ||
| <p>Look at official Denon's JSON-RPC API: <a href="http://denon.wiki/view/JSON-RPC_API/v6" target="_blank">http://denon.wiki/view/JSON-RPC_API/v6</a></p> | ||
| <p>Take a look at Denon AVR protocol: <a href="https://github.com/estbeetoo/node-red-contrib-denon/blob/master/doc/AVR3312CI_AVR3312_PROTOCOL_V7.6.0.pdf">DENON_PROTOCOL_V7.6.0.pdf</a></p | ||
| </script> | ||
@@ -69,17 +92,6 @@ | ||
| <pre>{ | ||
| "data": { | ||
| "data": { | ||
| "item": { | ||
| "title": "Lounge FM Terrace ()", | ||
| "type": "song" | ||
| }, | ||
| "playlistid": 0, | ||
| "position": 0 | ||
| }, | ||
| "sender": "xbmc" | ||
| }, | ||
| "notification": "Playlist.OnAdd" | ||
| //TODO: fill it | ||
| }</pre> | ||
| </p> | ||
| <p>Read more about official Denon's JSON-RPC api here: http://denon.wiki/view/JSON-RPC_API/v6</p> | ||
| <p>Take a look at Denon AVR protocol: <a href="https://github.com/estbeetoo/node-red-contrib-denon/blob/master/doc/AVR3312CI_AVR3312_PROTOCOL_V7.6.0.pdf">DENON_PROTOCOL_V7.6.0.pdf</a></p> | ||
| </script> | ||
@@ -115,3 +127,3 @@ | ||
| align: 'right', | ||
| icon: "bridge-dash.png", | ||
| icon: "denon.png", | ||
| label: function () { | ||
@@ -133,3 +145,3 @@ return (this.groupaddr || this.name || "denon"); | ||
| outputs: 1, | ||
| icon: "bridge-dash.png", | ||
| icon: "denon.png", | ||
| label: function () { | ||
@@ -136,0 +148,0 @@ return (this.groupaddr || this.name || "denon"); |
+36
-31
@@ -26,4 +26,4 @@ /** | ||
| /** | ||
| * Initialize an denonjs socket, calling the handler function | ||
| * when successfully connected, passing it the denonjs connection | ||
| * Initialize an denon_telnet socket, calling the handler function | ||
| * when successfully connected, passing it the denon_telnet connection | ||
| */ | ||
@@ -37,8 +37,12 @@ this.initializeDenonConnection = function (handler) { | ||
| if (handler && (typeof handler === 'function')) { | ||
| if (node.denon.connection) | ||
| if (node.denon.connection && node.denon.connected) | ||
| handler(node.denon); | ||
| else | ||
| else { | ||
| if (node.denon.connection && !node.denon.connected) | ||
| node.denon.connect(); | ||
| node.denon.on('connected', function () { | ||
| handler(node.denon); | ||
| }); | ||
| } | ||
| } | ||
@@ -53,2 +57,3 @@ return node.denon; | ||
| }); | ||
| node.denon.connect(); | ||
| if (handler && (typeof handler === 'function')) { | ||
@@ -59,3 +64,2 @@ node.denon.on('connected', function () { | ||
| } | ||
| node.denon.connect(); | ||
| DEBUG && RED.comms.publish("debug", { | ||
@@ -69,3 +73,3 @@ name: node.name, | ||
| this.on("close", function () { | ||
| node.log('disconnecting from denonjs server at ' + config.host + ':' + config.port); | ||
| node.log('disconnecting from denon device at ' + config.host + ':' + config.port); | ||
| node.denon && node.denon.disconnect && node.denon.disconnect(); | ||
@@ -101,2 +105,3 @@ node.denon = null; | ||
| var payload = msg.payload; | ||
| console.log('------------- ' + JSON.stringify(msg) + ''); | ||
| if (typeof(msg.payload) === "object") { | ||
@@ -120,5 +125,5 @@ payload = msg.payload; | ||
| if (msg.topic) { | ||
| if(payload.value===null || payload.value===undefined) | ||
| if (payload.value === null || payload.value === undefined) | ||
| payload.value = payload.cmd; | ||
| payload.cmd = msg.topic.toString(); | ||
| payload = {cmd: msg.topic.toString(), value: payload.value}; | ||
| } | ||
@@ -184,5 +189,2 @@ | ||
| DEBUG && RED.comms.publish("debug", {name: node.name, msg: 'send data[' + JSON.stringify(data) + ']'}); | ||
| //node.log('send data[' + data + ']'); | ||
| // init a new one-off connection from the effectively singleton DenonController | ||
| // there seems to be no way to reuse the outgoing conn in adreek/node-denonjs | ||
| controllerNode.initializeDenonConnection(function (fsm) { | ||
@@ -192,8 +194,25 @@ try { | ||
| data.cmd = data.cmd || data.method; | ||
| data.args = data.args || data.params; | ||
| fsm.connection.run(data.cmd, data.args).then(function () { | ||
| callback && callback(err); | ||
| }, function (err) { | ||
| callback && callback(err); | ||
| }); | ||
| data.value = data.value || data.params; | ||
| switch (data.cmd.toLowerCase()) { | ||
| case 'setvolumedb': | ||
| fsm.connection.setVolumeDb(parseFloat(data.value), function (error, response) { | ||
| if (!callback) | ||
| return; | ||
| if (error) | ||
| callback && callback(error, response); | ||
| else | ||
| callback(response); | ||
| }); | ||
| break; | ||
| default: | ||
| fsm.connection.send(data.cmd, function (error, response) { | ||
| if (!callback) | ||
| return; | ||
| if (error) | ||
| callback && callback(error, response); | ||
| else | ||
| callback(response); | ||
| }); | ||
| } | ||
| } | ||
@@ -242,14 +261,2 @@ catch (err) { | ||
| function bindNotificationListeners(connection) { | ||
| function getListenerForNotification(notification) { | ||
| return function (data) { | ||
| node.receiveNotification(notification, data); | ||
| } | ||
| } | ||
| Object.keys(connection.schema.schema.notifications).forEach(function (method) { | ||
| connection.schema.schema.notifications[method](getListenerForNotification(method)); | ||
| }); | ||
| } | ||
| node.receiveNotification = function (notification, data) { | ||
@@ -270,4 +277,2 @@ DEBUG && RED.comms.publish("debug", { | ||
| controllerNode.initializeDenonConnection(function (fsm) { | ||
| bindNotificationListeners(fsm.connection); | ||
| if (fsm.connected) | ||
@@ -274,0 +279,0 @@ nodeStatusConnected(); |
@@ -11,3 +11,3 @@ ~function (undefined) { | ||
| PING_TIMEOUT: options.pingTimeout || options['ping-timeout'] || 5000, | ||
| PING_INTERVAL: options.pingInterval || options['ping-interval'] || 10000, | ||
| PING_INTERVAL: options.pingInterval || options['ping-interval'] || 20000, | ||
| RECONNECT_INTERVAL: options.reconnectInterval || options['reconnect-interval'] || 5000, | ||
@@ -144,3 +144,3 @@ initialize: function (options) { | ||
| this.emit('disconnected'); | ||
| this.connection && this.connection.close(); | ||
| this.connection && this.connection.getConnection().destroy(); | ||
| this.connection = null; | ||
@@ -147,0 +147,0 @@ this.transition('uninitialized'); |
+1
-1
| { | ||
| "name": "node-red-contrib-denon", | ||
| "version": "0.1.0", | ||
| "version": "0.1.1", | ||
| "description": "Node-RED nodes for communicating with a Denon AVR.", | ||
@@ -5,0 +5,0 @@ "repository": { |
707416
0.27%9
12.5%403
1.51%