@switchbot/homebridge-switchbot 1.15.1-beta.9 → 2.0.0-beta.0
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/.github/Old Releaser.zip +0 -0
- package/.github/npm-version-script.js +81 -0
- package/.github/workflows/beta-release.yml +31 -0
- package/.github/workflows/build.yml +18 -0
- package/.github/workflows/codeql-analysis.yml +5 -63
- package/.github/workflows/label.yml +2 -2
- package/.github/workflows/release-drafter.yml +14 -0
- package/.github/workflows/release.yml +24 -0
- package/.github/workflows/stale.yml +6 -22
- package/README.md +10 -3
- package/dist/device/bot.js +1 -1
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +33 -7
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.js +1 -1
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +8 -2
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.js +1 -1
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/meter.js +1 -1
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.js +1 -1
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.js +1 -1
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.js +1 -1
- package/dist/device/plug.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +35 -32
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +30 -28
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +28 -26
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +47 -45
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +40 -38
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +28 -26
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +82 -80
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +24 -22
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +28 -26
- package/dist/irdevice/waterheater.js.map +1 -1
- package/package.json +79 -79
- package/src/device/bot.ts +1 -1
- package/src/device/colorbulb.ts +33 -9
- package/src/device/contact.ts +1 -1
- package/src/device/curtain.ts +8 -2
- package/src/device/humidifier.ts +1 -1
- package/src/device/meter.ts +1 -1
- package/src/device/meterplus.ts +1 -1
- package/src/device/motion.ts +1 -1
- package/src/device/plug.ts +1 -1
- package/src/irdevice/airconditioner.ts +35 -40
- package/src/irdevice/airpurifier.ts +30 -37
- package/src/irdevice/camera.ts +28 -33
- package/src/irdevice/fan.ts +47 -52
- package/src/irdevice/light.ts +40 -45
- package/src/irdevice/other.ts +28 -33
- package/src/irdevice/tv.ts +82 -87
- package/src/irdevice/vacuumcleaner.ts +24 -29
- package/src/irdevice/waterheater.ts +28 -33
- package/.github/workflows/nodejs-beta.yml +0 -42
- package/.github/workflows/nodejs.yml +0 -47
- package/.github/workflows/prerelease-beta.js +0 -34
package/src/irdevice/other.ts
CHANGED
|
@@ -99,12 +99,12 @@ export class Others {
|
|
|
99
99
|
if (this.device.other) {
|
|
100
100
|
if (this.device.other.commandOn) {
|
|
101
101
|
if (!this.Active) {
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
parameter: 'default',
|
|
105
|
-
|
|
106
|
-
};
|
|
107
|
-
await this.pushChanges(
|
|
102
|
+
const body = JSON.stringify({
|
|
103
|
+
'command': `${this.device.other.commandOn}`,
|
|
104
|
+
'parameter': 'default',
|
|
105
|
+
'commandType': 'customize',
|
|
106
|
+
});
|
|
107
|
+
await this.pushChanges(body);
|
|
108
108
|
}
|
|
109
109
|
} else {
|
|
110
110
|
this.errorLog(`Other: ${this.accessory.displayName} On Command not set, commandOn: ${this.device.other.commandOn}`);
|
|
@@ -122,12 +122,12 @@ export class Others {
|
|
|
122
122
|
if (this.device.other) {
|
|
123
123
|
if (this.device.other.commandOff) {
|
|
124
124
|
if (this.Active) {
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
parameter: 'default',
|
|
128
|
-
|
|
129
|
-
};
|
|
130
|
-
await this.pushChanges(
|
|
125
|
+
const body = JSON.stringify({
|
|
126
|
+
'command': `${this.device.other.commandOff}`,
|
|
127
|
+
'parameter': 'default',
|
|
128
|
+
'commandType': 'customize',
|
|
129
|
+
});
|
|
130
|
+
await this.pushChanges(body);
|
|
131
131
|
}
|
|
132
132
|
} else {
|
|
133
133
|
this.errorLog(`Other: ${this.accessory.displayName} Off Command not set, commandOff: ${this.device.other.commandOff}`);
|
|
@@ -140,49 +140,44 @@ export class Others {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
async pushChanges(
|
|
143
|
+
async pushChanges(body): Promise<void> {
|
|
144
144
|
try {
|
|
145
|
-
|
|
146
|
-
`Other: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
147
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
// Make the API request
|
|
145
|
+
// Make Push On request to the API
|
|
151
146
|
const t = Date.now();
|
|
152
147
|
const nonce = 'requestID';
|
|
153
148
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
154
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
149
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
150
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
151
|
+
.digest();
|
|
155
152
|
const sign = signTerm.toString('base64');
|
|
156
153
|
this.debugLog(`Other: ${this.accessory.displayName} sign: ${sign}`);
|
|
154
|
+
this.infoLog(`Other: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
157
155
|
const options = {
|
|
158
156
|
hostname: HostDomain,
|
|
159
157
|
port: 443,
|
|
160
158
|
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
161
159
|
method: 'POST',
|
|
162
160
|
headers: {
|
|
163
|
-
Authorization: this.platform.config.credentials?.token,
|
|
164
|
-
sign: sign,
|
|
165
|
-
nonce: nonce,
|
|
166
|
-
t: t,
|
|
161
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
162
|
+
'sign': sign,
|
|
163
|
+
'nonce': nonce,
|
|
164
|
+
't': t,
|
|
167
165
|
'Content-Type': 'application/json',
|
|
166
|
+
'Content-Length': body.length,
|
|
168
167
|
},
|
|
169
168
|
};
|
|
170
|
-
|
|
171
|
-
const req = https.request(options, (res) => {
|
|
169
|
+
const req = https.request(options, res => {
|
|
172
170
|
this.debugLog(`Other: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
173
171
|
this.statusCode({ res });
|
|
174
|
-
res.on('data',
|
|
172
|
+
res.on('data', d => {
|
|
175
173
|
this.debugLog(`Other: ${this.accessory.displayName} d: ${d}`);
|
|
176
174
|
});
|
|
177
175
|
});
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
this.errorLog(`Other: ${this.accessory.displayName} error: ${error}`);
|
|
176
|
+
req.on('error', (e: any) => {
|
|
177
|
+
this.errorLog(`Other: ${this.accessory.displayName} error message: ${e.message}`);
|
|
181
178
|
});
|
|
182
|
-
|
|
183
|
-
req.write(payload);
|
|
179
|
+
req.write(body);
|
|
184
180
|
req.end();
|
|
185
|
-
|
|
186
181
|
this.debugLog(`Other: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
|
|
187
182
|
this.updateHomeKitCharacteristics();
|
|
188
183
|
} catch (e: any) {
|
package/src/irdevice/tv.ts
CHANGED
|
@@ -237,148 +237,143 @@ export class TV {
|
|
|
237
237
|
*/
|
|
238
238
|
async pushTvOnChanges(): Promise<void> {
|
|
239
239
|
if (this.Active !== 1) {
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
parameter: 'default',
|
|
243
|
-
|
|
244
|
-
};
|
|
245
|
-
await this.pushTVChanges(
|
|
240
|
+
const body = JSON.stringify({
|
|
241
|
+
'command': 'turnOn',
|
|
242
|
+
'parameter': 'default',
|
|
243
|
+
'commandType': 'command',
|
|
244
|
+
});
|
|
245
|
+
await this.pushTVChanges(body);
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
async pushTvOffChanges(): Promise<void> {
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
parameter: 'default',
|
|
253
|
-
|
|
254
|
-
};
|
|
255
|
-
await this.pushTVChanges(
|
|
250
|
+
const body = JSON.stringify({
|
|
251
|
+
'command': 'turnOff',
|
|
252
|
+
'parameter': 'default',
|
|
253
|
+
'commandType': 'command',
|
|
254
|
+
});
|
|
255
|
+
await this.pushTVChanges(body);
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
async pushOkChanges(): Promise<void> {
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
parameter: 'default',
|
|
262
|
-
|
|
263
|
-
};
|
|
264
|
-
await this.pushTVChanges(
|
|
259
|
+
const body = JSON.stringify({
|
|
260
|
+
'command': 'Ok',
|
|
261
|
+
'parameter': 'default',
|
|
262
|
+
'commandType': 'command',
|
|
263
|
+
});
|
|
264
|
+
await this.pushTVChanges(body);
|
|
265
265
|
}
|
|
266
266
|
|
|
267
267
|
async pushBackChanges(): Promise<void> {
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
parameter: 'default',
|
|
271
|
-
|
|
272
|
-
};
|
|
273
|
-
await this.pushTVChanges(
|
|
268
|
+
const body = JSON.stringify({
|
|
269
|
+
'command': 'Back',
|
|
270
|
+
'parameter': 'default',
|
|
271
|
+
'commandType': 'command',
|
|
272
|
+
});
|
|
273
|
+
await this.pushTVChanges(body);
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
async pushMenuChanges(): Promise<void> {
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
parameter: 'default',
|
|
280
|
-
|
|
281
|
-
};
|
|
282
|
-
await this.pushTVChanges(
|
|
277
|
+
const body = JSON.stringify({
|
|
278
|
+
'command': 'Menu',
|
|
279
|
+
'parameter': 'default',
|
|
280
|
+
'commandType': 'command',
|
|
281
|
+
});
|
|
282
|
+
await this.pushTVChanges(body);
|
|
283
283
|
}
|
|
284
284
|
|
|
285
285
|
async pushUpChanges(): Promise<void> {
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
parameter: 'default',
|
|
289
|
-
|
|
290
|
-
};
|
|
291
|
-
await this.pushTVChanges(
|
|
286
|
+
const body = JSON.stringify({
|
|
287
|
+
'command': 'Up',
|
|
288
|
+
'parameter': 'default',
|
|
289
|
+
'commandType': 'command',
|
|
290
|
+
});
|
|
291
|
+
await this.pushTVChanges(body);
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
async pushDownChanges(): Promise<void> {
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
parameter: 'default',
|
|
298
|
-
|
|
299
|
-
};
|
|
300
|
-
await this.pushTVChanges(
|
|
295
|
+
const body = JSON.stringify({
|
|
296
|
+
'command': 'Down',
|
|
297
|
+
'parameter': 'default',
|
|
298
|
+
'commandType': 'command',
|
|
299
|
+
});
|
|
300
|
+
await this.pushTVChanges(body);
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
async pushRightChanges(): Promise<void> {
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
parameter: 'default',
|
|
307
|
-
|
|
308
|
-
};
|
|
309
|
-
await this.pushTVChanges(
|
|
304
|
+
const body = JSON.stringify({
|
|
305
|
+
'command': 'Right',
|
|
306
|
+
'parameter': 'default',
|
|
307
|
+
'commandType': 'command',
|
|
308
|
+
});
|
|
309
|
+
await this.pushTVChanges(body);
|
|
310
310
|
}
|
|
311
311
|
|
|
312
312
|
async pushLeftChanges(): Promise<void> {
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
parameter: 'default',
|
|
316
|
-
|
|
317
|
-
};
|
|
318
|
-
await this.pushTVChanges(
|
|
313
|
+
const body = JSON.stringify({
|
|
314
|
+
'command': 'Left',
|
|
315
|
+
'parameter': 'default',
|
|
316
|
+
'commandType': 'command',
|
|
317
|
+
});
|
|
318
|
+
await this.pushTVChanges(body);
|
|
319
319
|
}
|
|
320
320
|
|
|
321
321
|
async pushVolumeUpChanges(): Promise<void> {
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
parameter: 'default',
|
|
325
|
-
|
|
326
|
-
};
|
|
327
|
-
await this.pushTVChanges(
|
|
322
|
+
const body = JSON.stringify({
|
|
323
|
+
'command': 'volumeAdd',
|
|
324
|
+
'parameter': 'default',
|
|
325
|
+
'commandType': 'command',
|
|
326
|
+
});
|
|
327
|
+
await this.pushTVChanges(body);
|
|
328
328
|
}
|
|
329
329
|
|
|
330
330
|
async pushVolumeDownChanges(): Promise<void> {
|
|
331
|
-
const
|
|
332
|
-
|
|
333
|
-
parameter: 'default',
|
|
334
|
-
|
|
335
|
-
};
|
|
336
|
-
await this.pushTVChanges(
|
|
331
|
+
const body = JSON.stringify({
|
|
332
|
+
'command': 'volumeSub',
|
|
333
|
+
'parameter': 'default',
|
|
334
|
+
'commandType': 'command',
|
|
335
|
+
});
|
|
336
|
+
await this.pushTVChanges(body);
|
|
337
337
|
}
|
|
338
338
|
|
|
339
|
-
async pushTVChanges(
|
|
339
|
+
async pushTVChanges(body): Promise<void> {
|
|
340
340
|
try {
|
|
341
|
-
|
|
342
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
343
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
344
|
-
);
|
|
345
|
-
|
|
346
|
-
// Make the API request
|
|
341
|
+
// Make Push On request to the API
|
|
347
342
|
const t = Date.now();
|
|
348
343
|
const nonce = 'requestID';
|
|
349
344
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
350
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
345
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
346
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
347
|
+
.digest();
|
|
351
348
|
const sign = signTerm.toString('base64');
|
|
352
349
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
350
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
353
351
|
const options = {
|
|
354
352
|
hostname: HostDomain,
|
|
355
353
|
port: 443,
|
|
356
354
|
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
357
355
|
method: 'POST',
|
|
358
356
|
headers: {
|
|
359
|
-
Authorization: this.platform.config.credentials?.token,
|
|
360
|
-
sign: sign,
|
|
361
|
-
nonce: nonce,
|
|
362
|
-
t: t,
|
|
357
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
358
|
+
'sign': sign,
|
|
359
|
+
'nonce': nonce,
|
|
360
|
+
't': t,
|
|
363
361
|
'Content-Type': 'application/json',
|
|
362
|
+
'Content-Length': body.length,
|
|
364
363
|
},
|
|
365
364
|
};
|
|
366
|
-
|
|
367
|
-
const req = https.request(options, (res) => {
|
|
365
|
+
const req = https.request(options, res => {
|
|
368
366
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
369
367
|
this.statusCode({ res });
|
|
370
|
-
res.on('data',
|
|
368
|
+
res.on('data', d => {
|
|
371
369
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
|
|
372
370
|
});
|
|
373
371
|
});
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} error: ${error}`);
|
|
372
|
+
req.on('error', (e: any) => {
|
|
373
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
377
374
|
});
|
|
378
|
-
|
|
379
|
-
req.write(payload);
|
|
375
|
+
req.write(body);
|
|
380
376
|
req.end();
|
|
381
|
-
|
|
382
377
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
|
|
383
378
|
this.updateHomeKitCharacteristics();
|
|
384
379
|
} catch (e: any) {
|
|
@@ -86,40 +86,38 @@ export class VacuumCleaner {
|
|
|
86
86
|
*/
|
|
87
87
|
async pushOnChanges(): Promise<void> {
|
|
88
88
|
if (this.On) {
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
parameter: 'default',
|
|
92
|
-
|
|
93
|
-
};
|
|
94
|
-
await this.pushChanges(
|
|
89
|
+
const body = JSON.stringify({
|
|
90
|
+
'command': 'turnOn',
|
|
91
|
+
'parameter': 'default',
|
|
92
|
+
'commandType': 'command',
|
|
93
|
+
});
|
|
94
|
+
await this.pushChanges(body);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
async pushOffChanges(): Promise<void> {
|
|
99
99
|
if (!this.On) {
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
parameter: 'default',
|
|
103
|
-
|
|
104
|
-
};
|
|
105
|
-
await this.pushChanges(
|
|
100
|
+
const body = JSON.stringify({
|
|
101
|
+
'command': 'turnOff',
|
|
102
|
+
'parameter': 'default',
|
|
103
|
+
'commandType': 'command',
|
|
104
|
+
});
|
|
105
|
+
await this.pushChanges(body);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
async pushChanges(
|
|
109
|
+
async pushChanges(body): Promise<void> {
|
|
110
110
|
try {
|
|
111
|
-
|
|
112
|
-
`Vacuum Cleaner: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
113
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
// Make the API request
|
|
111
|
+
// Make Push On request to the API
|
|
117
112
|
const t = Date.now();
|
|
118
113
|
const nonce = 'requestID';
|
|
119
114
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
120
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
115
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
116
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
117
|
+
.digest();
|
|
121
118
|
const sign = signTerm.toString('base64');
|
|
122
119
|
this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} sign: ${sign}`);
|
|
120
|
+
this.infoLog(`Vacuum Cleaner: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
123
121
|
const options = {
|
|
124
122
|
hostname: HostDomain,
|
|
125
123
|
port: 443,
|
|
@@ -131,24 +129,21 @@ export class VacuumCleaner {
|
|
|
131
129
|
'nonce': nonce,
|
|
132
130
|
't': t,
|
|
133
131
|
'Content-Type': 'application/json',
|
|
132
|
+
'Content-Length': body.length,
|
|
134
133
|
},
|
|
135
134
|
};
|
|
136
|
-
|
|
137
|
-
const req = https.request(options, (res) => {
|
|
135
|
+
const req = https.request(options, res => {
|
|
138
136
|
this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
139
137
|
this.statusCode({ res });
|
|
140
|
-
res.on('data',
|
|
138
|
+
res.on('data', d => {
|
|
141
139
|
this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} d: ${d}`);
|
|
142
140
|
});
|
|
143
141
|
});
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} error: ${error}`);
|
|
142
|
+
req.on('error', (e: any) => {
|
|
143
|
+
this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} error message: ${e.message}`);
|
|
147
144
|
});
|
|
148
|
-
|
|
149
|
-
req.write(payload);
|
|
145
|
+
req.write(body);
|
|
150
146
|
req.end();
|
|
151
|
-
|
|
152
147
|
this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
|
|
153
148
|
this.OnCached = this.On;
|
|
154
149
|
this.accessory.context.On = this.OnCached;
|
|
@@ -93,69 +93,64 @@ export class WaterHeater {
|
|
|
93
93
|
*/
|
|
94
94
|
async pushWaterHeaterOnChanges(): Promise<void> {
|
|
95
95
|
if (this.Active !== 1) {
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
parameter: 'default',
|
|
99
|
-
|
|
100
|
-
};
|
|
101
|
-
await this.pushChanges(
|
|
96
|
+
const body = JSON.stringify({
|
|
97
|
+
'command': 'turnOn',
|
|
98
|
+
'parameter': 'default',
|
|
99
|
+
'commandType': 'command',
|
|
100
|
+
});
|
|
101
|
+
await this.pushChanges(body);
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
async pushWaterHeaterOffChanges(): Promise<void> {
|
|
106
106
|
if (this.Active !== 0) {
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
parameter: 'default',
|
|
110
|
-
|
|
111
|
-
};
|
|
112
|
-
await this.pushChanges(
|
|
107
|
+
const body = JSON.stringify({
|
|
108
|
+
'command': 'turnOff',
|
|
109
|
+
'parameter': 'default',
|
|
110
|
+
'commandType': 'command',
|
|
111
|
+
});
|
|
112
|
+
await this.pushChanges(body);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
async pushChanges(
|
|
116
|
+
async pushChanges(body): Promise<void> {
|
|
117
117
|
try {
|
|
118
|
-
|
|
119
|
-
`Water Heater: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
120
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
// Make the API request
|
|
118
|
+
// Make Push On request to the API
|
|
124
119
|
const t = Date.now();
|
|
125
120
|
const nonce = 'requestID';
|
|
126
121
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
127
|
-
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
122
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
123
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
124
|
+
.digest();
|
|
128
125
|
const sign = signTerm.toString('base64');
|
|
129
126
|
this.debugLog(`Water Heater: ${this.accessory.displayName} sign: ${sign}`);
|
|
127
|
+
this.infoLog(`Water Heater: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
130
128
|
const options = {
|
|
131
129
|
hostname: HostDomain,
|
|
132
130
|
port: 443,
|
|
133
131
|
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
134
132
|
method: 'POST',
|
|
135
133
|
headers: {
|
|
136
|
-
Authorization: this.platform.config.credentials?.token,
|
|
137
|
-
sign: sign,
|
|
138
|
-
nonce: nonce,
|
|
139
|
-
t: t,
|
|
134
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
135
|
+
'sign': sign,
|
|
136
|
+
'nonce': nonce,
|
|
137
|
+
't': t,
|
|
140
138
|
'Content-Type': 'application/json',
|
|
139
|
+
'Content-Length': body.length,
|
|
141
140
|
},
|
|
142
141
|
};
|
|
143
|
-
|
|
144
|
-
const req = https.request(options, (res) => {
|
|
142
|
+
const req = https.request(options, res => {
|
|
145
143
|
this.debugLog(`Water Heater: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
146
144
|
this.statusCode({ res });
|
|
147
|
-
res.on('data',
|
|
145
|
+
res.on('data', d => {
|
|
148
146
|
this.debugLog(`Water Heater: ${this.accessory.displayName} d: ${d}`);
|
|
149
147
|
});
|
|
150
148
|
});
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
this.errorLog(`Water Heater: ${this.accessory.displayName} error: ${error}`);
|
|
149
|
+
req.on('error', (e: any) => {
|
|
150
|
+
this.errorLog(`Water Heater: ${this.accessory.displayName} error message: ${e.message}`);
|
|
154
151
|
});
|
|
155
|
-
|
|
156
|
-
req.write(payload);
|
|
152
|
+
req.write(body);
|
|
157
153
|
req.end();
|
|
158
|
-
|
|
159
154
|
this.debugLog(`Water Heater: ${this.accessory.displayName} pushchanges: ${JSON.stringify(req)}`);
|
|
160
155
|
this.updateHomeKitCharacteristics();
|
|
161
156
|
} catch (e: any) {
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
2
|
-
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
|
|
3
|
-
|
|
4
|
-
name: Beta
|
|
5
|
-
|
|
6
|
-
on:
|
|
7
|
-
push:
|
|
8
|
-
branches:
|
|
9
|
-
- beta
|
|
10
|
-
|
|
11
|
-
jobs:
|
|
12
|
-
build:
|
|
13
|
-
runs-on: ubuntu-latest
|
|
14
|
-
steps:
|
|
15
|
-
- uses: actions/checkout@v3
|
|
16
|
-
- uses: actions/setup-node@v3
|
|
17
|
-
with:
|
|
18
|
-
node-version: 14
|
|
19
|
-
- name: npm install, build and test
|
|
20
|
-
run: |
|
|
21
|
-
npm install
|
|
22
|
-
npm run lint
|
|
23
|
-
npm run build
|
|
24
|
-
env:
|
|
25
|
-
CI: true
|
|
26
|
-
|
|
27
|
-
publish-npm:
|
|
28
|
-
if: github.repository == 'openwonderlabs/homebridge-switchbot'
|
|
29
|
-
needs: build
|
|
30
|
-
runs-on: ubuntu-latest
|
|
31
|
-
steps:
|
|
32
|
-
- uses: actions/checkout@v3
|
|
33
|
-
- uses: actions/setup-node@v3
|
|
34
|
-
with:
|
|
35
|
-
node-version: 14
|
|
36
|
-
registry-url: https://registry.npmjs.org/
|
|
37
|
-
- run: npm ci
|
|
38
|
-
- run: node .github/workflows/prerelease-beta.js
|
|
39
|
-
- run: npm --no-git-tag-version version prerelease --preid=beta
|
|
40
|
-
- run: npm publish --tag=beta
|
|
41
|
-
env:
|
|
42
|
-
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
name: Latest
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: latest
|
|
6
|
-
pull_request:
|
|
7
|
-
release: # Run when release is created
|
|
8
|
-
types: [created]
|
|
9
|
-
|
|
10
|
-
jobs:
|
|
11
|
-
build:
|
|
12
|
-
strategy:
|
|
13
|
-
matrix:
|
|
14
|
-
node-version: [14.x, 16.x]
|
|
15
|
-
os: [ubuntu-latest]
|
|
16
|
-
|
|
17
|
-
runs-on: ${{ matrix.os }}
|
|
18
|
-
|
|
19
|
-
steps:
|
|
20
|
-
- uses: actions/checkout@v3
|
|
21
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
22
|
-
uses: actions/setup-node@v3
|
|
23
|
-
with:
|
|
24
|
-
node-version: ${{ matrix.node-version }}
|
|
25
|
-
- name: npm install, build and test
|
|
26
|
-
run: |
|
|
27
|
-
npm install
|
|
28
|
-
npm run lint
|
|
29
|
-
npm run build
|
|
30
|
-
env:
|
|
31
|
-
CI: true
|
|
32
|
-
|
|
33
|
-
publish-npm:
|
|
34
|
-
# publish only if we are on our own repo, event was 'release' (a tag was created) and the tag starts with "v" (aka version tag)
|
|
35
|
-
if: github.repository == 'openwonderlabs/homebridge-switchbot' && github.event_name == 'release' && startsWith(github.ref, 'refs/tags/v')
|
|
36
|
-
needs: build # only run if build succeeds
|
|
37
|
-
runs-on: ubuntu-latest
|
|
38
|
-
steps:
|
|
39
|
-
- uses: actions/checkout@v3
|
|
40
|
-
- uses: actions/setup-node@v3
|
|
41
|
-
with:
|
|
42
|
-
node-version: 14 # use the minimum required version
|
|
43
|
-
registry-url: https://registry.npmjs.org/
|
|
44
|
-
- run: npm ci
|
|
45
|
-
- run: npm publish
|
|
46
|
-
env:
|
|
47
|
-
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
#!/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const semver = require('semver');
|
|
5
|
-
const child_process = require('child_process');
|
|
6
|
-
|
|
7
|
-
function getTagVersionFromNpm(tag) {
|
|
8
|
-
try {
|
|
9
|
-
return child_process.execSync(`npm info ${package.name} version --tag="${tag}"`).toString('utf8').trim();
|
|
10
|
-
} catch (e) {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// load package.json
|
|
16
|
-
const package = JSON.parse(fs.readFileSync('package.json', 'utf8'));
|
|
17
|
-
|
|
18
|
-
// work out the correct tag
|
|
19
|
-
const currentLatest = getTagVersionFromNpm('latest') || '0.0.0';
|
|
20
|
-
const currentBeta = getTagVersionFromNpm('beta') || '0.0.0';
|
|
21
|
-
const latestNpmTag = semver.gt(currentBeta, currentLatest, {
|
|
22
|
-
includePrerelease: true,
|
|
23
|
-
})
|
|
24
|
-
? currentBeta
|
|
25
|
-
: currentLatest;
|
|
26
|
-
const publishTag = semver.gt(package.version, latestNpmTag, {
|
|
27
|
-
includePrerelease: true,
|
|
28
|
-
})
|
|
29
|
-
? package.version
|
|
30
|
-
: latestNpmTag;
|
|
31
|
-
|
|
32
|
-
// save the package.json
|
|
33
|
-
package.version = publishTag;
|
|
34
|
-
fs.writeFileSync('package.json', JSON.stringify(package, null, 4));
|