homey-api 3.0.0-rc.21 → 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 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') {
@@ -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 || properties._id || null,
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 || null,
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);
@@ -19,6 +19,14 @@ class HomeyAPIV1 extends HomeyAPI {
19
19
  this.token = token;
20
20
  }
21
21
 
22
+ get platform() {
23
+ return 'local';
24
+ }
25
+
26
+ get platformVersion() {
27
+ return 1;
28
+ }
29
+
22
30
  updates = {
23
31
  async getUpdates() {
24
32
  throw new Error('Not Implemented');
@@ -25,6 +25,14 @@ class HomeyAPIV2 extends HomeyAPIV3 {
25
25
  ManagerInsights,
26
26
  };
27
27
 
28
+ get platform() {
29
+ return 'local';
30
+ }
31
+
32
+ get platformVersion() {
33
+ return 1;
34
+ }
35
+
28
36
  }
29
37
 
30
38
  module.exports = HomeyAPIV2;
@@ -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');
@@ -17,6 +17,14 @@ class HomeyAPIV3Local extends HomeyAPIV3 {
17
17
  ManagerDevkit,
18
18
  };
19
19
 
20
+ get platform() {
21
+ return 'local';
22
+ }
23
+
24
+ get platformVersion() {
25
+ return 2;
26
+ }
27
+
20
28
  getSpecification() {
21
29
  // eslint-disable-next-line global-require
22
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.21",
3
+ "version": "3.0.0-rc.22",
4
4
  "description": "Homey API",
5
5
  "main": "index.js",
6
6
  "files": [