Skip to content

Commit

Permalink
* (Apollon77) Adjust to new automations (Routines) route
Browse files Browse the repository at this point in the history
* (Apollon77) Add getAllDeviceVolumes method
* (Apollon77) Return relationships in getSmarthomeDevices call
  • Loading branch information
Apollon77 committed Jan 28, 2021
1 parent 1a7fa83 commit 7883057
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ Thank you for that work.

## Changelog:

### __WORK IN PROGRESS__
* (Apollon77) Adjust to new automations (Routines) route
* (Apollon77) Add getAllDeviceVolumes method
* (Apollon77) Return relationships in getSmarthomeDevices call

### 3.5.2 (2021-01-17)
* (Apollon77) Fix potential crash issue (Sentry IOBROKER-ALEXA2-39)

Expand Down
62 changes: 33 additions & 29 deletions alexa-remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ class AlexaRemote extends EventEmitter {
this.emit('ws-unknown-message', incomingMsg);
});
this.alexaWsMqtt.on('command', (command, payload) => {

this.emit('command', { 'command': command, 'payload': payload });

switch(command) {
case 'PUSH_DOPPLER_CONNECTION_CHANGE':
/*
Expand Down Expand Up @@ -614,7 +614,7 @@ class AlexaRemote extends EventEmitter {
this.getPushedActivities();
}, 200);
return;

case 'PUSH_TODO_CHANGE': // does not exist?
case 'PUSH_LIST_CHANGE': // does not exist?
case 'PUSH_LIST_ITEM_CHANGE':
Expand All @@ -635,7 +635,7 @@ class AlexaRemote extends EventEmitter {
listItemId: payload.listItemId
});
return;

case 'PUSH_MICROPHONE_STATE':
case 'PUSH_DELETE_DOPPLER_ACTIVITIES':
case 'PUSH_DEVICE_SETUP_STATE_CHANGE':
Expand Down Expand Up @@ -755,7 +755,7 @@ class AlexaRemote extends EventEmitter {
}

httpsGetCall(path, callback, flags = {}) {

let options = {
host: this.baseUrl,
path: '',
Expand Down Expand Up @@ -871,7 +871,7 @@ class AlexaRemote extends EventEmitter {
if (flags && flags.data) {
req.write(flags.data);
}

req.end();
}

Expand Down Expand Up @@ -928,7 +928,7 @@ class AlexaRemote extends EventEmitter {
getList(listId, callback) {
this.httpsGet ('/api/namedLists/' + listId + '?_=%t', callback);
}

/**
* Get items from a list.
*
Expand All @@ -941,30 +941,30 @@ class AlexaRemote extends EventEmitter {
*
*/
getListItems(listId, options, callback) {

// get function params
if (typeof options === 'function') {
callback = options;
options = {};
}

// get params by options
let params = '';
for (let option in options) {
params += '&' + option + '=' + options[option];
params += '&' + option + '=' + options[option];
}

// send request
this.httpsGet ('/api/namedLists/' + listId + '/items?_=%t' + params, (err, res) => callback && callback(err, res && res.list));
}

addListItem(listId, options, callback) {

// get function params
if (typeof options === 'string') {
options = { 'value': options };
}

// request options
let request = {
'method': 'POST',
Expand All @@ -975,29 +975,29 @@ class AlexaRemote extends EventEmitter {
...options
})
};

// send request
this.httpsGet ('/api/namedLists/' + listId + '/item', callback, request);
}

updateListItem(listId, listItem, options, callback) {

// providing a version is mandatory
if (typeof options !== 'object' || !options.version || !options.value) {
let errors = [];

if (!options.version && callback) {
errors.push('Providing the current version via options is mandatory!');
}

if (!options.value && callback) {
errors.push('Providing a new value (description) via options is mandatory!');
}

callback && callback(errors);
return false;
}

// request options
let request = {
'method': 'PUT',
Expand All @@ -1008,20 +1008,20 @@ class AlexaRemote extends EventEmitter {
...options
})
};

// send request
this.httpsGet ('/api/namedLists/' + listId + '/item/' + listItem, callback, request);
}

deleteListItem(listId, listItem, callback) {

// data
let data = JSON.stringify({
'listId': listId,
'id': listItem,
'value': '' // must be provided, but value doesn't matter
});

// request options
let request = {
'method': 'DELETE',
Expand All @@ -1031,11 +1031,11 @@ class AlexaRemote extends EventEmitter {
'Content-Length': data.length
}
};

// send request
this.httpsGet ('/api/namedLists/' + listId + '/item/' + listItem, callback, request);
}

getWakeWords(callback) {
this.httpsGet (`/api/wake-word?_=%t`, callback);
}
Expand Down Expand Up @@ -1810,7 +1810,7 @@ class AlexaRemote extends EventEmitter {
limit = 0;
}
limit = limit || 2000;
this.httpsGet (`/api/behaviors/automations?limit=${limit}`, callback, {
this.httpsGet (`/api/behaviors/v2/automations?limit=${limit}`, callback, {
timeout: 30000
});
}
Expand Down Expand Up @@ -1930,8 +1930,12 @@ class AlexaRemote extends EventEmitter {
this.httpsGet ('/api/device-preferences?cached=true&_=%t', callback);
}

getAllDeviceVolumes(callback) {
this.httpsGet ('/api/devices/deviceType/dsn/audio/v1/allDeviceVolumes', callback);
}

getSmarthomeDevices(callback) {
this.httpsGet ('/api/phoenix?_=%t', function (err, res) {
this.httpsGet ('/api/phoenix?includeRelationships=true&_=%t', function (err, res) {
if (err || !res || !res.networkDetail) return callback(err, res);
try {
res = JSON.parse(res.networkDetail);
Expand Down

0 comments on commit 7883057

Please sign in to comment.