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