homey-api 3.0.0-rc.20 → 3.0.0-rc.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +20 -0
- package/lib/API.js +6 -0
- package/lib/HomeyAPI/HomeyAPI.js +30 -4
- package/lib/HomeyAPI/HomeyAPIV1.js +8 -0
- package/lib/HomeyAPI/HomeyAPIV2.js +8 -0
- package/lib/HomeyAPI/HomeyAPIV3.js +8 -8
- package/lib/HomeyAPI/HomeyAPIV3Cloud.js +8 -0
- package/lib/HomeyAPI/HomeyAPIV3Local/ManagerDevkit.js +32 -0
- package/lib/HomeyAPI/HomeyAPIV3Local.js +14 -0
- package/package.json +2 -1
package/index.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
5
|
module.exports = {};
|
|
6
|
+
|
|
7
|
+
// Athom Cloud
|
|
6
8
|
module.exports.AthomAppsAPI = require('./lib/AthomAppsAPI');
|
|
7
9
|
module.exports.AthomBackupAPI = require('./lib/AthomBackupAPI');
|
|
8
10
|
module.exports.AthomCallbackAPI = require('./lib/AthomCallbackAPI');
|
|
@@ -19,5 +21,23 @@ module.exports.AthomSetupAPI = require('./lib/AthomSetupAPI');
|
|
|
19
21
|
module.exports.AthomStoreAPI = require('./lib/AthomStoreAPI');
|
|
20
22
|
module.exports.AthomWeatherAPI = require('./lib/AthomWeatherAPI');
|
|
21
23
|
module.exports.AthomWebhooksAPI = require('./lib/AthomWebhooksAPI');
|
|
24
|
+
|
|
25
|
+
// Homey Cloud
|
|
22
26
|
module.exports.HomeyCloudAPI = require('./lib/HomeyCloudAPI');
|
|
27
|
+
|
|
28
|
+
// Homey API
|
|
23
29
|
module.exports.HomeyAPI = require('./lib/HomeyAPI/HomeyAPI');
|
|
30
|
+
module.exports.HomeyAPIV1 = require('./lib/HomeyAPI/HomeyAPIV1');
|
|
31
|
+
module.exports.HomeyAPIV2 = require('./lib/HomeyAPI/HomeyAPIV2');
|
|
32
|
+
module.exports.HomeyAPIV3 = require('./lib/HomeyAPI/HomeyAPIV3');
|
|
33
|
+
module.exports.HomeyAPIV3Local = require('./lib/HomeyAPI/HomeyAPIV3Local');
|
|
34
|
+
module.exports.HomeyAPIV3Cloud = require('./lib/HomeyAPI/HomeyAPIV3Cloud');
|
|
35
|
+
|
|
36
|
+
// APIError
|
|
37
|
+
module.exports.APIError = require('./lib/APIError');
|
|
38
|
+
module.exports.APIErrorHomeyOffline = require('./lib/APIErrorHomeyOffline');
|
|
39
|
+
module.exports.APIErrorNotFound = require('./lib/APIErrorNotFound');
|
|
40
|
+
module.exports.APIErrorTimeout = require('./lib/APIErrorTimeout');
|
|
41
|
+
|
|
42
|
+
// Util
|
|
43
|
+
module.exports.Util = require('./lib/Util');
|
package/lib/API.js
CHANGED
|
@@ -73,6 +73,7 @@ class API {
|
|
|
73
73
|
$body = {},
|
|
74
74
|
$query = {},
|
|
75
75
|
$headers = {},
|
|
76
|
+
$token = null,
|
|
76
77
|
...args
|
|
77
78
|
} = {}) => {
|
|
78
79
|
let pathWithParameters = operation.path;
|
|
@@ -89,6 +90,11 @@ class API {
|
|
|
89
90
|
value = this.__secret;
|
|
90
91
|
}
|
|
91
92
|
|
|
93
|
+
// Set Authorization header if $token is provided
|
|
94
|
+
if (typeof $token === 'string') {
|
|
95
|
+
headers.Authorization = `Bearer ${$token}`;
|
|
96
|
+
}
|
|
97
|
+
|
|
92
98
|
// Validate the parameter
|
|
93
99
|
if ($validate) {
|
|
94
100
|
if (parameter.required === true && typeof value === 'undefined') {
|
package/lib/HomeyAPI/HomeyAPI.js
CHANGED
|
@@ -8,6 +8,14 @@ const Util = require('../Util');
|
|
|
8
8
|
*/
|
|
9
9
|
class HomeyAPI {
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Possible Platforms
|
|
13
|
+
*/
|
|
14
|
+
static PLATFORMS = {
|
|
15
|
+
LOCAL: 'local',
|
|
16
|
+
CLOUD: 'cloud',
|
|
17
|
+
};
|
|
18
|
+
|
|
11
19
|
/**
|
|
12
20
|
* Possible Discovery Strategies
|
|
13
21
|
* @static
|
|
@@ -27,8 +35,8 @@ class HomeyAPI {
|
|
|
27
35
|
};
|
|
28
36
|
|
|
29
37
|
constructor({
|
|
30
|
-
api,
|
|
31
|
-
properties,
|
|
38
|
+
api = null,
|
|
39
|
+
properties = {},
|
|
32
40
|
debug = () => { },
|
|
33
41
|
}) {
|
|
34
42
|
// Set Debug Enabled
|
|
@@ -47,14 +55,28 @@ class HomeyAPI {
|
|
|
47
55
|
|
|
48
56
|
// Set ID
|
|
49
57
|
Object.defineProperty(this, 'id', {
|
|
50
|
-
value: properties.id
|
|
58
|
+
value: properties.id ?? properties._id ?? null,
|
|
51
59
|
enumerable: true,
|
|
52
60
|
writable: true,
|
|
53
61
|
});
|
|
54
62
|
|
|
55
63
|
// Set Version
|
|
56
64
|
Object.defineProperty(this, 'version', {
|
|
57
|
-
value: properties.softwareVersion
|
|
65
|
+
value: properties.softwareVersion ?? null,
|
|
66
|
+
enumerable: true,
|
|
67
|
+
writable: true,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Set Name
|
|
71
|
+
Object.defineProperty(this, 'name', {
|
|
72
|
+
value: properties.name ?? null,
|
|
73
|
+
enumerable: true,
|
|
74
|
+
writable: true,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Set Language
|
|
78
|
+
Object.defineProperty(this, 'Language', {
|
|
79
|
+
value: properties.Language ?? null,
|
|
58
80
|
enumerable: true,
|
|
59
81
|
writable: true,
|
|
60
82
|
});
|
|
@@ -67,6 +89,10 @@ class HomeyAPI {
|
|
|
67
89
|
});
|
|
68
90
|
}
|
|
69
91
|
|
|
92
|
+
get _id() {
|
|
93
|
+
throw new Error('HomeyAPI._id is not supported, please use HomeyAPI.id');
|
|
94
|
+
}
|
|
95
|
+
|
|
70
96
|
__debug(...props) {
|
|
71
97
|
if (!this.__debugFunction) return;
|
|
72
98
|
this.__debugFunction(...props);
|
|
@@ -378,32 +378,32 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
378
378
|
headers,
|
|
379
379
|
path,
|
|
380
380
|
body,
|
|
381
|
+
json = true,
|
|
381
382
|
retryAfterRefresh = false,
|
|
382
383
|
}) {
|
|
383
384
|
const baseUrl = await this.baseUrl;
|
|
384
385
|
|
|
385
|
-
method = method.toUpperCase();
|
|
386
|
+
method = String(method).toUpperCase();
|
|
386
387
|
|
|
387
388
|
headers = {
|
|
388
389
|
...headers,
|
|
389
390
|
'X-Homey-ID': this.id,
|
|
390
391
|
};
|
|
391
392
|
|
|
392
|
-
if (body) {
|
|
393
|
-
headers['Content-Type'] = 'application/json';
|
|
394
|
-
}
|
|
395
|
-
|
|
396
393
|
if (this.__token) {
|
|
397
394
|
headers['Authorization'] = `Bearer ${this.__token}`;
|
|
398
395
|
}
|
|
399
396
|
|
|
397
|
+
if (body && json === true && ['PUT', 'POST'].includes(method)) {
|
|
398
|
+
headers['Content-Type'] = 'application/json';
|
|
399
|
+
body = JSON.stringify(body);
|
|
400
|
+
}
|
|
401
|
+
|
|
400
402
|
this.__debug(method, `${baseUrl}${path}`);
|
|
401
403
|
const res = await Util.timeout(Util.fetch(`${baseUrl}${path}`, {
|
|
402
404
|
method,
|
|
403
405
|
headers,
|
|
404
|
-
body
|
|
405
|
-
? JSON.stringify(body)
|
|
406
|
-
: undefined,
|
|
406
|
+
body,
|
|
407
407
|
}), $timeout);
|
|
408
408
|
|
|
409
409
|
const resStatusCode = res.status;
|
|
@@ -33,6 +33,14 @@ class HomeyAPIV3Cloud extends HomeyAPIV3 {
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
get platform() {
|
|
37
|
+
return 'cloud';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get platformVersion() {
|
|
41
|
+
return 1;
|
|
42
|
+
}
|
|
43
|
+
|
|
36
44
|
getSpecification() {
|
|
37
45
|
// eslint-disable-next-line global-require
|
|
38
46
|
return require('../../assets/specifications/HomeyAPIV3Cloud.json');
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const FormData = require('form-data');
|
|
4
|
+
|
|
5
|
+
const Manager = require('./Manager');
|
|
6
|
+
|
|
7
|
+
class ManagerDevkit extends Manager {
|
|
8
|
+
|
|
9
|
+
async runApp({
|
|
10
|
+
app, // Readable
|
|
11
|
+
env = {},
|
|
12
|
+
debug = false,
|
|
13
|
+
clean = false,
|
|
14
|
+
}) {
|
|
15
|
+
const form = new FormData();
|
|
16
|
+
form.append('app', app);
|
|
17
|
+
form.append('env', JSON.stringify(env));
|
|
18
|
+
form.append('debug', debug ? 'true' : 'false');
|
|
19
|
+
form.append('purgseSettings', clean ? 'true' : 'false');
|
|
20
|
+
|
|
21
|
+
return this.homey.call({
|
|
22
|
+
$timeout: 1000 * 60 * 5, // 5 minutes
|
|
23
|
+
method: 'POST',
|
|
24
|
+
path: '/api/manager/devkit/',
|
|
25
|
+
body: form,
|
|
26
|
+
json: false,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = ManagerDevkit;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const HomeyAPIV3 = require('./HomeyAPIV3');
|
|
4
|
+
const ManagerDevkit = require('./HomeyAPIV3Local/ManagerDevkit');
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* This class is returned by {@link AthomCloudAPI.Homey#authenticate} for a Homey with `platform: 'local'` and `platformVersion: 1`.
|
|
@@ -11,6 +12,19 @@ const HomeyAPIV3 = require('./HomeyAPIV3');
|
|
|
11
12
|
*/
|
|
12
13
|
class HomeyAPIV3Local extends HomeyAPIV3 {
|
|
13
14
|
|
|
15
|
+
static MANAGERS = {
|
|
16
|
+
...HomeyAPIV3.MANAGERS,
|
|
17
|
+
ManagerDevkit,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
get platform() {
|
|
21
|
+
return 'local';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get platformVersion() {
|
|
25
|
+
return 2;
|
|
26
|
+
}
|
|
27
|
+
|
|
14
28
|
getSpecification() {
|
|
15
29
|
// eslint-disable-next-line global-require
|
|
16
30
|
return require('../../assets/specifications/HomeyAPIV3Local.json');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homey-api",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.22",
|
|
4
4
|
"description": "Homey API",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"core-js": "^3.19.1",
|
|
49
|
+
"form-data": "^4.0.0",
|
|
49
50
|
"node-fetch": "^2.6.7",
|
|
50
51
|
"regenerator-runtime": "^0.13.9",
|
|
51
52
|
"socket.io-client": "^2.5.0"
|