Skip to content

Commit

Permalink
Minor cleanup of app.js
Browse files Browse the repository at this point in the history
  • Loading branch information
bpruessm committed Jan 16, 2018
1 parent 4d5aa2f commit 5dbad3d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
41 changes: 21 additions & 20 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const debug = require('debug')('roon-extension-arcam'),
debug_keepalive = require('debug')('roon-extension-arcam:keepalive'),
Promise = require('bluebird'),
Arcam = require('./arcam_client'),
RoonApi = require('node-roon-api'),
RoonApiSettings = require('node-roon-api-settings'),
Expand All @@ -12,7 +13,7 @@ var arcam = {};
var roon = new RoonApi({
extension_id: 'org.pruessmann.roon.arcam',
display_name: 'Arcam AVR390/550/850/AV860/SR250',
display_version: '0.0.1',
display_version: '0.0.2',
publisher: 'Doc Bobo',
email: '[email protected]',
website: 'https://github.com/docbobo/roon-extension-arcam',
Expand Down Expand Up @@ -99,10 +100,11 @@ function setup_arcam_connection(host, keepalive) {

if (!arcam.reconnect) {
arcam.reconnect = setTimeout(() => {
arcam.client.connect();
arcam.reconnect = null;

svc_status.set_status("Connected to receiver", false);
debug("Attempting to reconnect");
arcam.client.connect().then(() => {
arcam.reconnect = null;
svc_status.set_status("Connected to receiver", false);
});
}, 1000);
}
});
Expand Down Expand Up @@ -130,6 +132,7 @@ function setup_arcam_connection(host, keepalive) {

function create_volume_control(arcam) {
debug("create_volume_control: volume_control=%o", arcam.volume_control)

var result = arcam.client;
if (!arcam.volume_control) {
arcam.state = {
Expand All @@ -142,6 +145,7 @@ function create_volume_control(arcam) {

var device = {
state: arcam.state,

set_volume: function (req, mode, value) {
debug("set_volume: mode=%s value=%d", mode, value);

Expand All @@ -159,29 +163,26 @@ function create_volume_control(arcam) {
req.send_complete("Failed");
});
},

set_mute: function (req, inAction) {
debug("set_mute: action=%s", inAction);

const action = !this.state.is_muted ? "on" : "off";
arcam.client.setMute(action === "on" ? Arcam.Options.MuteOptions.On : Arcam.Options.MuteOptions.Off)
.then(() => {
debug("set_mute: Succeeded.");

req.send_complete("Success");
}).catch((error) => {
debug("set_mute: Failed.");
arcam.client.setMute(action === "on" ? Arcam.Options.MuteOptions.On : Arcam.Options.MuteOptions.Off).then(() => {
debug("set_mute: Succeeded.");
req.send_complete("Success");
}).catch((error) => {
debug("set_mute: Failed.");

console.log(error);
req.send_complete("Failed");
});
console.log(error);
req.send_complete("Failed");
});
}
};

result = arcam.client.getVolume().then((val) => {
arcam.state.volume_value = val;
return arcam.client.getMute();
}).then((val) => {
arcam.state.is_muted = (val === Arcam.Options.MuteOptions.On);
result = Promise.join(arcam.client.getVolume(), arcam.client.getMute(), function(volume, is_muted) {
arcam.state.volume_value = volume;
arcam.state.is_muted = (is_muted === Arcam.Options.MuteOptions.On);

debug("Registering volume control extension");
arcam.volume_control = svc_volume_control.new_device(device);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "roon-extension-arcam",
"version": "0.0.1",
"version": "0.0.2",
"description": "Volume Control extension to control Arcam AV receivers AVR390/550/850/AV860/SR250 via network.",
"main": "app.js",
"author": "Doc Bobo <[email protected]> (https://blog.pruessmann.org/)",
Expand Down

0 comments on commit 5dbad3d

Please sign in to comment.