homey-api 3.17.12 → 3.18.1

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.
@@ -4761,6 +4761,40 @@ export class AthomConnectAPI {
4761
4761
  }): Promise<any>;
4762
4762
  }
4763
4763
 
4764
+ export class AthomDeviceFirmwareAPI {
4765
+ constructor(opts?: {
4766
+ baseUrl?: string;
4767
+
4768
+ debug?: boolean;
4769
+
4770
+ secret?: string;
4771
+ });
4772
+
4773
+ getFirmwareURL(opts: {
4774
+ integrity: string;
4775
+
4776
+ noCache?: boolean;
4777
+
4778
+ sourceUrl?: string;
4779
+
4780
+ homeyTag?: string;
4781
+
4782
+ $timeout?: number;
4783
+ }): Promise<{ url: string; cache: string }>;
4784
+
4785
+ getFirmwareURL(opts: {
4786
+ integrity: string;
4787
+
4788
+ noCache?: boolean;
4789
+
4790
+ sourceUrl?: string;
4791
+
4792
+ homeyTag?: string;
4793
+
4794
+ $timeout?: number;
4795
+ }): Promise<{ url: string; cache: string }>;
4796
+ }
4797
+
4764
4798
  export class AthomDNSAPI {
4765
4799
  constructor(opts?: {
4766
4800
  baseUrl?: string;
@@ -8261,6 +8295,40 @@ export class AthomDNSAPI {
8261
8295
  getHomeyCertificate(opts: { secret: string }): Promise<any>;
8262
8296
  }
8263
8297
 
8298
+ export class AthomDeviceFirmwareAPI {
8299
+ constructor(opts?: {
8300
+ baseUrl?: string;
8301
+
8302
+ debug?: boolean;
8303
+
8304
+ secret?: string;
8305
+ });
8306
+
8307
+ getFirmwareURL(opts: {
8308
+ integrity: string;
8309
+
8310
+ noCache?: boolean;
8311
+
8312
+ sourceUrl?: string;
8313
+
8314
+ homeyTag?: string;
8315
+
8316
+ $timeout?: number;
8317
+ }): Promise<{ url: string; cache: string }>;
8318
+
8319
+ getFirmwareURL(opts: {
8320
+ integrity: string;
8321
+
8322
+ noCache?: boolean;
8323
+
8324
+ sourceUrl?: string;
8325
+
8326
+ homeyTag?: string;
8327
+
8328
+ $timeout?: number;
8329
+ }): Promise<{ url: string; cache: string }>;
8330
+ }
8331
+
8264
8332
  export class AthomEnergyAPI {
8265
8333
  constructor(opts?: {
8266
8334
  baseUrl?: string;
package/index.js CHANGED
@@ -20,6 +20,7 @@ module.exports.AthomStoreAPI = require('./lib/AthomStoreAPI');
20
20
  module.exports.AthomWeatherAPI = require('./lib/AthomWeatherAPI');
21
21
  module.exports.AthomWebhooksAPI = require('./lib/AthomWebhooksAPI');
22
22
  module.exports.AthomEnergyAPI = require('./lib/AthomEnergyAPI');
23
+ module.exports.AthomDeviceFirmwareAPI = require('./lib/AthomDeviceFirmwareAPI');
23
24
 
24
25
  // Homey Cloud
25
26
  module.exports.HomeyCloudAPI = require('./lib/HomeyCloudAPI');
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ const API = require('./API');
4
+
5
+ class AthomDeviceFirmwareAPI extends API {
6
+
7
+ static SPECIFICATION = {
8
+ host: 'device-firmware.athom.com',
9
+ basePath: '/',
10
+ operations: {},
11
+ };
12
+
13
+ static JSDOC_PRIVATE = true;
14
+
15
+ /**
16
+ * Get the location of a firmware update file.
17
+ *
18
+ * @param {Object} opts
19
+ * @param {string} opts.integrity - The integrity hash (i.e unique key) of the firmware file, e.g. "sha256:abcdef1234567890..."
20
+ * @param {boolean} [opts.noCache] - Whether to bypass the cache and fetch the firmware fresh from sourceUrl. Default: false.
21
+ * @param {string} [opts.sourceUrl] - The original URL of the firmware file, if the cache is bypassed or missed the server can attempt to fetch the file from this URL.
22
+ * @param {string} [opts.homeyTag] - How to tag the file in the cache (requires sourceUrl to be set, and the cache to be bypassed or missed).
23
+ * @param {number} [opts.$timeout] - Optional timeout in milliseconds for this API call.
24
+ * @returns {Promise<{ url: string, cache: string }>}
25
+ */
26
+ async getFirmwareURL({ integrity, noCache, sourceUrl, homeyTag, $timeout }) {
27
+ const query = {};
28
+
29
+ if (typeof this.__secret === 'string') {
30
+ query.secret = this.__secret;
31
+ }
32
+
33
+ if (noCache !== undefined) {
34
+ query.noCache = noCache;
35
+ }
36
+
37
+ if (sourceUrl !== undefined) {
38
+ query.sourceUrl = sourceUrl;
39
+ }
40
+
41
+ if (homeyTag !== undefined) {
42
+ query.homeyTag = homeyTag;
43
+ }
44
+
45
+ return this.call({
46
+ method: 'get',
47
+ path: `/firmware/${integrity}`,
48
+ query,
49
+ timeout: $timeout,
50
+ });
51
+ }
52
+
53
+ }
54
+
55
+ module.exports = AthomDeviceFirmwareAPI;
@@ -62,35 +62,39 @@ class Item extends EventEmitter {
62
62
  writable: true,
63
63
  });
64
64
 
65
- this.__realtimeConsumer = new RealtimeConsumer({
66
- subscribe: (uri, handlers) => this.homey.subscribe(uri, handlers),
67
- getUri: () => this.uri,
68
- debug: (...props) => this.__debug(...props),
69
- setConnected: (connected) => {
70
- this.__connected = connected;
71
- },
72
- onConnect: () => {
73
- this.onConnect();
74
- },
75
- onDisconnect: () => {
76
- this.onDisconnect();
77
- },
78
- onReconnect: () => {
79
- this.onReconnect();
80
- },
81
- onEvent: (event, data) => {
82
- if (event === 'update') {
83
- this.__update(this.constructor.transformGet({ ...data }));
84
- return;
85
- }
86
-
87
- if (event === 'delete') {
88
- this.__delete();
89
- return;
90
- }
91
-
92
- this.emit(event, data);
93
- },
65
+ Object.defineProperty(this, '__realtimeConsumer', {
66
+ value: new RealtimeConsumer({
67
+ subscribe: (uri, handlers) => this.homey.subscribe(uri, handlers),
68
+ getUri: () => this.uri,
69
+ debug: (...props) => this.__debug(...props),
70
+ setConnected: (connected) => {
71
+ this.__connected = connected;
72
+ },
73
+ onConnect: () => {
74
+ this.onConnect();
75
+ },
76
+ onDisconnect: () => {
77
+ this.onDisconnect();
78
+ },
79
+ onReconnect: () => {
80
+ this.onReconnect();
81
+ },
82
+ onEvent: (event, data) => {
83
+ if (event === 'update') {
84
+ this.__update(this.constructor.transformGet({ ...data }));
85
+ return;
86
+ }
87
+
88
+ if (event === 'delete') {
89
+ this.__delete();
90
+ return;
91
+ }
92
+
93
+ this.emit(event, data);
94
+ },
95
+ }),
96
+ enumerable: false,
97
+ writable: false,
94
98
  });
95
99
 
96
100
  // Set Properties
@@ -87,69 +87,73 @@ class Manager extends EventEmitter {
87
87
  writable: false,
88
88
  });
89
89
 
90
- this.__realtimeConsumer = new RealtimeConsumer({
91
- subscribe: (uri, handlers) => this.homey.subscribe(uri, handlers),
92
- getUri: () => this.uri,
93
- debug: (...props) => this.__debug(...props),
94
- setConnected: (connected) => {
95
- this.__connected = connected;
96
- },
97
- onEvent: (event, data) => {
98
- // Transform & add to cache if this is a CRUD event
99
- if (event.endsWith('.create') || event.endsWith('.update') || event.endsWith('.delete')) {
100
- const [itemId, operation] = event.split('.');
101
- const itemName = this.itemNames[itemId];
102
- const ItemClass = this.itemClasses[itemName];
103
-
104
- switch (operation) {
105
- case 'create': {
106
- const props = ItemClass.transformGet(data);
107
-
108
- const item = new ItemClass({
109
- id: props.id,
110
- homey: this.homey,
111
- manager: this,
112
- properties: props,
113
- });
114
- this.__cache[ItemClass.ID][props.id] = item;
115
-
116
- this.emit(event, item);
117
- return;
118
- }
119
- case 'update': {
120
- const props = ItemClass.transformGet(data);
90
+ Object.defineProperty(this, '__realtimeConsumer', {
91
+ value: new RealtimeConsumer({
92
+ subscribe: (uri, handlers) => this.homey.subscribe(uri, handlers),
93
+ getUri: () => this.uri,
94
+ debug: (...props) => this.__debug(...props),
95
+ setConnected: (connected) => {
96
+ this.__connected = connected;
97
+ },
98
+ onEvent: (event, data) => {
99
+ // Transform & add to cache if this is a CRUD event
100
+ if (event.endsWith('.create') || event.endsWith('.update') || event.endsWith('.delete')) {
101
+ const [itemId, operation] = event.split('.');
102
+ const itemName = this.itemNames[itemId];
103
+ const ItemClass = this.itemClasses[itemName];
104
+
105
+ switch (operation) {
106
+ case 'create': {
107
+ const props = ItemClass.transformGet(data);
108
+
109
+ const item = new ItemClass({
110
+ id: props.id,
111
+ homey: this.homey,
112
+ manager: this,
113
+ properties: props,
114
+ });
115
+ this.__cache[ItemClass.ID][props.id] = item;
121
116
 
122
- if (this.__cache[ItemClass.ID][props.id]) {
123
- const item = this.__cache[ItemClass.ID][props.id];
124
- item.__update(props);
125
117
  this.emit(event, item);
126
118
  return;
127
119
  }
120
+ case 'update': {
121
+ const props = ItemClass.transformGet(data);
122
+
123
+ if (this.__cache[ItemClass.ID][props.id]) {
124
+ const item = this.__cache[ItemClass.ID][props.id];
125
+ item.__update(props);
126
+ this.emit(event, item);
127
+ return;
128
+ }
128
129
 
129
- break;
130
- }
131
- case 'delete': {
132
- const props = ItemClass.transformGet(data);
133
-
134
- if (this.__cache[ItemClass.ID][props.id]) {
135
- const item = this.__cache[ItemClass.ID][props.id];
136
- item.__delete();
137
- delete this.__cache[ItemClass.ID][item.id];
138
- this.emit(event, {
139
- id: item.id,
140
- });
141
- return;
130
+ break;
142
131
  }
132
+ case 'delete': {
133
+ const props = ItemClass.transformGet(data);
134
+
135
+ if (this.__cache[ItemClass.ID][props.id]) {
136
+ const item = this.__cache[ItemClass.ID][props.id];
137
+ item.__delete();
138
+ delete this.__cache[ItemClass.ID][item.id];
139
+ this.emit(event, {
140
+ id: item.id,
141
+ });
142
+ return;
143
+ }
143
144
 
144
- break;
145
+ break;
146
+ }
147
+ default:
148
+ break;
145
149
  }
146
- default:
147
- break;
148
150
  }
149
- }
150
151
 
151
- this.emit(event, data);
152
- },
152
+ this.emit(event, data);
153
+ },
154
+ }),
155
+ enumerable: false,
156
+ writable: false,
153
157
  });
154
158
 
155
159
  // Create methods
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homey-api",
3
- "version": "3.17.12",
3
+ "version": "3.18.1",
4
4
  "description": "Homey API",
5
5
  "main": "index.js",
6
6
  "license": "SEE LICENSE",