@switchbot/homebridge-switchbot 2.1.1-beta.2 → 2.1.1-beta.4
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/CHANGELOG.md +2 -1
- package/dist/device/curtain.js +2 -2
- package/dist/device/curtain.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +19 -6
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +13 -13
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +31 -10
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +40 -33
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +1 -1
- package/dist/platform.js.map +1 -1
- package/package.json +1 -1
- package/src/device/curtain.ts +2 -2
- package/src/irdevice/airconditioner.ts +14 -14
- package/src/irdevice/waterheater.ts +41 -34
- package/src/platform.ts +1 -1
|
@@ -5,6 +5,7 @@ import superStringify from 'super-stringify';
|
|
|
5
5
|
import { SwitchBotPlatform } from '../platform';
|
|
6
6
|
import { irDevicesConfig, irdevice, HostDomain, DevicePath } from '../settings';
|
|
7
7
|
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
8
|
+
const version = process.env.npm_package_version;
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Platform Accessory
|
|
@@ -23,8 +24,8 @@ export class WaterHeater {
|
|
|
23
24
|
|
|
24
25
|
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
|
|
25
26
|
// default placeholders
|
|
26
|
-
this.logs(device);
|
|
27
|
-
this.config(device);
|
|
27
|
+
this.logs({ device });
|
|
28
|
+
this.config({ device });
|
|
28
29
|
this.context();
|
|
29
30
|
|
|
30
31
|
// set accessory information
|
|
@@ -33,9 +34,9 @@ export class WaterHeater {
|
|
|
33
34
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
34
35
|
.setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
|
|
35
36
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
36
|
-
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
37
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision({ accessory, device }))
|
|
37
38
|
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
38
|
-
.updateValue(this.FirmwareRevision(accessory, device));
|
|
39
|
+
.updateValue(this.FirmwareRevision({ accessory, device }));
|
|
39
40
|
|
|
40
41
|
// get the Television service if it exists, otherwise create a new Television service
|
|
41
42
|
// you can create multiple services for each accessory
|
|
@@ -89,7 +90,7 @@ export class WaterHeater {
|
|
|
89
90
|
'parameter': 'default',
|
|
90
91
|
'commandType': commandType,
|
|
91
92
|
});
|
|
92
|
-
await this.pushChanges(body);
|
|
93
|
+
await this.pushChanges({ body });
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
96
|
|
|
@@ -102,11 +103,11 @@ export class WaterHeater {
|
|
|
102
103
|
'parameter': 'default',
|
|
103
104
|
'commandType': commandType,
|
|
104
105
|
});
|
|
105
|
-
await this.pushChanges(body);
|
|
106
|
+
await this.pushChanges({ body });
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
async pushChanges(body): Promise<void> {
|
|
110
|
+
async pushChanges({ body }: { body: any; }): Promise<void> {
|
|
110
111
|
if (this.device.connectionType === 'OpenAPI') {
|
|
111
112
|
try {
|
|
112
113
|
// Make Push On request to the API
|
|
@@ -118,7 +119,7 @@ export class WaterHeater {
|
|
|
118
119
|
.digest();
|
|
119
120
|
const sign = signTerm.toString('base64');
|
|
120
121
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
121
|
-
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
122
|
+
this.infoLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`] });
|
|
122
123
|
const options = {
|
|
123
124
|
hostname: HostDomain,
|
|
124
125
|
port: 443,
|
|
@@ -141,20 +142,24 @@ export class WaterHeater {
|
|
|
141
142
|
});
|
|
142
143
|
});
|
|
143
144
|
req.on('error', (e: any) => {
|
|
144
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
145
|
+
this.errorLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} error message: ${e.message}`] });
|
|
145
146
|
});
|
|
146
147
|
req.write(body);
|
|
147
148
|
req.end();
|
|
148
149
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
|
|
149
150
|
this.updateHomeKitCharacteristics();
|
|
150
151
|
} catch (e: any) {
|
|
151
|
-
this.apiError(e);
|
|
152
|
-
this.errorLog(
|
|
153
|
-
|
|
152
|
+
this.apiError({ e });
|
|
153
|
+
this.errorLog({
|
|
154
|
+
log: [`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
|
|
155
|
+
+ ` Error Message: ${superStringify(e.message)}`],
|
|
156
|
+
});
|
|
154
157
|
}
|
|
155
158
|
} else {
|
|
156
|
-
this.warnLog(
|
|
157
|
-
|
|
159
|
+
this.warnLog({
|
|
160
|
+
log: [`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
161
|
+
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`],
|
|
162
|
+
});
|
|
158
163
|
}
|
|
159
164
|
}
|
|
160
165
|
|
|
@@ -201,24 +206,26 @@ export class WaterHeater {
|
|
|
201
206
|
async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
|
|
202
207
|
switch (res.statusCode) {
|
|
203
208
|
case 151:
|
|
204
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
209
|
+
this.errorLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`] });
|
|
205
210
|
break;
|
|
206
211
|
case 152:
|
|
207
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found.`);
|
|
212
|
+
this.errorLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} Device not found.`] });
|
|
208
213
|
break;
|
|
209
214
|
case 160:
|
|
210
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported.`);
|
|
215
|
+
this.errorLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported.`] });
|
|
211
216
|
break;
|
|
212
217
|
case 161:
|
|
213
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline.`);
|
|
218
|
+
this.errorLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} Device is offline.`] });
|
|
214
219
|
break;
|
|
215
220
|
case 171:
|
|
216
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
221
|
+
this.errorLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`] });
|
|
217
222
|
break;
|
|
218
223
|
case 190:
|
|
219
224
|
this.errorLog(
|
|
220
|
-
|
|
221
|
-
|
|
225
|
+
{
|
|
226
|
+
log: [`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
|
|
227
|
+
` with server, Or command: ${superStringify(res)} format is invalid`],
|
|
228
|
+
},
|
|
222
229
|
);
|
|
223
230
|
break;
|
|
224
231
|
case 100:
|
|
@@ -229,27 +236,27 @@ export class WaterHeater {
|
|
|
229
236
|
}
|
|
230
237
|
}
|
|
231
238
|
|
|
232
|
-
async apiError(e: any): Promise<void> {
|
|
239
|
+
async apiError({ e }: { e: any; }): Promise<void> {
|
|
233
240
|
this.valveService.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
234
241
|
}
|
|
235
242
|
|
|
236
|
-
FirmwareRevision(accessory: PlatformAccessory
|
|
243
|
+
FirmwareRevision({ accessory, device }: { accessory: PlatformAccessory; device: irdevice & irDevicesConfig; }): string {
|
|
237
244
|
let FirmwareRevision: string;
|
|
238
245
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
239
246
|
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
240
247
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
241
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}
|
|
248
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} version: ${version}`);
|
|
242
249
|
if (accessory.context.FirmwareRevision) {
|
|
243
250
|
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
244
251
|
} else if (device.firmware) {
|
|
245
252
|
FirmwareRevision = device.firmware;
|
|
246
253
|
} else {
|
|
247
|
-
FirmwareRevision =
|
|
254
|
+
FirmwareRevision = version!;
|
|
248
255
|
}
|
|
249
256
|
return FirmwareRevision;
|
|
250
257
|
}
|
|
251
258
|
|
|
252
|
-
async context() {
|
|
259
|
+
async context(): Promise<void> {
|
|
253
260
|
if (this.Active === undefined) {
|
|
254
261
|
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
255
262
|
} else {
|
|
@@ -257,7 +264,7 @@ export class WaterHeater {
|
|
|
257
264
|
}
|
|
258
265
|
}
|
|
259
266
|
|
|
260
|
-
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
267
|
+
async config({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
|
|
261
268
|
let config = {};
|
|
262
269
|
if (device.irwh) {
|
|
263
270
|
config = device.irwh;
|
|
@@ -272,11 +279,11 @@ export class WaterHeater {
|
|
|
272
279
|
config['external'] = device.external;
|
|
273
280
|
}
|
|
274
281
|
if (Object.entries(config).length !== 0) {
|
|
275
|
-
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
282
|
+
this.infoLog({ log: [`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`] });
|
|
276
283
|
}
|
|
277
284
|
}
|
|
278
285
|
|
|
279
|
-
async logs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
286
|
+
async logs({ device }: { device: irdevice & irDevicesConfig; }): Promise<void> {
|
|
280
287
|
if (this.platform.debugMode) {
|
|
281
288
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
282
289
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -295,19 +302,19 @@ export class WaterHeater {
|
|
|
295
302
|
/**
|
|
296
303
|
* Logging for Device
|
|
297
304
|
*/
|
|
298
|
-
infoLog(
|
|
305
|
+
infoLog({ log = [] }: { log?: any[]; } = {}): void {
|
|
299
306
|
if (this.enablingDeviceLogging()) {
|
|
300
307
|
this.platform.log.info(String(...log));
|
|
301
308
|
}
|
|
302
309
|
}
|
|
303
310
|
|
|
304
|
-
warnLog(
|
|
311
|
+
warnLog({ log = [] }: { log?: any[]; } = {}): void {
|
|
305
312
|
if (this.enablingDeviceLogging()) {
|
|
306
313
|
this.platform.log.warn(String(...log));
|
|
307
314
|
}
|
|
308
315
|
}
|
|
309
316
|
|
|
310
|
-
debugWarnLog(
|
|
317
|
+
debugWarnLog({ log = [] }: { log?: any[]; } = {}): void {
|
|
311
318
|
if (this.enablingDeviceLogging()) {
|
|
312
319
|
if (this.deviceLogging?.includes('debug')) {
|
|
313
320
|
this.platform.log.warn('[DEBUG]', String(...log));
|
|
@@ -315,13 +322,13 @@ export class WaterHeater {
|
|
|
315
322
|
}
|
|
316
323
|
}
|
|
317
324
|
|
|
318
|
-
errorLog(
|
|
325
|
+
errorLog({ log = [] }: { log?: any[]; } = {}): void {
|
|
319
326
|
if (this.enablingDeviceLogging()) {
|
|
320
327
|
this.platform.log.error(String(...log));
|
|
321
328
|
}
|
|
322
329
|
}
|
|
323
330
|
|
|
324
|
-
debugErrorLog(
|
|
331
|
+
debugErrorLog({ log = [] }: { log?: any[]; } = {}): void {
|
|
325
332
|
if (this.enablingDeviceLogging()) {
|
|
326
333
|
if (this.deviceLogging?.includes('debug')) {
|
|
327
334
|
this.platform.log.error('[DEBUG]', String(...log));
|
package/src/platform.ts
CHANGED
|
@@ -41,7 +41,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
41
41
|
// this is used to track restored cached accessories
|
|
42
42
|
public readonly accessories: PlatformAccessory[] = [];
|
|
43
43
|
|
|
44
|
-
version =
|
|
44
|
+
version = process.env.npm_package_version!;
|
|
45
45
|
debugMode!: boolean;
|
|
46
46
|
platformLogging?: string;
|
|
47
47
|
|