homey-api 3.0.0-rc.20 → 3.0.0-rc.21

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.
@@ -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: ['PUT', 'POST'].includes(method) && typeof body !== 'undefined'
405
- ? JSON.stringify(body)
406
- : undefined,
406
+ body,
407
407
  }), $timeout);
408
408
 
409
409
  const resStatusCode = res.status;
@@ -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,11 @@ const HomeyAPIV3 = require('./HomeyAPIV3');
11
12
  */
12
13
  class HomeyAPIV3Local extends HomeyAPIV3 {
13
14
 
15
+ static MANAGERS = {
16
+ ...HomeyAPIV3.MANAGERS,
17
+ ManagerDevkit,
18
+ };
19
+
14
20
  getSpecification() {
15
21
  // eslint-disable-next-line global-require
16
22
  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.20",
3
+ "version": "3.0.0-rc.21",
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"