@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
package/src/irdevices/fans.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import { AxiosResponse } from
|
|
2
|
-
import { SwitchBotPlatform } from
|
|
3
|
-
import { CharacteristicValue, PlatformAccessory, Service } from
|
|
4
|
-
import {
|
|
5
|
-
DeviceURL,
|
|
6
|
-
irdevice,
|
|
7
|
-
deviceStatusResponse,
|
|
8
|
-
irDevicesConfig,
|
|
9
|
-
payload,
|
|
10
|
-
} from "../settings";
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
import { SwitchBotPlatform } from '../platform';
|
|
3
|
+
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
4
|
+
import { DeviceURL, irdevice, deviceStatusResponse, irDevicesConfig, payload } from '../settings';
|
|
11
5
|
|
|
12
6
|
/**
|
|
13
7
|
* Platform Accessory
|
|
@@ -52,19 +46,15 @@ export class Fan {
|
|
|
52
46
|
// set accessory information
|
|
53
47
|
accessory
|
|
54
48
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
55
|
-
.setCharacteristic(this.platform.Characteristic.Manufacturer,
|
|
49
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
56
50
|
.setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
|
|
57
|
-
.setCharacteristic(
|
|
58
|
-
this.platform.Characteristic.SerialNumber,
|
|
59
|
-
device.deviceId!,
|
|
60
|
-
);
|
|
51
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
61
52
|
|
|
62
53
|
// get the Television service if it exists, otherwise create a new Television service
|
|
63
54
|
// you can create multiple services for each accessory
|
|
64
55
|
(this.service =
|
|
65
56
|
accessory.getService(this.platform.Service.Fanv2) ||
|
|
66
|
-
accessory.addService(this.platform.Service.Fanv2)),
|
|
67
|
-
`${accessory.displayName} Fan`;
|
|
57
|
+
accessory.addService(this.platform.Service.Fanv2)), `${accessory.displayName} Fan`;
|
|
68
58
|
|
|
69
59
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
70
60
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
@@ -72,15 +62,10 @@ export class Fan {
|
|
|
72
62
|
|
|
73
63
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
74
64
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
75
|
-
this.service.setCharacteristic(
|
|
76
|
-
this.platform.Characteristic.Name,
|
|
77
|
-
accessory.displayName,
|
|
78
|
-
);
|
|
65
|
+
this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
79
66
|
|
|
80
67
|
// handle on / off events using the Active characteristic
|
|
81
|
-
this.service
|
|
82
|
-
.getCharacteristic(this.platform.Characteristic.Active)
|
|
83
|
-
.onSet(this.ActiveSet.bind(this));
|
|
68
|
+
this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
84
69
|
|
|
85
70
|
if (device.irfan?.rotation_speed) {
|
|
86
71
|
if (device.irfan?.set_minStep) {
|
|
@@ -108,46 +93,27 @@ export class Fan {
|
|
|
108
93
|
})
|
|
109
94
|
.onSet(this.RotationSpeedSet.bind(this));
|
|
110
95
|
} else if (
|
|
111
|
-
this.service.testCharacteristic(
|
|
112
|
-
|
|
113
|
-
)
|
|
114
|
-
!device.irfan?.swing_mode
|
|
115
|
-
) {
|
|
116
|
-
const characteristic = this.service.getCharacteristic(
|
|
117
|
-
this.platform.Characteristic.RotationSpeed,
|
|
118
|
-
);
|
|
96
|
+
this.service.testCharacteristic(this.platform.Characteristic.RotationSpeed) &&
|
|
97
|
+
!device.irfan?.swing_mode) {
|
|
98
|
+
const characteristic = this.service.getCharacteristic(this.platform.Characteristic.RotationSpeed);
|
|
119
99
|
this.service.removeCharacteristic(characteristic);
|
|
120
|
-
this.debugLog(
|
|
121
|
-
`Fan: ${this.accessory.displayName} Rotation Speed Characteristic was removed.`,
|
|
122
|
-
);
|
|
100
|
+
this.debugLog(`Fan: ${this.accessory.displayName} Rotation Speed Characteristic was removed.`);
|
|
123
101
|
} else {
|
|
124
102
|
// eslint-disable-next-line max-len
|
|
125
|
-
this.debugLog(
|
|
126
|
-
`Fan: ${this.accessory.displayName} Rotation Speed Characteristic was not removed or not added. To Remove Chracteristic, Clear Cache on this Accessory.`,
|
|
127
|
-
);
|
|
103
|
+
this.debugLog(`Fan: ${this.accessory.displayName} Rotation Speed Characteristic was not removed or not added. To Remove Chracteristic, Clear Cache on this Accessory.`);
|
|
128
104
|
}
|
|
129
105
|
|
|
130
106
|
if (device.irfan?.swing_mode) {
|
|
131
107
|
// handle Osolcation events using the SwingMode characteristic
|
|
132
|
-
this.service
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
} else if (
|
|
136
|
-
this.service.testCharacteristic(this.platform.Characteristic.SwingMode) &&
|
|
137
|
-
!device.irfan?.swing_mode
|
|
138
|
-
) {
|
|
139
|
-
const characteristic = this.service.getCharacteristic(
|
|
140
|
-
this.platform.Characteristic.SwingMode,
|
|
141
|
-
);
|
|
108
|
+
this.service.getCharacteristic(this.platform.Characteristic.SwingMode).onSet(this.SwingModeSet.bind(this));
|
|
109
|
+
} else if (this.service.testCharacteristic(this.platform.Characteristic.SwingMode) && !device.irfan?.swing_mode) {
|
|
110
|
+
const characteristic = this.service.getCharacteristic(this.platform.Characteristic.SwingMode);
|
|
142
111
|
this.service.removeCharacteristic(characteristic);
|
|
143
|
-
this.debugLog(
|
|
144
|
-
`Fan: ${this.accessory.displayName} Swing Mode Characteristic was removed.`,
|
|
145
|
-
);
|
|
112
|
+
this.debugLog(`Fan: ${this.accessory.displayName} Swing Mode Characteristic was removed.`);
|
|
146
113
|
} else {
|
|
147
114
|
// eslint-disable-next-line max-len
|
|
148
|
-
this.debugLog(
|
|
149
|
-
|
|
150
|
-
);
|
|
115
|
+
this.debugLog(`Fan: ${this.accessory.displayName} Swing Mode Characteristic was not removed or not added. To Remove Chracteristic, Clear Cache on this Accessory.`);
|
|
116
|
+
|
|
151
117
|
}
|
|
152
118
|
}
|
|
153
119
|
|
|
@@ -167,43 +133,22 @@ export class Fan {
|
|
|
167
133
|
|
|
168
134
|
private updateHomeKitCharacteristics() {
|
|
169
135
|
if (this.Active === undefined) {
|
|
170
|
-
this.debugLog(
|
|
171
|
-
`Fan: ${this.accessory.displayName} Active: ${this.Active}`,
|
|
172
|
-
);
|
|
136
|
+
this.debugLog(`Fan: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
173
137
|
} else {
|
|
174
|
-
this.service?.updateCharacteristic(
|
|
175
|
-
|
|
176
|
-
this.Active,
|
|
177
|
-
);
|
|
178
|
-
this.debugLog(
|
|
179
|
-
`Fan: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`,
|
|
180
|
-
);
|
|
138
|
+
this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
139
|
+
this.debugLog(`Fan: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
181
140
|
}
|
|
182
141
|
if (this.SwingMode === undefined) {
|
|
183
|
-
this.debugLog(
|
|
184
|
-
`Fan: ${this.accessory.displayName} SwingMode: ${this.SwingMode}`,
|
|
185
|
-
);
|
|
142
|
+
this.debugLog(`Fan: ${this.accessory.displayName} SwingMode: ${this.SwingMode}`);
|
|
186
143
|
} else {
|
|
187
|
-
this.service?.updateCharacteristic(
|
|
188
|
-
|
|
189
|
-
this.SwingMode,
|
|
190
|
-
);
|
|
191
|
-
this.debugLog(
|
|
192
|
-
`Fan: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.SwingMode}`,
|
|
193
|
-
);
|
|
144
|
+
this.service?.updateCharacteristic(this.platform.Characteristic.SwingMode, this.SwingMode);
|
|
145
|
+
this.debugLog(`Fan: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.SwingMode}`);
|
|
194
146
|
}
|
|
195
147
|
if (this.RotationSpeed === undefined) {
|
|
196
|
-
this.debugLog(
|
|
197
|
-
`Fan: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`,
|
|
198
|
-
);
|
|
148
|
+
this.debugLog(`Fan: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
|
|
199
149
|
} else {
|
|
200
|
-
this.service?.updateCharacteristic(
|
|
201
|
-
|
|
202
|
-
this.RotationSpeed,
|
|
203
|
-
);
|
|
204
|
-
this.debugLog(
|
|
205
|
-
`Fan: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`,
|
|
206
|
-
);
|
|
150
|
+
this.service?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
|
|
151
|
+
this.debugLog(`Fan: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
|
|
207
152
|
}
|
|
208
153
|
}
|
|
209
154
|
|
|
@@ -244,9 +189,9 @@ export class Fan {
|
|
|
244
189
|
async pushFanOnChanges() {
|
|
245
190
|
if (this.Active !== 1) {
|
|
246
191
|
const payload = {
|
|
247
|
-
commandType:
|
|
248
|
-
parameter:
|
|
249
|
-
command:
|
|
192
|
+
commandType: 'command',
|
|
193
|
+
parameter: 'default',
|
|
194
|
+
command: 'turnOn',
|
|
250
195
|
} as payload;
|
|
251
196
|
await this.pushTVChanges(payload);
|
|
252
197
|
}
|
|
@@ -254,112 +199,87 @@ export class Fan {
|
|
|
254
199
|
|
|
255
200
|
async pushFanOffChanges() {
|
|
256
201
|
const payload = {
|
|
257
|
-
commandType:
|
|
258
|
-
parameter:
|
|
259
|
-
command:
|
|
202
|
+
commandType: 'command',
|
|
203
|
+
parameter: 'default',
|
|
204
|
+
command: 'turnOff',
|
|
260
205
|
} as payload;
|
|
261
206
|
await this.pushTVChanges(payload);
|
|
262
207
|
}
|
|
263
208
|
|
|
264
209
|
async pushFanSpeedUpChanges() {
|
|
265
210
|
const payload = {
|
|
266
|
-
commandType:
|
|
267
|
-
parameter:
|
|
268
|
-
command:
|
|
211
|
+
commandType: 'command',
|
|
212
|
+
parameter: 'default',
|
|
213
|
+
command: 'highSpeed',
|
|
269
214
|
} as payload;
|
|
270
215
|
await this.pushTVChanges(payload);
|
|
271
216
|
}
|
|
272
217
|
|
|
273
218
|
async pushFanSpeedDownChanges() {
|
|
274
219
|
const payload = {
|
|
275
|
-
commandType:
|
|
276
|
-
parameter:
|
|
277
|
-
command:
|
|
220
|
+
commandType: 'command',
|
|
221
|
+
parameter: 'default',
|
|
222
|
+
command: 'lowSpeed',
|
|
278
223
|
} as payload;
|
|
279
224
|
await this.pushTVChanges(payload);
|
|
280
225
|
}
|
|
281
226
|
|
|
282
227
|
async pushFanSwingChanges() {
|
|
283
228
|
const payload = {
|
|
284
|
-
commandType:
|
|
285
|
-
parameter:
|
|
286
|
-
command:
|
|
229
|
+
commandType: 'command',
|
|
230
|
+
parameter: 'default',
|
|
231
|
+
command: 'swing',
|
|
287
232
|
} as payload;
|
|
288
233
|
await this.pushTVChanges(payload);
|
|
289
234
|
}
|
|
290
235
|
|
|
291
236
|
public async pushTVChanges(payload: payload) {
|
|
292
237
|
try {
|
|
293
|
-
this.infoLog(
|
|
294
|
-
`
|
|
295
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
296
|
-
);
|
|
238
|
+
this.infoLog(`Fan: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
239
|
+
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
297
240
|
|
|
298
241
|
// Make the API request
|
|
299
|
-
const push = await this.platform.axios.post(
|
|
300
|
-
|
|
301
|
-
payload,
|
|
302
|
-
);
|
|
303
|
-
this.debugLog(
|
|
304
|
-
`Fan: ${this.accessory.displayName} pushTVChanges: ${push.data}`,
|
|
305
|
-
);
|
|
242
|
+
const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
243
|
+
this.debugLog(`Fan: ${this.accessory.displayName} pushTVChanges: ${push.data}`);
|
|
306
244
|
this.statusCode(push);
|
|
307
245
|
this.updateHomeKitCharacteristics();
|
|
308
246
|
} catch (e: any) {
|
|
309
|
-
this.errorLog(
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
this.errorLog(
|
|
314
|
-
`Fan: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
315
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
316
|
-
);
|
|
247
|
+
this.errorLog(`Fan: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
248
|
+
if (this.deviceLogging === 'debug') {
|
|
249
|
+
this.errorLog(`Fan: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
250
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
317
251
|
}
|
|
318
252
|
if (this.platform.debugMode) {
|
|
319
|
-
this.errorLog(
|
|
320
|
-
`
|
|
321
|
-
` Error: ${JSON.stringify(e)}`,
|
|
322
|
-
);
|
|
253
|
+
this.errorLog(`Fan: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
254
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
323
255
|
}
|
|
324
256
|
this.apiError(e);
|
|
325
257
|
}
|
|
326
258
|
}
|
|
327
259
|
|
|
328
|
-
private statusCode(push: AxiosResponse<{ statusCode: number }>) {
|
|
260
|
+
private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
|
|
329
261
|
switch (push.data.statusCode) {
|
|
330
262
|
case 151:
|
|
331
|
-
this.errorLog(
|
|
332
|
-
`Fan: ${this.accessory.displayName} Command not supported by this device type.`,
|
|
333
|
-
);
|
|
263
|
+
this.errorLog(`Fan: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
334
264
|
break;
|
|
335
265
|
case 152:
|
|
336
266
|
this.errorLog(`Fan: ${this.accessory.displayName} Device not found.`);
|
|
337
267
|
break;
|
|
338
268
|
case 160:
|
|
339
|
-
this.errorLog(
|
|
340
|
-
`Fan: ${this.accessory.displayName} Command is not supported.`,
|
|
341
|
-
);
|
|
269
|
+
this.errorLog(`Fan: ${this.accessory.displayName} Command is not supported.`);
|
|
342
270
|
break;
|
|
343
271
|
case 161:
|
|
344
272
|
this.errorLog(`Fan: ${this.accessory.displayName} Device is offline.`);
|
|
345
273
|
break;
|
|
346
274
|
case 171:
|
|
347
|
-
this.errorLog(
|
|
348
|
-
`Fan: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
|
|
349
|
-
);
|
|
275
|
+
this.errorLog(`Fan: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
350
276
|
break;
|
|
351
277
|
case 190:
|
|
352
|
-
this.errorLog(
|
|
353
|
-
`
|
|
354
|
-
` with server, Or command: ${JSON.stringify(
|
|
355
|
-
push.data,
|
|
356
|
-
)} format is invalid`,
|
|
357
|
-
);
|
|
278
|
+
this.errorLog(`Fan: ${this.accessory.displayName} Device internal error due to device states not synchronized`
|
|
279
|
+
+ ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
358
280
|
break;
|
|
359
281
|
case 100:
|
|
360
|
-
this.debugLog(
|
|
361
|
-
`Fan: ${this.accessory.displayName} Command successfully sent.`,
|
|
362
|
-
);
|
|
282
|
+
this.debugLog(`Fan: ${this.accessory.displayName} Command successfully sent.`);
|
|
363
283
|
break;
|
|
364
284
|
default:
|
|
365
285
|
this.debugLog(`Fan: ${this.accessory.displayName} Unknown statusCode.`);
|
|
@@ -368,14 +288,8 @@ export class Fan {
|
|
|
368
288
|
|
|
369
289
|
public apiError(e: any) {
|
|
370
290
|
this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
371
|
-
this.service.updateCharacteristic(
|
|
372
|
-
|
|
373
|
-
e,
|
|
374
|
-
);
|
|
375
|
-
this.service.updateCharacteristic(
|
|
376
|
-
this.platform.Characteristic.SwingMode,
|
|
377
|
-
e,
|
|
378
|
-
);
|
|
291
|
+
this.service.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
|
|
292
|
+
this.service.updateCharacteristic(this.platform.Characteristic.SwingMode, e);
|
|
379
293
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
380
294
|
}
|
|
381
295
|
|
|
@@ -385,43 +299,32 @@ export class Fan {
|
|
|
385
299
|
config = device.irfan;
|
|
386
300
|
}
|
|
387
301
|
if (device.logging !== undefined) {
|
|
388
|
-
config[
|
|
302
|
+
config['logging'] = device.logging;
|
|
389
303
|
}
|
|
390
304
|
if (Object.entries(config).length !== 0) {
|
|
391
|
-
this.warnLog(
|
|
392
|
-
`Fan: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`,
|
|
393
|
-
);
|
|
305
|
+
this.warnLog(`Fan: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
394
306
|
}
|
|
395
307
|
}
|
|
396
308
|
|
|
397
309
|
logs(device: irdevice & irDevicesConfig) {
|
|
398
310
|
if (this.platform.debugMode) {
|
|
399
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
400
|
-
this.debugLog(
|
|
401
|
-
`Fan: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
|
|
402
|
-
);
|
|
311
|
+
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
312
|
+
this.debugLog(`Fan: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
403
313
|
} else if (device.logging) {
|
|
404
314
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
405
|
-
this.debugLog(
|
|
406
|
-
`Fan: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
|
|
407
|
-
);
|
|
315
|
+
this.debugLog(`Fan: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
408
316
|
} else if (this.platform.config.options?.logging) {
|
|
409
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
410
|
-
|
|
411
|
-
this.debugLog(
|
|
412
|
-
`Fan: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
|
|
413
|
-
);
|
|
317
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
318
|
+
this.debugLog(`Fan: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
414
319
|
} else {
|
|
415
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
416
|
-
this.debugLog(
|
|
417
|
-
`Fan: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
|
|
418
|
-
);
|
|
320
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
321
|
+
this.debugLog(`Fan: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
419
322
|
}
|
|
420
323
|
}
|
|
421
324
|
|
|
422
325
|
/**
|
|
423
|
-
|
|
424
|
-
|
|
326
|
+
* Logging for Device
|
|
327
|
+
*/
|
|
425
328
|
infoLog(...log: any[]) {
|
|
426
329
|
if (this.enablingDeviceLogging()) {
|
|
427
330
|
this.platform.log.info(String(...log));
|
|
@@ -442,8 +345,8 @@ export class Fan {
|
|
|
442
345
|
|
|
443
346
|
debugLog(...log: any[]) {
|
|
444
347
|
if (this.enablingDeviceLogging()) {
|
|
445
|
-
if (this.deviceLogging ===
|
|
446
|
-
this.platform.log.info(
|
|
348
|
+
if (this.deviceLogging === 'debug') {
|
|
349
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
447
350
|
} else {
|
|
448
351
|
this.platform.log.debug(String(...log));
|
|
449
352
|
}
|
|
@@ -451,6 +354,6 @@ export class Fan {
|
|
|
451
354
|
}
|
|
452
355
|
|
|
453
356
|
enablingDeviceLogging(): boolean {
|
|
454
|
-
return this.deviceLogging
|
|
357
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
455
358
|
}
|
|
456
359
|
}
|