@switchbot/homebridge-switchbot 1.8.2 → 1.8.3-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/.eslintrc +1 -1
- package/.vscode/extensions.json +5 -0
- package/.vscode/settings.json +15 -0
- package/dist/devices/bots.d.ts +34 -35
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +241 -184
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +50 -50
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +145 -131
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +27 -29
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +138 -115
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +29 -31
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +211 -176
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +33 -33
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +214 -189
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +30 -31
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +124 -100
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +25 -26
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +120 -102
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +23 -23
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +81 -63
- package/dist/devices/plugs.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -3
- package/dist/index.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +6 -6
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +105 -79
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +5 -5
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +56 -42
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +5 -5
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +31 -27
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +5 -5
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +45 -38
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +5 -5
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +37 -33
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +5 -5
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +34 -29
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +5 -5
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +91 -76
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +5 -5
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +31 -27
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +5 -5
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +31 -27
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +12 -12
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +241 -172
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +4 -4
- package/dist/settings.js.map +1 -1
- package/package.json +72 -71
- package/src/devices/bots.ts +927 -442
- package/src/devices/colorbulb.ts +473 -246
- package/src/devices/contact.ts +381 -208
- package/src/devices/curtains.ts +613 -321
- package/src/devices/humidifiers.ts +594 -323
- package/src/devices/meters.ts +331 -186
- package/src/devices/motion.ts +327 -184
- package/src/devices/plugs.ts +175 -107
- package/src/index.ts +5 -5
- package/src/irdevices/airconditioners.ts +360 -149
- package/src/irdevices/airpurifiers.ts +178 -80
- package/src/irdevices/cameras.ts +109 -51
- package/src/irdevices/fans.ts +174 -77
- package/src/irdevices/lights.ts +110 -57
- package/src/irdevices/others.ts +137 -62
- package/src/irdevices/tvs.ts +249 -124
- package/src/irdevices/vacuumcleaners.ts +112 -52
- package/src/irdevices/waterheaters.ts +115 -53
- package/src/platform.ts +768 -357
- package/src/settings.ts +17 -23
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AxiosResponse } from
|
|
2
|
-
import { SwitchBotPlatform } from
|
|
3
|
-
import { irDevicesConfig, DeviceURL, irdevice, payload } from
|
|
4
|
-
import { CharacteristicValue, PlatformAccessory, Service } from
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
import { SwitchBotPlatform } from "../platform";
|
|
3
|
+
import { irDevicesConfig, DeviceURL, irdevice, payload } from "../settings";
|
|
4
|
+
import { CharacteristicValue, PlatformAccessory, Service } from "homebridge";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -60,15 +60,19 @@ export class AirPurifier {
|
|
|
60
60
|
// set accessory information
|
|
61
61
|
accessory
|
|
62
62
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
63
|
-
.setCharacteristic(this.platform.Characteristic.Manufacturer,
|
|
63
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
|
|
64
64
|
.setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
|
|
65
|
-
.setCharacteristic(
|
|
65
|
+
.setCharacteristic(
|
|
66
|
+
this.platform.Characteristic.SerialNumber,
|
|
67
|
+
device.deviceId!,
|
|
68
|
+
);
|
|
66
69
|
|
|
67
70
|
// get the Television service if it exists, otherwise create a new Television service
|
|
68
71
|
// you can create multiple services for each accessory
|
|
69
72
|
(this.service =
|
|
70
73
|
accessory.getService(this.platform.Service.AirPurifier) ||
|
|
71
|
-
accessory.addService(this.platform.Service.AirPurifier)),
|
|
74
|
+
accessory.addService(this.platform.Service.AirPurifier)),
|
|
75
|
+
`${accessory.displayName} Air Purifier`;
|
|
72
76
|
|
|
73
77
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
74
78
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
@@ -76,20 +80,31 @@ export class AirPurifier {
|
|
|
76
80
|
|
|
77
81
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
78
82
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
79
|
-
this.service.setCharacteristic(
|
|
83
|
+
this.service.setCharacteristic(
|
|
84
|
+
this.platform.Characteristic.Name,
|
|
85
|
+
accessory.displayName,
|
|
86
|
+
);
|
|
80
87
|
|
|
81
88
|
// handle on / off events using the Active characteristic
|
|
82
|
-
this.service
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
+
this.service
|
|
90
|
+
.getCharacteristic(this.platform.Characteristic.Active)
|
|
91
|
+
.onSet(this.ActiveSet.bind(this));
|
|
92
|
+
|
|
93
|
+
this.service
|
|
94
|
+
.getCharacteristic(this.platform.Characteristic.CurrentAirPurifierState)
|
|
95
|
+
.onGet(() => {
|
|
96
|
+
return this.CurrentAirPurifierStateGet();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
this.service
|
|
100
|
+
.getCharacteristic(this.platform.Characteristic.TargetAirPurifierState)
|
|
101
|
+
.onSet(this.TargetAirPurifierStateSet.bind(this));
|
|
89
102
|
}
|
|
90
103
|
|
|
91
104
|
private ActiveSet(value: CharacteristicValue) {
|
|
92
|
-
this.debugLog(
|
|
105
|
+
this.debugLog(
|
|
106
|
+
`Air Purifier: ${this.accessory.displayName} Set Active: ${value}`,
|
|
107
|
+
);
|
|
93
108
|
if (value === this.platform.Characteristic.Active.INACTIVE) {
|
|
94
109
|
this.pushAirPurifierOffChanges();
|
|
95
110
|
} else {
|
|
@@ -102,24 +117,45 @@ export class AirPurifier {
|
|
|
102
117
|
|
|
103
118
|
private updateHomeKitCharacteristics() {
|
|
104
119
|
if (this.Active === undefined) {
|
|
105
|
-
this.debugLog(
|
|
120
|
+
this.debugLog(
|
|
121
|
+
`Air Purifier: ${this.accessory.displayName} Active: ${this.Active}`,
|
|
122
|
+
);
|
|
106
123
|
} else {
|
|
107
|
-
this.service?.updateCharacteristic(
|
|
108
|
-
|
|
124
|
+
this.service?.updateCharacteristic(
|
|
125
|
+
this.platform.Characteristic.Active,
|
|
126
|
+
this.Active,
|
|
127
|
+
);
|
|
128
|
+
this.debugLog(
|
|
129
|
+
`Air Purifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`,
|
|
130
|
+
);
|
|
109
131
|
}
|
|
110
132
|
if (this.CurrentAirPurifierState === undefined) {
|
|
111
|
-
this.debugLog(
|
|
133
|
+
this.debugLog(
|
|
134
|
+
`Air Purifier: ${this.accessory.displayName} CurrentAirPurifierState: ${this.CurrentAirPurifierState}`,
|
|
135
|
+
);
|
|
112
136
|
} else {
|
|
113
|
-
this.service?.updateCharacteristic(
|
|
114
|
-
|
|
115
|
-
|
|
137
|
+
this.service?.updateCharacteristic(
|
|
138
|
+
this.platform.Characteristic.CurrentAirPurifierState,
|
|
139
|
+
this.CurrentAirPurifierState,
|
|
140
|
+
);
|
|
141
|
+
this.debugLog(
|
|
142
|
+
`Air Purifier: ${this.accessory.displayName}` +
|
|
143
|
+
` updateCharacteristic CurrentAirPurifierState: ${this.CurrentAirPurifierState}`,
|
|
144
|
+
);
|
|
116
145
|
}
|
|
117
146
|
if (this.CurrentHeaterCoolerState === undefined) {
|
|
118
|
-
this.debugLog(
|
|
147
|
+
this.debugLog(
|
|
148
|
+
`Air Purifier: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
|
|
149
|
+
);
|
|
119
150
|
} else {
|
|
120
|
-
this.service?.updateCharacteristic(
|
|
121
|
-
|
|
122
|
-
|
|
151
|
+
this.service?.updateCharacteristic(
|
|
152
|
+
this.platform.Characteristic.CurrentHeaterCoolerState,
|
|
153
|
+
this.CurrentHeaterCoolerState,
|
|
154
|
+
);
|
|
155
|
+
this.debugLog(
|
|
156
|
+
`Air Purifier: ${this.accessory.displayName}` +
|
|
157
|
+
` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
|
|
158
|
+
);
|
|
123
159
|
}
|
|
124
160
|
}
|
|
125
161
|
|
|
@@ -141,9 +177,11 @@ export class AirPurifier {
|
|
|
141
177
|
|
|
142
178
|
private CurrentAirPurifierStateGet() {
|
|
143
179
|
if (this.Active === 1) {
|
|
144
|
-
this.CurrentAirPurifierState =
|
|
180
|
+
this.CurrentAirPurifierState =
|
|
181
|
+
this.platform.Characteristic.CurrentAirPurifierState.PURIFYING_AIR;
|
|
145
182
|
} else {
|
|
146
|
-
this.CurrentAirPurifierState =
|
|
183
|
+
this.CurrentAirPurifierState =
|
|
184
|
+
this.platform.Characteristic.CurrentAirPurifierState.INACTIVE;
|
|
147
185
|
}
|
|
148
186
|
return this.CurrentAirPurifierState;
|
|
149
187
|
}
|
|
@@ -162,9 +200,9 @@ export class AirPurifier {
|
|
|
162
200
|
async pushAirPurifierOnChanges() {
|
|
163
201
|
if (this.Active !== 1) {
|
|
164
202
|
const payload = {
|
|
165
|
-
commandType:
|
|
166
|
-
parameter:
|
|
167
|
-
command:
|
|
203
|
+
commandType: "command",
|
|
204
|
+
parameter: "default",
|
|
205
|
+
command: "turnOn",
|
|
168
206
|
} as payload;
|
|
169
207
|
await this.pushChanges(payload);
|
|
170
208
|
}
|
|
@@ -173,9 +211,9 @@ export class AirPurifier {
|
|
|
173
211
|
async pushAirPurifierOffChanges() {
|
|
174
212
|
if (this.Active !== 0) {
|
|
175
213
|
const payload = {
|
|
176
|
-
commandType:
|
|
177
|
-
parameter:
|
|
178
|
-
command:
|
|
214
|
+
commandType: "command",
|
|
215
|
+
parameter: "default",
|
|
216
|
+
command: "turnOff",
|
|
179
217
|
} as payload;
|
|
180
218
|
await this.pushChanges(payload);
|
|
181
219
|
}
|
|
@@ -184,34 +222,41 @@ export class AirPurifier {
|
|
|
184
222
|
async pushAirConditionerStatusChanges() {
|
|
185
223
|
if (!this.Busy) {
|
|
186
224
|
this.Busy = true;
|
|
187
|
-
this.CurrentHeaterCoolerState =
|
|
225
|
+
this.CurrentHeaterCoolerState =
|
|
226
|
+
this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
|
|
188
227
|
}
|
|
189
228
|
clearTimeout(this.Timeout);
|
|
190
229
|
|
|
191
230
|
// Make a new Timeout set to go off in 1000ms (1 second)
|
|
192
|
-
this.Timeout = setTimeout(
|
|
231
|
+
this.Timeout = setTimeout(
|
|
232
|
+
this.pushAirConditionerDetailsChanges.bind(this),
|
|
233
|
+
1500,
|
|
234
|
+
);
|
|
193
235
|
}
|
|
194
236
|
|
|
195
237
|
async pushAirConditionerDetailsChanges() {
|
|
196
238
|
const payload = {
|
|
197
|
-
commandType:
|
|
198
|
-
command:
|
|
239
|
+
commandType: "command",
|
|
240
|
+
command: "setAll",
|
|
199
241
|
} as payload;
|
|
200
242
|
|
|
201
243
|
this.CurrentAPTemp = this.CurrentTemperature || 24;
|
|
202
244
|
this.CurrentAPMode = this.CurrentMode || 1;
|
|
203
245
|
this.CurrentAPFanSpeed = this.CurrentFanSpeed || 1;
|
|
204
|
-
this.APActive = this.Active === 1 ?
|
|
246
|
+
this.APActive = this.Active === 1 ? "on" : "off";
|
|
205
247
|
payload.parameter = `${this.CurrentAPTemp},${this.CurrentAPMode},${this.CurrentAPFanSpeed},${this.APActive}`;
|
|
206
248
|
|
|
207
249
|
if (this.Active === 1) {
|
|
208
250
|
if ((this.CurrentTemperature || 24) < (this.LastTemperature || 30)) {
|
|
209
|
-
this.CurrentHeaterCoolerState =
|
|
251
|
+
this.CurrentHeaterCoolerState =
|
|
252
|
+
this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
|
|
210
253
|
} else {
|
|
211
|
-
this.CurrentHeaterCoolerState =
|
|
254
|
+
this.CurrentHeaterCoolerState =
|
|
255
|
+
this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
|
|
212
256
|
}
|
|
213
257
|
} else {
|
|
214
|
-
this.CurrentHeaterCoolerState =
|
|
258
|
+
this.CurrentHeaterCoolerState =
|
|
259
|
+
this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
|
|
215
260
|
}
|
|
216
261
|
|
|
217
262
|
await this.pushChanges(payload);
|
|
@@ -219,63 +264,103 @@ export class AirPurifier {
|
|
|
219
264
|
|
|
220
265
|
public async pushChanges(payload: payload) {
|
|
221
266
|
try {
|
|
222
|
-
this.infoLog(
|
|
223
|
-
|
|
267
|
+
this.infoLog(
|
|
268
|
+
`Air Purifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
269
|
+
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
270
|
+
);
|
|
224
271
|
|
|
225
272
|
// Make the API request
|
|
226
|
-
const push = await this.platform.axios.post(
|
|
227
|
-
|
|
273
|
+
const push = await this.platform.axios.post(
|
|
274
|
+
`${DeviceURL}/${this.device.deviceId}/commands`,
|
|
275
|
+
payload,
|
|
276
|
+
);
|
|
277
|
+
this.debugLog(
|
|
278
|
+
`Air Purifier: ${this.accessory.displayName} pushChanges: ${push.data}`,
|
|
279
|
+
);
|
|
228
280
|
this.statusCode(push);
|
|
229
281
|
this.updateHomeKitCharacteristics();
|
|
230
282
|
this.CurrentTemperatureCached = this.CurrentTemperature;
|
|
231
283
|
this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
|
|
232
284
|
} catch (e: any) {
|
|
233
|
-
this.errorLog(
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
285
|
+
this.errorLog(
|
|
286
|
+
`Air Purifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
|
|
287
|
+
);
|
|
288
|
+
if (this.deviceLogging === "debug") {
|
|
289
|
+
this.errorLog(
|
|
290
|
+
`Air Purifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
291
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
292
|
+
);
|
|
237
293
|
}
|
|
238
294
|
if (this.platform.debugMode) {
|
|
239
|
-
this.errorLog(
|
|
240
|
-
|
|
295
|
+
this.errorLog(
|
|
296
|
+
`Air Purifier: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
297
|
+
` Error: ${JSON.stringify(e)}`,
|
|
298
|
+
);
|
|
241
299
|
}
|
|
242
300
|
this.apiError(e);
|
|
243
301
|
}
|
|
244
302
|
}
|
|
245
303
|
|
|
246
|
-
private statusCode(push: AxiosResponse<{ statusCode: number
|
|
304
|
+
private statusCode(push: AxiosResponse<{ statusCode: number }>) {
|
|
247
305
|
switch (push.data.statusCode) {
|
|
248
306
|
case 151:
|
|
249
|
-
this.errorLog(
|
|
307
|
+
this.errorLog(
|
|
308
|
+
`Air Purifier: ${this.accessory.displayName} Command not supported by this device type.`,
|
|
309
|
+
);
|
|
250
310
|
break;
|
|
251
311
|
case 152:
|
|
252
|
-
this.errorLog(
|
|
312
|
+
this.errorLog(
|
|
313
|
+
`Air Purifier: ${this.accessory.displayName} Device not found.`,
|
|
314
|
+
);
|
|
253
315
|
break;
|
|
254
316
|
case 160:
|
|
255
|
-
this.errorLog(
|
|
317
|
+
this.errorLog(
|
|
318
|
+
`Air Purifier: ${this.accessory.displayName} Command is not supported.`,
|
|
319
|
+
);
|
|
256
320
|
break;
|
|
257
321
|
case 161:
|
|
258
|
-
this.errorLog(
|
|
322
|
+
this.errorLog(
|
|
323
|
+
`Air Purifier: ${this.accessory.displayName} Device is offline.`,
|
|
324
|
+
);
|
|
259
325
|
break;
|
|
260
326
|
case 171:
|
|
261
|
-
this.errorLog(
|
|
327
|
+
this.errorLog(
|
|
328
|
+
`Air Purifier: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
|
|
329
|
+
);
|
|
262
330
|
break;
|
|
263
331
|
case 190:
|
|
264
|
-
this.errorLog(
|
|
265
|
-
|
|
332
|
+
this.errorLog(
|
|
333
|
+
`Air Purifier: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
|
|
334
|
+
` with server, Or command: ${JSON.stringify(
|
|
335
|
+
push.data,
|
|
336
|
+
)} format is invalid`,
|
|
337
|
+
);
|
|
266
338
|
break;
|
|
267
339
|
case 100:
|
|
268
|
-
this.debugLog(
|
|
340
|
+
this.debugLog(
|
|
341
|
+
`Air Purifier: ${this.accessory.displayName} Command successfully sent.`,
|
|
342
|
+
);
|
|
269
343
|
break;
|
|
270
344
|
default:
|
|
271
|
-
this.debugLog(
|
|
345
|
+
this.debugLog(
|
|
346
|
+
`Air Purifier: ${this.accessory.displayName} Unknown statusCode.`,
|
|
347
|
+
);
|
|
272
348
|
}
|
|
273
349
|
}
|
|
274
350
|
|
|
275
351
|
public apiError(e: any) {
|
|
276
|
-
this.service.updateCharacteristic(
|
|
277
|
-
|
|
278
|
-
|
|
352
|
+
this.service.updateCharacteristic(
|
|
353
|
+
this.platform.Characteristic.CurrentHeaterCoolerState,
|
|
354
|
+
e,
|
|
355
|
+
);
|
|
356
|
+
this.service.updateCharacteristic(
|
|
357
|
+
this.platform.Characteristic.CurrentAirPurifierState,
|
|
358
|
+
e,
|
|
359
|
+
);
|
|
360
|
+
this.service.updateCharacteristic(
|
|
361
|
+
this.platform.Characteristic.TargetAirPurifierState,
|
|
362
|
+
e,
|
|
363
|
+
);
|
|
279
364
|
this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
280
365
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
281
366
|
}
|
|
@@ -286,32 +371,45 @@ export class AirPurifier {
|
|
|
286
371
|
config = device.irpur;
|
|
287
372
|
}
|
|
288
373
|
if (device.logging !== undefined) {
|
|
289
|
-
config[
|
|
374
|
+
config["logging"] = device.logging;
|
|
290
375
|
}
|
|
291
376
|
if (Object.entries(config).length !== 0) {
|
|
292
|
-
this.warnLog(
|
|
377
|
+
this.warnLog(
|
|
378
|
+
`Air Purifier: ${this.accessory.displayName} Config: ${JSON.stringify(
|
|
379
|
+
config,
|
|
380
|
+
)}`,
|
|
381
|
+
);
|
|
293
382
|
}
|
|
294
383
|
}
|
|
295
384
|
|
|
296
385
|
logs(device: irdevice & irDevicesConfig) {
|
|
297
386
|
if (this.platform.debugMode) {
|
|
298
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
299
|
-
this.debugLog(
|
|
387
|
+
this.deviceLogging = this.accessory.context.logging = "debugMode";
|
|
388
|
+
this.debugLog(
|
|
389
|
+
`Air Purifier: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
|
|
390
|
+
);
|
|
300
391
|
} else if (device.logging) {
|
|
301
392
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
302
|
-
this.debugLog(
|
|
393
|
+
this.debugLog(
|
|
394
|
+
`Air Purifier: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
|
|
395
|
+
);
|
|
303
396
|
} else if (this.platform.config.options?.logging) {
|
|
304
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
305
|
-
|
|
397
|
+
this.deviceLogging = this.accessory.context.logging =
|
|
398
|
+
this.platform.config.options?.logging;
|
|
399
|
+
this.debugLog(
|
|
400
|
+
`Air Purifier: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
|
|
401
|
+
);
|
|
306
402
|
} else {
|
|
307
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
308
|
-
this.debugLog(
|
|
403
|
+
this.deviceLogging = this.accessory.context.logging = "standard";
|
|
404
|
+
this.debugLog(
|
|
405
|
+
`Air Purifier: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
|
|
406
|
+
);
|
|
309
407
|
}
|
|
310
408
|
}
|
|
311
409
|
|
|
312
410
|
/**
|
|
313
|
-
|
|
314
|
-
|
|
411
|
+
* Logging for Device
|
|
412
|
+
*/
|
|
315
413
|
infoLog(...log: any[]) {
|
|
316
414
|
if (this.enablingDeviceLogging()) {
|
|
317
415
|
this.platform.log.info(String(...log));
|
|
@@ -332,8 +430,8 @@ export class AirPurifier {
|
|
|
332
430
|
|
|
333
431
|
debugLog(...log: any[]) {
|
|
334
432
|
if (this.enablingDeviceLogging()) {
|
|
335
|
-
if (this.deviceLogging ===
|
|
336
|
-
this.platform.log.info(
|
|
433
|
+
if (this.deviceLogging === "debug") {
|
|
434
|
+
this.platform.log.info("[DEBUG]", String(...log));
|
|
337
435
|
} else {
|
|
338
436
|
this.platform.log.debug(String(...log));
|
|
339
437
|
}
|
|
@@ -341,6 +439,6 @@ export class AirPurifier {
|
|
|
341
439
|
}
|
|
342
440
|
|
|
343
441
|
enablingDeviceLogging(): boolean {
|
|
344
|
-
return this.deviceLogging
|
|
442
|
+
return this.deviceLogging.includes("debug") || this.deviceLogging === "standard";
|
|
345
443
|
}
|
|
346
444
|
}
|