@switchbot/homebridge-switchbot 2.0.0-beta.3 → 2.0.0-beta.30
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 +10 -1
- package/README.md +1 -2
- package/config.schema.json +102 -20
- package/dist/device/bot.d.ts +34 -28
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +655 -649
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +36 -19
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +483 -309
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +18 -8
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +303 -237
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +23 -16
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +541 -498
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +24 -18
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +450 -369
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +27 -8
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +302 -148
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +22 -16
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +340 -262
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +24 -12
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +359 -213
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +18 -8
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +276 -216
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +27 -17
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +292 -251
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +43 -19
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +503 -262
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +9 -12
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +275 -230
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +5 -3
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +151 -104
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +11 -8
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +130 -86
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +10 -7
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +157 -109
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +11 -8
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +134 -103
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +11 -8
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +142 -98
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +12 -9
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +140 -93
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +9 -10
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +129 -89
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +8 -9
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +129 -89
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -12
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +479 -434
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +18 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +12 -10
- package/src/device/bot.ts +654 -660
- package/src/device/colorbulb.ts +487 -344
- package/src/device/contact.ts +306 -241
- package/src/device/curtain.ts +546 -512
- package/src/device/humidifier.ts +453 -403
- package/src/device/lock.ts +311 -149
- package/src/device/meter.ts +351 -275
- package/src/device/meterplus.ts +369 -219
- package/src/device/motion.ts +282 -222
- package/src/device/plug.ts +296 -260
- package/src/device/striplight.ts +519 -289
- package/src/irdevice/airconditioner.ts +279 -241
- package/src/irdevice/airpurifier.ts +148 -103
- package/src/irdevice/camera.ts +128 -85
- package/src/irdevice/fan.ts +154 -106
- package/src/irdevice/light.ts +132 -103
- package/src/irdevice/other.ts +140 -97
- package/src/irdevice/tv.ts +139 -93
- package/src/irdevice/vacuumcleaner.ts +128 -89
- package/src/irdevice/waterheater.ts +127 -89
- package/src/platform.ts +469 -456
- package/src/settings.ts +18 -11
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import https from 'https';
|
|
2
2
|
import crypto from 'crypto';
|
|
3
3
|
import { IncomingMessage } from 'http';
|
|
4
|
+
import superStringify from 'super-stringify';
|
|
4
5
|
import { SwitchBotPlatform } from '../platform';
|
|
5
6
|
import { irDevicesConfig, irdevice, HostDomain, DevicePath } from '../settings';
|
|
6
7
|
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
@@ -17,13 +18,11 @@ export class AirPurifier {
|
|
|
17
18
|
// Characteristic Values
|
|
18
19
|
Active!: CharacteristicValue;
|
|
19
20
|
APActive!: CharacteristicValue;
|
|
20
|
-
ActiveCached!: CharacteristicValue;
|
|
21
21
|
CurrentAPTemp!: CharacteristicValue;
|
|
22
22
|
CurrentAPMode!: CharacteristicValue;
|
|
23
23
|
RotationSpeed!: CharacteristicValue;
|
|
24
24
|
CurrentAPFanSpeed!: CharacteristicValue;
|
|
25
25
|
CurrentTemperature!: CharacteristicValue;
|
|
26
|
-
CurrentTemperatureCached!: CharacteristicValue;
|
|
27
26
|
CurrentAirPurifierState!: CharacteristicValue;
|
|
28
27
|
CurrentHeaterCoolerState!: CharacteristicValue;
|
|
29
28
|
|
|
@@ -44,23 +43,17 @@ export class AirPurifier {
|
|
|
44
43
|
// default placeholders
|
|
45
44
|
this.logs(device);
|
|
46
45
|
this.config(device);
|
|
47
|
-
|
|
48
|
-
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
49
|
-
} else {
|
|
50
|
-
this.Active = this.accessory.context.Active;
|
|
51
|
-
}
|
|
52
|
-
if (this.CurrentTemperature === undefined) {
|
|
53
|
-
this.CurrentTemperature = 24;
|
|
54
|
-
} else {
|
|
55
|
-
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
56
|
-
}
|
|
46
|
+
this.context();
|
|
57
47
|
|
|
58
48
|
// set accessory information
|
|
59
49
|
accessory
|
|
60
50
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
61
51
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
62
52
|
.setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
|
|
63
|
-
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
53
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
54
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
55
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
56
|
+
.updateValue(this.FirmwareRevision(accessory, device));
|
|
64
57
|
|
|
65
58
|
// get the Television service if it exists, otherwise create a new Television service
|
|
66
59
|
// you can create multiple services for each accessory
|
|
@@ -86,38 +79,14 @@ export class AirPurifier {
|
|
|
86
79
|
}
|
|
87
80
|
|
|
88
81
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
89
|
-
this.debugLog(
|
|
82
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
|
|
83
|
+
this.Active = value;
|
|
84
|
+
this.accessory.context.Active = this.Active;
|
|
90
85
|
if (value === this.platform.Characteristic.Active.INACTIVE) {
|
|
91
86
|
this.pushAirPurifierOffChanges();
|
|
92
87
|
} else {
|
|
93
88
|
this.pushAirPurifierOnChanges();
|
|
94
89
|
}
|
|
95
|
-
this.Active = value;
|
|
96
|
-
this.ActiveCached = this.Active;
|
|
97
|
-
this.accessory.context.Active = this.ActiveCached;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async updateHomeKitCharacteristics(): Promise<void> {
|
|
101
|
-
if (this.Active === undefined) {
|
|
102
|
-
this.debugLog(`Air Purifier: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
103
|
-
} else {
|
|
104
|
-
this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
105
|
-
this.debugLog(`Air Purifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
106
|
-
}
|
|
107
|
-
if (this.CurrentAirPurifierState === undefined) {
|
|
108
|
-
this.debugLog(`Air Purifier: ${this.accessory.displayName} CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
|
|
109
|
-
} else {
|
|
110
|
-
this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, this.CurrentAirPurifierState);
|
|
111
|
-
this.debugLog(`Air Purifier: ${this.accessory.displayName}` + ` updateCharacteristic CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
|
|
112
|
-
}
|
|
113
|
-
if (this.CurrentHeaterCoolerState === undefined) {
|
|
114
|
-
this.debugLog(`Air Purifier: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
115
|
-
} else {
|
|
116
|
-
this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
|
|
117
|
-
this.debugLog(
|
|
118
|
-
`Air Purifier: ${this.accessory.displayName}` + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
90
|
}
|
|
122
91
|
|
|
123
92
|
async TargetAirPurifierStateSet(value: CharacteristicValue): Promise<void> {
|
|
@@ -158,7 +127,7 @@ export class AirPurifier {
|
|
|
158
127
|
*/
|
|
159
128
|
async pushAirPurifierOnChanges(): Promise<void> {
|
|
160
129
|
if (this.Active !== 1) {
|
|
161
|
-
const body =
|
|
130
|
+
const body = superStringify({
|
|
162
131
|
'command': 'turnOn',
|
|
163
132
|
'parameter': 'default',
|
|
164
133
|
'commandType': 'command',
|
|
@@ -169,7 +138,7 @@ export class AirPurifier {
|
|
|
169
138
|
|
|
170
139
|
async pushAirPurifierOffChanges(): Promise<void> {
|
|
171
140
|
if (this.Active !== 0) {
|
|
172
|
-
const body =
|
|
141
|
+
const body = superStringify({
|
|
173
142
|
'command': 'turnOff',
|
|
174
143
|
'parameter': 'default',
|
|
175
144
|
'commandType': 'command',
|
|
@@ -195,7 +164,7 @@ export class AirPurifier {
|
|
|
195
164
|
this.CurrentAPFanSpeed = this.CurrentFanSpeed || 1;
|
|
196
165
|
this.APActive = this.Active === 1 ? 'on' : 'off';
|
|
197
166
|
const parameter = `${this.CurrentAPTemp},${this.CurrentAPMode},${this.CurrentAPFanSpeed},${this.APActive}`;
|
|
198
|
-
const body =
|
|
167
|
+
const body = superStringify({
|
|
199
168
|
'command': 'setAll',
|
|
200
169
|
'parameter': `${parameter}`,
|
|
201
170
|
'commandType': 'command',
|
|
@@ -213,86 +182,115 @@ export class AirPurifier {
|
|
|
213
182
|
}
|
|
214
183
|
|
|
215
184
|
async pushChanges(body): Promise<void> {
|
|
216
|
-
|
|
185
|
+
if (this.device.connectionType === 'OpenAPI') {
|
|
186
|
+
try {
|
|
217
187
|
// Make Push On request to the API
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
188
|
+
const t = Date.now();
|
|
189
|
+
const nonce = 'requestID';
|
|
190
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
191
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
192
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
193
|
+
.digest();
|
|
194
|
+
const sign = signTerm.toString('base64');
|
|
195
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
196
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
197
|
+
const options = {
|
|
198
|
+
hostname: HostDomain,
|
|
199
|
+
port: 443,
|
|
200
|
+
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
201
|
+
method: 'POST',
|
|
202
|
+
headers: {
|
|
203
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
204
|
+
'sign': sign,
|
|
205
|
+
'nonce': nonce,
|
|
206
|
+
't': t,
|
|
207
|
+
'Content-Type': 'application/json',
|
|
208
|
+
'Content-Length': body.length,
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
const req = https.request(options, res => {
|
|
212
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
213
|
+
this.statusCode({ res });
|
|
214
|
+
res.on('data', d => {
|
|
215
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
|
|
216
|
+
});
|
|
246
217
|
});
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
if (this.deviceLogging.includes('debug')) {
|
|
260
|
-
this.errorLog(
|
|
261
|
-
`Air Purifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
218
|
+
req.on('error', (e: any) => {
|
|
219
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
220
|
+
});
|
|
221
|
+
req.write(body);
|
|
222
|
+
req.end();
|
|
223
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
|
|
224
|
+
this.updateHomeKitCharacteristics();
|
|
225
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
226
|
+
} catch (e: any) {
|
|
227
|
+
this.apiError(e);
|
|
228
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
|
|
229
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
262
230
|
);
|
|
263
231
|
}
|
|
264
|
-
|
|
232
|
+
} else {
|
|
233
|
+
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
234
|
+
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
239
|
+
if (this.Active === undefined) {
|
|
240
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
241
|
+
} else {
|
|
242
|
+
this.accessory.context.Active = this.Active;
|
|
243
|
+
this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
244
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
245
|
+
}
|
|
246
|
+
if (this.CurrentAirPurifierState === undefined) {
|
|
247
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
|
|
248
|
+
} else {
|
|
249
|
+
this.accessory.context.CurrentAirPurifierState = this.CurrentAirPurifierState;
|
|
250
|
+
this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, this.CurrentAirPurifierState);
|
|
251
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
252
|
+
+ ` updateCharacteristic CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
|
|
253
|
+
}
|
|
254
|
+
if (this.CurrentHeaterCoolerState === undefined) {
|
|
255
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
256
|
+
} else {
|
|
257
|
+
this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
|
|
258
|
+
this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
|
|
259
|
+
this.debugLog(
|
|
260
|
+
`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
261
|
+
+ ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
|
|
262
|
+
);
|
|
265
263
|
}
|
|
266
264
|
}
|
|
267
265
|
|
|
268
266
|
async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
|
|
269
267
|
switch (res.statusCode) {
|
|
270
268
|
case 151:
|
|
271
|
-
this.errorLog(
|
|
269
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
272
270
|
break;
|
|
273
271
|
case 152:
|
|
274
|
-
this.errorLog(
|
|
272
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found.`);
|
|
275
273
|
break;
|
|
276
274
|
case 160:
|
|
277
|
-
this.errorLog(
|
|
275
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported.`);
|
|
278
276
|
break;
|
|
279
277
|
case 161:
|
|
280
|
-
this.errorLog(
|
|
278
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline.`);
|
|
281
279
|
break;
|
|
282
280
|
case 171:
|
|
283
|
-
this.errorLog(
|
|
281
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
284
282
|
break;
|
|
285
283
|
case 190:
|
|
286
284
|
this.errorLog(
|
|
287
|
-
|
|
288
|
-
` with server, Or command: ${
|
|
285
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
|
|
286
|
+
` with server, Or command: ${superStringify(res)} format is invalid`,
|
|
289
287
|
);
|
|
290
288
|
break;
|
|
291
289
|
case 100:
|
|
292
|
-
this.debugLog(
|
|
290
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
293
291
|
break;
|
|
294
292
|
default:
|
|
295
|
-
this.debugLog(
|
|
293
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
296
294
|
}
|
|
297
295
|
}
|
|
298
296
|
|
|
@@ -301,7 +299,35 @@ export class AirPurifier {
|
|
|
301
299
|
this.airPurifierService.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, e);
|
|
302
300
|
this.airPurifierService.updateCharacteristic(this.platform.Characteristic.TargetAirPurifierState, e);
|
|
303
301
|
this.airPurifierService.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
304
|
-
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
|
|
305
|
+
let FirmwareRevision: string;
|
|
306
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
307
|
+
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
308
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
309
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
310
|
+
if (accessory.context.FirmwareRevision) {
|
|
311
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
312
|
+
} else if (device.firmware) {
|
|
313
|
+
FirmwareRevision = device.firmware;
|
|
314
|
+
} else {
|
|
315
|
+
FirmwareRevision = this.platform.version;
|
|
316
|
+
}
|
|
317
|
+
return FirmwareRevision;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
private context() {
|
|
321
|
+
if (this.Active === undefined) {
|
|
322
|
+
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
323
|
+
} else {
|
|
324
|
+
this.Active = this.accessory.context.Active;
|
|
325
|
+
}
|
|
326
|
+
if (this.CurrentTemperature === undefined) {
|
|
327
|
+
this.CurrentTemperature = 24;
|
|
328
|
+
} else {
|
|
329
|
+
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
330
|
+
}
|
|
305
331
|
}
|
|
306
332
|
|
|
307
333
|
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
@@ -312,24 +338,27 @@ export class AirPurifier {
|
|
|
312
338
|
if (device.logging !== undefined) {
|
|
313
339
|
config['logging'] = device.logging;
|
|
314
340
|
}
|
|
341
|
+
if (device.connectionType !== undefined) {
|
|
342
|
+
config['connectionType'] = device.connectionType;
|
|
343
|
+
}
|
|
315
344
|
if (Object.entries(config).length !== 0) {
|
|
316
|
-
this.infoLog(
|
|
345
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
317
346
|
}
|
|
318
347
|
}
|
|
319
348
|
|
|
320
349
|
async logs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
321
350
|
if (this.platform.debugMode) {
|
|
322
351
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
323
|
-
this.debugLog(
|
|
352
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
324
353
|
} else if (device.logging) {
|
|
325
354
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
326
|
-
this.debugLog(
|
|
355
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
327
356
|
} else if (this.platform.config.options?.logging) {
|
|
328
357
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
329
|
-
this.debugLog(
|
|
358
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
330
359
|
} else {
|
|
331
360
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
332
|
-
this.debugLog(
|
|
361
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
333
362
|
}
|
|
334
363
|
}
|
|
335
364
|
|
|
@@ -348,12 +377,28 @@ export class AirPurifier {
|
|
|
348
377
|
}
|
|
349
378
|
}
|
|
350
379
|
|
|
380
|
+
debugWarnLog(...log: any[]): void {
|
|
381
|
+
if (this.enablingDeviceLogging()) {
|
|
382
|
+
if (this.deviceLogging?.includes('debug')) {
|
|
383
|
+
this.platform.log.warn('[DEBUG]', String(...log));
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
351
388
|
errorLog(...log: any[]): void {
|
|
352
389
|
if (this.enablingDeviceLogging()) {
|
|
353
390
|
this.platform.log.error(String(...log));
|
|
354
391
|
}
|
|
355
392
|
}
|
|
356
393
|
|
|
394
|
+
debugErrorLog(...log: any[]): void {
|
|
395
|
+
if (this.enablingDeviceLogging()) {
|
|
396
|
+
if (this.deviceLogging?.includes('debug')) {
|
|
397
|
+
this.platform.log.error('[DEBUG]', String(...log));
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
357
402
|
debugLog(...log: any[]): void {
|
|
358
403
|
if (this.enablingDeviceLogging()) {
|
|
359
404
|
if (this.deviceLogging === 'debug') {
|