homey-api 3.4.32 → 3.4.34
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/assets/specifications/AthomAppsAPI.json +30 -0
- package/assets/types/homey-api.private.d.ts +56 -0
- package/index.browser.js +0 -3
- package/index.js +0 -2
- package/lib/API.js +0 -1
- package/lib/APIErrorNotFound.js +0 -2
- package/lib/APIErrorTimeout.js +0 -2
- package/lib/AthomCloudAPI/StorageAdapterBrowser.js +0 -2
- package/lib/AthomCloudAPI/Token.js +0 -2
- package/lib/AthomCloudAPI.js +0 -2
- package/lib/HomeyAPI/HomeyAPI.js +15 -0
- package/lib/HomeyAPI/HomeyAPIError.js +0 -2
- package/lib/HomeyAPI/HomeyAPIErrorNotFound.js +0 -2
- package/lib/HomeyAPI/HomeyAPIV1.js +2 -2
- package/lib/HomeyAPI/HomeyAPIV2/Manager.js +0 -2
- package/lib/HomeyAPI/HomeyAPIV3/Manager.js +0 -4
- package/lib/HomeyAPI/HomeyAPIV3/ManagerFlow/AdvancedFlow.js +2 -2
- package/lib/HomeyAPI/HomeyAPIV3/ManagerFlow/Flow.js +3 -1
- package/lib/HomeyAPI/HomeyAPIV3.js +99 -83
- package/lib/HomeyAPI/HomeyAPIV3Cloud.js +9 -1
- package/lib/HomeyAPI/HomeyAPIV3Local.js +0 -1
- package/lib/Util.js +0 -2
- package/package.json +3 -1
|
@@ -176,6 +176,36 @@
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
},
|
|
179
|
+
"searchMatterDriver": {
|
|
180
|
+
"path": "/app/search-matter-driver",
|
|
181
|
+
"method": "post",
|
|
182
|
+
"parameters": {
|
|
183
|
+
"language": {
|
|
184
|
+
"in": "query",
|
|
185
|
+
"type": "string"
|
|
186
|
+
},
|
|
187
|
+
"homeyVersion": {
|
|
188
|
+
"type": "string",
|
|
189
|
+
"in": "body"
|
|
190
|
+
},
|
|
191
|
+
"homeyPlatform": {
|
|
192
|
+
"type": "string",
|
|
193
|
+
"in": "body"
|
|
194
|
+
},
|
|
195
|
+
"homeyMinimumSdkVersion": {
|
|
196
|
+
"type": "number",
|
|
197
|
+
"in": "body"
|
|
198
|
+
},
|
|
199
|
+
"productId": {
|
|
200
|
+
"type": "number",
|
|
201
|
+
"in": "body"
|
|
202
|
+
},
|
|
203
|
+
"vendorId": {
|
|
204
|
+
"type": "number",
|
|
205
|
+
"in": "body"
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
},
|
|
179
209
|
"browseApps": {
|
|
180
210
|
"path": "/app/browse",
|
|
181
211
|
"method": "get",
|
|
@@ -1623,6 +1623,20 @@ export class AthomAppsAPI {
|
|
|
1623
1623
|
manufacturerId?: number;
|
|
1624
1624
|
}): Promise<any>;
|
|
1625
1625
|
|
|
1626
|
+
searchMatterDriver(opts: {
|
|
1627
|
+
language?: string;
|
|
1628
|
+
|
|
1629
|
+
homeyVersion?: string;
|
|
1630
|
+
|
|
1631
|
+
homeyPlatform?: string;
|
|
1632
|
+
|
|
1633
|
+
homeyMinimumSdkVersion?: number;
|
|
1634
|
+
|
|
1635
|
+
productId?: number;
|
|
1636
|
+
|
|
1637
|
+
vendorId?: number;
|
|
1638
|
+
}): Promise<any>;
|
|
1639
|
+
|
|
1626
1640
|
browseApps(opts: {
|
|
1627
1641
|
query?: string;
|
|
1628
1642
|
|
|
@@ -1913,6 +1927,20 @@ export class AthomAppsAPI {
|
|
|
1913
1927
|
manufacturerId?: number;
|
|
1914
1928
|
}): Promise<any>;
|
|
1915
1929
|
|
|
1930
|
+
searchMatterDriver(opts: {
|
|
1931
|
+
language?: string;
|
|
1932
|
+
|
|
1933
|
+
homeyVersion?: string;
|
|
1934
|
+
|
|
1935
|
+
homeyPlatform?: string;
|
|
1936
|
+
|
|
1937
|
+
homeyMinimumSdkVersion?: number;
|
|
1938
|
+
|
|
1939
|
+
productId?: number;
|
|
1940
|
+
|
|
1941
|
+
vendorId?: number;
|
|
1942
|
+
}): Promise<any>;
|
|
1943
|
+
|
|
1916
1944
|
browseApps(opts: {
|
|
1917
1945
|
query?: string;
|
|
1918
1946
|
|
|
@@ -4819,6 +4847,20 @@ export class AthomAppsAPI {
|
|
|
4819
4847
|
manufacturerId?: number;
|
|
4820
4848
|
}): Promise<any>;
|
|
4821
4849
|
|
|
4850
|
+
searchMatterDriver(opts: {
|
|
4851
|
+
language?: string;
|
|
4852
|
+
|
|
4853
|
+
homeyVersion?: string;
|
|
4854
|
+
|
|
4855
|
+
homeyPlatform?: string;
|
|
4856
|
+
|
|
4857
|
+
homeyMinimumSdkVersion?: number;
|
|
4858
|
+
|
|
4859
|
+
productId?: number;
|
|
4860
|
+
|
|
4861
|
+
vendorId?: number;
|
|
4862
|
+
}): Promise<any>;
|
|
4863
|
+
|
|
4822
4864
|
browseApps(opts: {
|
|
4823
4865
|
query?: string;
|
|
4824
4866
|
|
|
@@ -5109,6 +5151,20 @@ export class AthomAppsAPI {
|
|
|
5109
5151
|
manufacturerId?: number;
|
|
5110
5152
|
}): Promise<any>;
|
|
5111
5153
|
|
|
5154
|
+
searchMatterDriver(opts: {
|
|
5155
|
+
language?: string;
|
|
5156
|
+
|
|
5157
|
+
homeyVersion?: string;
|
|
5158
|
+
|
|
5159
|
+
homeyPlatform?: string;
|
|
5160
|
+
|
|
5161
|
+
homeyMinimumSdkVersion?: number;
|
|
5162
|
+
|
|
5163
|
+
productId?: number;
|
|
5164
|
+
|
|
5165
|
+
vendorId?: number;
|
|
5166
|
+
}): Promise<any>;
|
|
5167
|
+
|
|
5112
5168
|
browseApps(opts: {
|
|
5113
5169
|
query?: string;
|
|
5114
5170
|
|
package/index.browser.js
CHANGED
package/index.js
CHANGED
package/lib/API.js
CHANGED
package/lib/APIErrorNotFound.js
CHANGED
package/lib/APIErrorTimeout.js
CHANGED
|
@@ -17,7 +17,6 @@ class StorageAdapterBrowser extends StorageAdapter {
|
|
|
17
17
|
*/
|
|
18
18
|
async get() {
|
|
19
19
|
try {
|
|
20
|
-
// eslint-disable-next-line no-undef
|
|
21
20
|
return JSON.parse(window.localStorage.getItem(this.constructor.LOCAL_STORAGE_KEY) || '{}');
|
|
22
21
|
} catch (err) {
|
|
23
22
|
return {};
|
|
@@ -29,7 +28,6 @@ class StorageAdapterBrowser extends StorageAdapter {
|
|
|
29
28
|
* @returns {Promise<void>}
|
|
30
29
|
*/
|
|
31
30
|
async set(value) {
|
|
32
|
-
// eslint-disable-next-line no-undef
|
|
33
31
|
window.localStorage.setItem(this.constructor.LOCAL_STORAGE_KEY, JSON.stringify(value));
|
|
34
32
|
}
|
|
35
33
|
|
package/lib/AthomCloudAPI.js
CHANGED
|
@@ -476,11 +476,9 @@ for(const {@link HomeyAPIV2.ManagerDevices.Device device} of Object.values(devic
|
|
|
476
476
|
|
|
477
477
|
// Remove ?code=... from URL
|
|
478
478
|
if (Util.isBrowser() && removeCodeFromHistory) {
|
|
479
|
-
// eslint-disable-next-line no-undef
|
|
480
479
|
const url = new URL(window.location.href);
|
|
481
480
|
url.searchParams.delete('code');
|
|
482
481
|
|
|
483
|
-
// eslint-disable-next-line no-undef
|
|
484
482
|
window.history.pushState(undefined, undefined, url.toString());
|
|
485
483
|
}
|
|
486
484
|
|
package/lib/HomeyAPI/HomeyAPI.js
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
const Util = require('../Util');
|
|
4
4
|
const EventEmitter = require('../EventEmitter');
|
|
5
5
|
|
|
6
|
+
const tierCache = {};
|
|
7
|
+
const versionCache = {};
|
|
8
|
+
|
|
6
9
|
/**
|
|
7
10
|
* An authenticated Homey API. Do not construct this class manually.
|
|
8
11
|
* @class
|
|
@@ -49,6 +52,18 @@ class HomeyAPI extends EventEmitter {
|
|
|
49
52
|
}) {
|
|
50
53
|
super();
|
|
51
54
|
|
|
55
|
+
Object.defineProperty(this, '__tierCache', {
|
|
56
|
+
value: tierCache,
|
|
57
|
+
enumerable: false,
|
|
58
|
+
writable: false,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
Object.defineProperty(this, '__versionCache', {
|
|
62
|
+
value: versionCache,
|
|
63
|
+
enumerable: false,
|
|
64
|
+
writable: false,
|
|
65
|
+
});
|
|
66
|
+
|
|
52
67
|
// Set Debug Enabled
|
|
53
68
|
Object.defineProperty(this, '__debugFunction', {
|
|
54
69
|
value: debug,
|
|
@@ -11,8 +11,8 @@ const HomeyAPI = require('./HomeyAPI');
|
|
|
11
11
|
*/
|
|
12
12
|
class HomeyAPIV1 extends HomeyAPI {
|
|
13
13
|
|
|
14
|
-
constructor({ properties,
|
|
15
|
-
super({ properties,
|
|
14
|
+
constructor({ properties, api, debug }) {
|
|
15
|
+
super({ properties, api, debug });
|
|
16
16
|
|
|
17
17
|
// TODO: Bearer token
|
|
18
18
|
const { token } = this.__properties;
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
/* eslint-disable no-multi-assign */
|
|
2
|
-
|
|
3
1
|
'use strict';
|
|
4
2
|
|
|
5
3
|
const EventEmitter = require('../../EventEmitter');
|
|
6
4
|
const Util = require('../../Util');
|
|
7
5
|
const HomeyAPIError = require('../HomeyAPIError');
|
|
8
|
-
|
|
9
|
-
// eslint-disable-next-line no-unused-vars
|
|
10
6
|
const Item = require('./Item');
|
|
11
7
|
|
|
12
8
|
/**
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars */
|
|
2
|
-
|
|
3
1
|
'use strict';
|
|
4
2
|
|
|
5
3
|
const Item = require('../Item');
|
|
@@ -56,6 +54,7 @@ class AdvancedFlow extends Item {
|
|
|
56
54
|
if (typeof card.args === 'object') {
|
|
57
55
|
for (const arg of Object.values(card.args)) {
|
|
58
56
|
if (typeof arg !== 'string') continue;
|
|
57
|
+
// eslint-disable-next-line no-unused-vars
|
|
59
58
|
for (const [tokenMatch, tokenId] of arg.matchAll(/\[\[(.*?)\]\]/g)) {
|
|
60
59
|
await checkToken(tokenId);
|
|
61
60
|
}
|
|
@@ -87,6 +86,7 @@ class AdvancedFlow extends Item {
|
|
|
87
86
|
case 'condition': {
|
|
88
87
|
try {
|
|
89
88
|
await managerFlow.getFlowCardConditions(); // Fill the cache
|
|
89
|
+
// eslint-disable-next-line no-unused-vars
|
|
90
90
|
const conditionCard = await this.manager.getFlowCardCondition({ id: card.id });
|
|
91
91
|
|
|
92
92
|
// Add Error Token
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars */
|
|
2
1
|
|
|
3
2
|
'use strict';
|
|
4
3
|
|
|
@@ -56,6 +55,7 @@ class Flow extends Item {
|
|
|
56
55
|
if (typeof card.args === 'object') {
|
|
57
56
|
for (const arg of Object.values(card.args)) {
|
|
58
57
|
if (typeof arg !== 'string') continue;
|
|
58
|
+
// eslint-disable-next-line no-unused-vars
|
|
59
59
|
for (const [tokenMatch, tokenId] of arg.matchAll(/\[\[(.*?)\]\]/g)) {
|
|
60
60
|
await checkToken(tokenId);
|
|
61
61
|
}
|
|
@@ -87,6 +87,7 @@ class Flow extends Item {
|
|
|
87
87
|
for (const condition of Object.values(this.conditions)) {
|
|
88
88
|
try {
|
|
89
89
|
await managerFlow.getFlowCardConditions(); // Fill the cache
|
|
90
|
+
// eslint-disable-next-line no-unused-vars
|
|
90
91
|
const conditionCard = await this.manager.getFlowCardCondition({ id: condition.id });
|
|
91
92
|
await checkTokens(condition);
|
|
92
93
|
} catch (err) {
|
|
@@ -101,6 +102,7 @@ class Flow extends Item {
|
|
|
101
102
|
for (const action of Object.values(this.actions)) {
|
|
102
103
|
try {
|
|
103
104
|
await managerFlow.getFlowCardActions(); // Fill the cache
|
|
105
|
+
// eslint-disable-next-line no-unused-vars
|
|
104
106
|
const actionCard = await this.manager.getFlowCardAction({ id: action.id });
|
|
105
107
|
await checkTokens(action);
|
|
106
108
|
} catch (err) {
|
|
@@ -12,13 +12,8 @@ const ManagerFlow = require('./HomeyAPIV3/ManagerFlow');
|
|
|
12
12
|
const ManagerFlowToken = require('./HomeyAPIV3/ManagerFlowToken');
|
|
13
13
|
const ManagerInsights = require('./HomeyAPIV3/ManagerInsights');
|
|
14
14
|
const ManagerUsers = require('./HomeyAPIV3/ManagerUsers');
|
|
15
|
-
|
|
16
|
-
// eslint-disable-next-line no-unused-vars
|
|
17
15
|
const Manager = require('./HomeyAPIV3/Manager');
|
|
18
16
|
|
|
19
|
-
const tierCache = {};
|
|
20
|
-
const versionCache = {};
|
|
21
|
-
|
|
22
17
|
/**
|
|
23
18
|
* An authenticated Homey API. Do not construct this class manually.
|
|
24
19
|
* @class
|
|
@@ -53,9 +48,10 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
53
48
|
token = null,
|
|
54
49
|
session = null,
|
|
55
50
|
reconnect = true,
|
|
56
|
-
|
|
51
|
+
api,
|
|
52
|
+
debug,
|
|
57
53
|
}) {
|
|
58
|
-
super({ properties,
|
|
54
|
+
super({ properties, api, debug });
|
|
59
55
|
|
|
60
56
|
this.__refreshMap = {};
|
|
61
57
|
|
|
@@ -131,21 +127,13 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
131
127
|
this.__baseUrlPromise = this.discoverBaseUrl().then(({ baseUrl }) => {
|
|
132
128
|
return baseUrl;
|
|
133
129
|
});
|
|
134
|
-
this.__baseUrlPromise.catch(() => {});
|
|
130
|
+
this.__baseUrlPromise.catch(() => { });
|
|
135
131
|
}
|
|
136
132
|
|
|
137
133
|
return this.__baseUrlPromise;
|
|
138
134
|
})();
|
|
139
135
|
}
|
|
140
136
|
|
|
141
|
-
get tier() {
|
|
142
|
-
return tierCache[this.id];
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
get version() {
|
|
146
|
-
return versionCache[this.id];
|
|
147
|
-
}
|
|
148
|
-
|
|
149
137
|
get strategyId() {
|
|
150
138
|
return this.__strategyId;
|
|
151
139
|
}
|
|
@@ -156,7 +144,6 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
156
144
|
*/
|
|
157
145
|
|
|
158
146
|
getSpecification() {
|
|
159
|
-
// eslint-disable-next-line global-require
|
|
160
147
|
return require('../../assets/specifications/HomeyAPIV2.json');
|
|
161
148
|
}
|
|
162
149
|
|
|
@@ -174,8 +161,8 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
174
161
|
const ManagerClass = this.constructor.MANAGERS[managerName]
|
|
175
162
|
? this.constructor.MANAGERS[managerName]
|
|
176
163
|
: (() => {
|
|
177
|
-
|
|
178
|
-
|
|
164
|
+
return class extends Manager { };
|
|
165
|
+
})();
|
|
179
166
|
|
|
180
167
|
ManagerClass.ID = manager.id;
|
|
181
168
|
|
|
@@ -252,60 +239,68 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
252
239
|
// Create the returned Promise
|
|
253
240
|
let resolve;
|
|
254
241
|
let reject;
|
|
242
|
+
|
|
255
243
|
const promise = new Promise((resolve_, reject_) => {
|
|
256
244
|
resolve = resolve_;
|
|
257
245
|
reject = reject_;
|
|
258
246
|
});
|
|
247
|
+
|
|
259
248
|
promise
|
|
260
249
|
.then(({ baseUrl, strategyId }) => {
|
|
261
250
|
this.__baseUrl = baseUrl;
|
|
262
251
|
this.__strategyId = strategyId;
|
|
263
252
|
})
|
|
264
|
-
.catch(() => {});
|
|
253
|
+
.catch(() => { });
|
|
265
254
|
|
|
266
255
|
// Ping method
|
|
267
256
|
const ping = async (strategyId, timeout) => {
|
|
268
|
-
let pingTimeout;
|
|
269
257
|
const baseUrl = urls[strategyId];
|
|
270
|
-
|
|
271
|
-
|
|
258
|
+
|
|
259
|
+
const response = await Util.fetch(
|
|
260
|
+
`${baseUrl}/api/manager/system/ping?id=${this.id}`,
|
|
261
|
+
{
|
|
272
262
|
headers: {
|
|
273
263
|
'X-Homey-ID': this.id,
|
|
274
264
|
},
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
if (text === 'false') throw new Error('Invalid Homey ID');
|
|
265
|
+
},
|
|
266
|
+
timeout
|
|
267
|
+
);
|
|
279
268
|
|
|
280
|
-
|
|
269
|
+
const text = await response.text();
|
|
281
270
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
271
|
+
if (!response.ok) {
|
|
272
|
+
throw new Error(text || response.statusText)
|
|
273
|
+
}
|
|
285
274
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
275
|
+
if (text === 'false') {
|
|
276
|
+
throw new Error('Invalid Homey ID')
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const homeyId = response.headers.get('X-Homey-ID');
|
|
280
|
+
|
|
281
|
+
if (homeyId && homeyId !== this.id) {
|
|
282
|
+
throw new Error('Invalid Homey ID'); // TODO: Add to Homey Connect
|
|
283
|
+
}
|
|
292
284
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
285
|
+
// Set the version that Homey told us.
|
|
286
|
+
// It's the absolute truth, because the Cloud API may be behind.
|
|
287
|
+
const homeyVersion = response.headers.get('X-Homey-Version');
|
|
288
|
+
|
|
289
|
+
if (homeyVersion !== this.version) {
|
|
290
|
+
this.version = homeyVersion;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return {
|
|
294
|
+
baseUrl,
|
|
295
|
+
strategyId,
|
|
296
|
+
};
|
|
302
297
|
};
|
|
303
298
|
|
|
304
299
|
const pings = {};
|
|
305
300
|
|
|
306
301
|
// Ping localSecure (https://xxx-xxx-xxx-xx.homey.homeylocal.com)
|
|
307
302
|
if (urls[HomeyAPI.DISCOVERY_STRATEGIES.LOCAL_SECURE]) {
|
|
308
|
-
pings[HomeyAPI.DISCOVERY_STRATEGIES.LOCAL_SECURE] = ping(HomeyAPI.DISCOVERY_STRATEGIES.LOCAL_SECURE,
|
|
303
|
+
pings[HomeyAPI.DISCOVERY_STRATEGIES.LOCAL_SECURE] = ping(HomeyAPI.DISCOVERY_STRATEGIES.LOCAL_SECURE, 1200);
|
|
309
304
|
pings[HomeyAPI.DISCOVERY_STRATEGIES.LOCAL_SECURE].catch(err => {
|
|
310
305
|
this.__debug(`Ping ${HomeyAPI.DISCOVERY_STRATEGIES.LOCAL_SECURE} Error:`, err && err.message);
|
|
311
306
|
this.__debug(urls[HomeyAPI.DISCOVERY_STRATEGIES.LOCAL_SECURE]);
|
|
@@ -455,6 +450,7 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
455
450
|
}
|
|
456
451
|
|
|
457
452
|
this.__debug(method, `${baseUrl}${path}`);
|
|
453
|
+
|
|
458
454
|
const res = await Util.fetch(
|
|
459
455
|
`${baseUrl}${path}`,
|
|
460
456
|
{
|
|
@@ -472,11 +468,11 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
472
468
|
const resHeadersContentType = res.headers.get('Content-Type');
|
|
473
469
|
const version = res.headers.get('x-homey-version');
|
|
474
470
|
if (version) {
|
|
475
|
-
|
|
471
|
+
this.__versionCache[this.id] = version;
|
|
476
472
|
}
|
|
477
473
|
const tier = res.headers.get('x-homey-tier');
|
|
478
474
|
if (tier) {
|
|
479
|
-
|
|
475
|
+
this.__tierCache[this.id] = tier;
|
|
480
476
|
}
|
|
481
477
|
|
|
482
478
|
const resBodyText = await res.text();
|
|
@@ -485,7 +481,7 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
485
481
|
try {
|
|
486
482
|
resBodyJson = JSON.parse(resBodyText);
|
|
487
483
|
// eslint-disable-next-line no-empty
|
|
488
|
-
} catch (err) {}
|
|
484
|
+
} catch (err) { }
|
|
489
485
|
}
|
|
490
486
|
|
|
491
487
|
if (!res.ok) {
|
|
@@ -554,31 +550,7 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
554
550
|
return;
|
|
555
551
|
}
|
|
556
552
|
|
|
557
|
-
|
|
558
|
-
// and then sending the JWT token to Homey.
|
|
559
|
-
if (this.__api) {
|
|
560
|
-
this.__debug('Retrieving token...');
|
|
561
|
-
const jwtToken = await this.__api.createDelegationToken({ audience: 'homey' });
|
|
562
|
-
const token = await this.users.login({
|
|
563
|
-
$socket: false,
|
|
564
|
-
token: jwtToken,
|
|
565
|
-
shouldRetry: false,
|
|
566
|
-
});
|
|
567
|
-
this.__token = token;
|
|
568
|
-
|
|
569
|
-
const session = await this.sessions.getSessionMe({
|
|
570
|
-
$socket: false,
|
|
571
|
-
shouldRetry: false,
|
|
572
|
-
});
|
|
573
|
-
this.__session = session;
|
|
574
|
-
|
|
575
|
-
await this.__setStore({ token, session });
|
|
576
|
-
|
|
577
|
-
this.__debug('Got token');
|
|
578
|
-
return;
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
throw new Error('Cannot Sign In: Missing AthomCloudAPI');
|
|
553
|
+
await this.__refreshSession();
|
|
582
554
|
});
|
|
583
555
|
|
|
584
556
|
this.__loginPromise
|
|
@@ -596,6 +568,50 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
596
568
|
return this.__loginPromise;
|
|
597
569
|
}
|
|
598
570
|
|
|
571
|
+
async __refreshSession() {
|
|
572
|
+
this.__debug('refreshSession');
|
|
573
|
+
|
|
574
|
+
if (this.__api) {
|
|
575
|
+
// Create a Session by generating a JWT token on AthomCloudAPI,
|
|
576
|
+
// and then sending the JWT token to Homey.
|
|
577
|
+
const jwtToken = await this.__api.createDelegationToken({ audience: 'homey' });
|
|
578
|
+
const token = await this.users.login({
|
|
579
|
+
$socket: false,
|
|
580
|
+
token: jwtToken,
|
|
581
|
+
shouldRetry: false,
|
|
582
|
+
});
|
|
583
|
+
this.__token = token;
|
|
584
|
+
|
|
585
|
+
const session = await this.sessions.getSessionMe({
|
|
586
|
+
$socket: false,
|
|
587
|
+
shouldRetry: false,
|
|
588
|
+
});
|
|
589
|
+
this.__session = session;
|
|
590
|
+
|
|
591
|
+
await this.__setStore({ session, token });
|
|
592
|
+
|
|
593
|
+
this.__debug('Got token');
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
throw new Error('Cannot Sign In: Missing AthomCloudAPI');
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
async refreshSession() {
|
|
601
|
+
if (!this.__refreshSessionPromise) {
|
|
602
|
+
this.__refreshSessionPromise = this.__refreshSession();
|
|
603
|
+
|
|
604
|
+
this.__refreshSessionPromise
|
|
605
|
+
.catch(err => {
|
|
606
|
+
this.__debug('Error refreshing session:', err);
|
|
607
|
+
}).finally(() => {
|
|
608
|
+
this.__refreshSessionPromise = null;
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
return this.__refreshSessionPromise;
|
|
613
|
+
}
|
|
614
|
+
|
|
599
615
|
async logout() {
|
|
600
616
|
this.__token = null;
|
|
601
617
|
this.__session = null;
|
|
@@ -625,12 +641,12 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
625
641
|
});
|
|
626
642
|
|
|
627
643
|
this.__refreshMap[token]
|
|
628
|
-
.then(() => {})
|
|
644
|
+
.then(() => { })
|
|
629
645
|
.catch(err => {
|
|
630
646
|
this.__debug('Error Refreshing Token:', err);
|
|
631
647
|
})
|
|
632
648
|
.finally(() => {
|
|
633
|
-
// Delete after 30 seconds some requests might still be pending
|
|
649
|
+
// Delete after 30 seconds some requests might still be pending and they should be able
|
|
634
650
|
// to receive a rejected promise for this token.
|
|
635
651
|
this.__refreshMap[token + 'timeout'] = setTimeout(() => {
|
|
636
652
|
delete this.__refreshMap[token];
|
|
@@ -647,17 +663,17 @@ class HomeyAPIV3 extends HomeyAPI {
|
|
|
647
663
|
* @returns {Boolean}
|
|
648
664
|
*/
|
|
649
665
|
isConnected() {
|
|
650
|
-
return this.__homeySocket && this.__homeySocket.connected;
|
|
666
|
+
return Boolean(this.__homeySocket && this.__homeySocket.connected);
|
|
651
667
|
}
|
|
652
668
|
|
|
653
669
|
async subscribe(
|
|
654
670
|
uri,
|
|
655
671
|
{
|
|
656
|
-
onConnect = () => {},
|
|
657
|
-
onReconnect = () => {},
|
|
658
|
-
onReconnectError = () => {},
|
|
659
|
-
onDisconnect = () => {},
|
|
660
|
-
onEvent = () => {},
|
|
672
|
+
onConnect = () => { },
|
|
673
|
+
onReconnect = () => { },
|
|
674
|
+
onReconnectError = () => { },
|
|
675
|
+
onDisconnect = () => { },
|
|
676
|
+
onEvent = () => { },
|
|
661
677
|
}
|
|
662
678
|
) {
|
|
663
679
|
this.__debug('subscribe', uri);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const HomeyAPIV3 = require('./HomeyAPIV3');
|
|
4
4
|
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* This class is returned by {@link AthomCloudAPI.Homey#authenticate} for a Homey with `platform: 'cloud'` and `platformVersion: 1`.
|
|
7
8
|
*
|
|
@@ -33,6 +34,14 @@ class HomeyAPIV3Cloud extends HomeyAPIV3 {
|
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
get tier() {
|
|
38
|
+
return this.__tierCache[this.id];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get version() {
|
|
42
|
+
return this.__versionCache[this.id];
|
|
43
|
+
}
|
|
44
|
+
|
|
36
45
|
get platform() {
|
|
37
46
|
return 'cloud';
|
|
38
47
|
}
|
|
@@ -42,7 +51,6 @@ class HomeyAPIV3Cloud extends HomeyAPIV3 {
|
|
|
42
51
|
}
|
|
43
52
|
|
|
44
53
|
getSpecification() {
|
|
45
|
-
// eslint-disable-next-line global-require
|
|
46
54
|
return require('../../assets/specifications/HomeyAPIV3Cloud.json');
|
|
47
55
|
}
|
|
48
56
|
|
package/lib/Util.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homey-api",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.34",
|
|
4
4
|
"description": "Homey API",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"lint": "eslint .",
|
|
17
17
|
"serve": "concurrently \"serve jsdoc/\" \"npm run jsdoc:watch\"",
|
|
18
18
|
"build": "npm run build:specs && npm run build:jsdoc && npm run build:types && npm run build:webpack;",
|
|
19
|
+
"build:docs": "plantuml-cli -tsvg SOCKET.md",
|
|
19
20
|
"build:webpack": "npm run webpack",
|
|
20
21
|
"build:webpack:watch": "npm run webpack:watch",
|
|
21
22
|
"build:types": "npm run generate-types;",
|
|
@@ -75,6 +76,7 @@
|
|
|
75
76
|
"jsdoc-ts-utils": "^4.0.0",
|
|
76
77
|
"jsdoc-tsimport-plugin": "^1.0.5",
|
|
77
78
|
"keypather": "^3.1.0",
|
|
79
|
+
"plantuml-cli": "^1.2024.4",
|
|
78
80
|
"prettier": "^3.2.5",
|
|
79
81
|
"serve": "^14.0.1",
|
|
80
82
|
"socket.io": "^4.7.4",
|