@switchbot/homebridge-switchbot 3.5.1-beta.12 → 3.5.1-beta.3
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/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +9 -6
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +3 -7
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.js +9 -9
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.js.map +1 -1
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +3 -5
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +3 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +103 -44
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +1 -0
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +49 -18
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +9 -9
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +19 -19
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +10 -22
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +67 -89
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +17 -15
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +76 -76
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +35 -35
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +9 -9
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +9 -9
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +12 -14
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +245 -245
- package/dist/platform.js.map +1 -1
- package/dist/types/devicewebhookstatus.d.ts +1 -1
- package/dist/types/devicewebhookstatus.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/device/blindtilt.ts +1 -1
- package/src/device/bot.ts +1 -1
- package/src/device/ceilinglight.ts +15 -7
- package/src/device/colorbulb.ts +11 -8
- package/src/device/curtain.ts +1 -1
- package/src/device/device.ts +9 -9
- package/src/device/fan.ts +1 -1
- package/src/device/waterdetector.ts +3 -5
- package/src/irdevice/airconditioner.ts +97 -53
- package/src/irdevice/airpurifier.ts +45 -23
- package/src/irdevice/camera.ts +9 -9
- package/src/irdevice/fan.ts +19 -19
- package/src/irdevice/irdevice.ts +68 -92
- package/src/irdevice/light.ts +17 -15
- package/src/irdevice/other.ts +76 -76
- package/src/irdevice/tv.ts +35 -35
- package/src/irdevice/vacuumcleaner.ts +9 -9
- package/src/irdevice/waterheater.ts +9 -9
- package/src/platform.ts +247 -247
- package/src/types/devicewebhookstatus.ts +1 -1
|
@@ -23,7 +23,6 @@ export class AirPurifier extends irdeviceBase {
|
|
|
23
23
|
RotationSpeed: CharacteristicValue;
|
|
24
24
|
CurrentAirPurifierState: CharacteristicValue;
|
|
25
25
|
TargetAirPurifierState: CharacteristicValue;
|
|
26
|
-
CurrentHeaterCoolerState: CharacteristicValue;
|
|
27
26
|
};
|
|
28
27
|
|
|
29
28
|
private TemperatureSensor: {
|
|
@@ -37,6 +36,7 @@ export class AirPurifier extends irdeviceBase {
|
|
|
37
36
|
CurrentAPTemp!: CharacteristicValue;
|
|
38
37
|
CurrentAPMode!: CharacteristicValue;
|
|
39
38
|
CurrentAPFanSpeed!: CharacteristicValue;
|
|
39
|
+
CurrentHeaterCoolerState!: CharacteristicValue;
|
|
40
40
|
|
|
41
41
|
// Others
|
|
42
42
|
Busy: any;
|
|
@@ -64,7 +64,6 @@ export class AirPurifier extends irdeviceBase {
|
|
|
64
64
|
RotationSpeed: accessory.context.RotationSpeed ?? 0,
|
|
65
65
|
CurrentAirPurifierState: accessory.context.CurrentAirPurifierState ?? this.hap.Characteristic.CurrentAirPurifierState.INACTIVE,
|
|
66
66
|
TargetAirPurifierState: accessory.context.TargetAirPurifierState ?? this.hap.Characteristic.TargetAirPurifierState.AUTO,
|
|
67
|
-
CurrentHeaterCoolerState: accessory.context.CurrentHeaterCoolerState ?? this.hap.Characteristic.CurrentHeaterCoolerState.INACTIVE,
|
|
68
67
|
};
|
|
69
68
|
accessory.context.AirPurifier = this.AirPurifier as object;
|
|
70
69
|
|
|
@@ -107,7 +106,7 @@ export class AirPurifier extends irdeviceBase {
|
|
|
107
106
|
}
|
|
108
107
|
|
|
109
108
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
110
|
-
|
|
109
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
|
|
111
110
|
|
|
112
111
|
this.AirPurifier.Active = value;
|
|
113
112
|
if (this.AirPurifier.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
@@ -154,7 +153,7 @@ export class AirPurifier extends irdeviceBase {
|
|
|
154
153
|
* AirPurifier: "command" "highSpeed" "default" = fan speed to high
|
|
155
154
|
*/
|
|
156
155
|
async pushAirPurifierOnChanges(): Promise<void> {
|
|
157
|
-
|
|
156
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierOnChanges Active: ${this.AirPurifier.Active},`
|
|
158
157
|
+ ` disablePushOn: ${this.disablePushOn}`);
|
|
159
158
|
if (this.AirPurifier.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
160
159
|
const commandType: string = await this.commandType();
|
|
@@ -169,7 +168,7 @@ export class AirPurifier extends irdeviceBase {
|
|
|
169
168
|
}
|
|
170
169
|
|
|
171
170
|
async pushAirPurifierOffChanges(): Promise<void> {
|
|
172
|
-
|
|
171
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierOffChanges Active: ${this.AirPurifier.Active},`
|
|
173
172
|
+ ` disablePushOff: ${this.disablePushOff}`);
|
|
174
173
|
if (this.AirPurifier.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOn) {
|
|
175
174
|
const commandType: string = await this.commandType();
|
|
@@ -184,11 +183,11 @@ export class AirPurifier extends irdeviceBase {
|
|
|
184
183
|
}
|
|
185
184
|
|
|
186
185
|
async pushAirPurifierStatusChanges(): Promise<void> {
|
|
187
|
-
|
|
186
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierStatusChanges Active: ${this.AirPurifier.Active},`
|
|
188
187
|
+ ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
|
|
189
188
|
if (!this.Busy) {
|
|
190
189
|
this.Busy = true;
|
|
191
|
-
this.
|
|
190
|
+
this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.IDLE;
|
|
192
191
|
}
|
|
193
192
|
clearTimeout(this.Timeout);
|
|
194
193
|
|
|
@@ -197,7 +196,7 @@ export class AirPurifier extends irdeviceBase {
|
|
|
197
196
|
}
|
|
198
197
|
|
|
199
198
|
async pushAirPurifierDetailsChanges(): Promise<void> {
|
|
200
|
-
|
|
199
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierDetailsChanges Active: ${this.AirPurifier.Active},`
|
|
201
200
|
+ ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`);
|
|
202
201
|
this.CurrentAPTemp = this.TemperatureSensor!.CurrentTemperature ?? 24;
|
|
203
202
|
this.CurrentAPMode = this.CurrentMode ?? 1;
|
|
@@ -211,20 +210,20 @@ export class AirPurifier extends irdeviceBase {
|
|
|
211
210
|
});
|
|
212
211
|
if (this.AirPurifier.Active === 1) {
|
|
213
212
|
if ((Number(this.TemperatureSensor!.CurrentTemperature) || 24) < (this.LastTemperature || 30)) {
|
|
214
|
-
this.
|
|
213
|
+
this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.COOLING;
|
|
215
214
|
} else {
|
|
216
|
-
this.
|
|
215
|
+
this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.HEATING;
|
|
217
216
|
}
|
|
218
217
|
} else {
|
|
219
|
-
this.
|
|
218
|
+
this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.INACTIVE;
|
|
220
219
|
}
|
|
221
220
|
await this.pushChanges(bodyChange);
|
|
222
221
|
}
|
|
223
222
|
|
|
224
223
|
async pushChanges(bodyChange: any): Promise<void> {
|
|
225
|
-
|
|
224
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
|
|
226
225
|
if (this.device.connectionType === 'OpenAPI') {
|
|
227
|
-
this.infoLog(
|
|
226
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
228
227
|
try {
|
|
229
228
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
230
229
|
const deviceStatus: any = await body.json();
|
|
@@ -241,24 +240,47 @@ export class AirPurifier extends irdeviceBase {
|
|
|
241
240
|
await this.pushChangeError(e);
|
|
242
241
|
}
|
|
243
242
|
} else {
|
|
244
|
-
this.warnLog(
|
|
243
|
+
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
244
|
+
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
249
|
-
await this.debugLog('updateHomeKitCharacteristics');
|
|
250
249
|
// Active
|
|
251
|
-
|
|
252
|
-
this.
|
|
250
|
+
if (this.AirPurifier.Active === undefined) {
|
|
251
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.AirPurifier.Active}`);
|
|
252
|
+
} else {
|
|
253
|
+
this.accessory.context.Active = this.AirPurifier.Active;
|
|
254
|
+
this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.AirPurifier.Active);
|
|
255
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.AirPurifier.Active}`);
|
|
256
|
+
}
|
|
253
257
|
// CurrentAirPurifierState
|
|
254
|
-
|
|
255
|
-
this.
|
|
258
|
+
if (this.AirPurifier.CurrentAirPurifierState === undefined) {
|
|
259
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentAirPurifierState: ${this.AirPurifier.CurrentAirPurifierState}`);
|
|
260
|
+
} else {
|
|
261
|
+
this.accessory.context.CurrentAirPurifierState = this.AirPurifier.CurrentAirPurifierState;
|
|
262
|
+
this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentAirPurifierState, this.AirPurifier.CurrentAirPurifierState);
|
|
263
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
264
|
+
+ ` CurrentAirPurifierState: ${this.AirPurifier.CurrentAirPurifierState}`);
|
|
265
|
+
}
|
|
256
266
|
// CurrentHeaterCoolerState
|
|
257
|
-
|
|
258
|
-
this.
|
|
267
|
+
if (this.CurrentHeaterCoolerState === undefined) {
|
|
268
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
269
|
+
} else {
|
|
270
|
+
this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
|
|
271
|
+
this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
|
|
272
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
273
|
+
+ ` CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
274
|
+
}
|
|
259
275
|
// CurrentTemperature
|
|
260
|
-
|
|
261
|
-
this.
|
|
276
|
+
if (this.TemperatureSensor.CurrentTemperature === undefined) {
|
|
277
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
278
|
+
} else {
|
|
279
|
+
this.accessory.context.CurrentTemperature = this.TemperatureSensor.CurrentTemperature;
|
|
280
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor.CurrentTemperature);
|
|
281
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
282
|
+
+ ` CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
283
|
+
}
|
|
262
284
|
}
|
|
263
285
|
|
|
264
286
|
async apiError(e: any): Promise<void> {
|
package/src/irdevice/camera.ts
CHANGED
|
@@ -48,7 +48,7 @@ export class Camera extends irdeviceBase {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
51
|
-
|
|
51
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
|
|
52
52
|
|
|
53
53
|
this.Switch.On = value;
|
|
54
54
|
if (this.Switch.On) {
|
|
@@ -69,7 +69,7 @@ export class Camera extends irdeviceBase {
|
|
|
69
69
|
* Camera - "command" "channelSub" "default" = previous channel
|
|
70
70
|
*/
|
|
71
71
|
async pushOnChanges(): Promise<void> {
|
|
72
|
-
|
|
72
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges On: ${this.Switch.On},`
|
|
73
73
|
+ ` disablePushOn: ${this.disablePushOn}`);
|
|
74
74
|
if (this.Switch.On && !this.disablePushOn) {
|
|
75
75
|
const commandType: string = await this.commandType();
|
|
@@ -84,7 +84,7 @@ export class Camera extends irdeviceBase {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
async pushOffChanges(): Promise<void> {
|
|
87
|
-
|
|
87
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOffChanges On: ${this.Switch.On},`
|
|
88
88
|
+ ` disablePushOff: ${this.disablePushOff}`);
|
|
89
89
|
if (!this.Switch.On && !this.disablePushOff) {
|
|
90
90
|
const commandType: string = await this.commandType();
|
|
@@ -99,9 +99,9 @@ export class Camera extends irdeviceBase {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
async pushChanges(bodyChange: any): Promise<void> {
|
|
102
|
-
|
|
102
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
|
|
103
103
|
if (this.device.connectionType === 'OpenAPI') {
|
|
104
|
-
this.infoLog(
|
|
104
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
105
105
|
try {
|
|
106
106
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
107
107
|
const deviceStatus: any = await body.json();
|
|
@@ -118,19 +118,19 @@ export class Camera extends irdeviceBase {
|
|
|
118
118
|
await this.pushChangeError(e);
|
|
119
119
|
}
|
|
120
120
|
} else {
|
|
121
|
-
|
|
121
|
+
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
122
|
+
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
126
|
-
await this.debugLog('updateHomeKitCharacteristics');
|
|
127
127
|
// On
|
|
128
128
|
if (this.Switch.On === undefined) {
|
|
129
|
-
|
|
129
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Switch.On}`);
|
|
130
130
|
} else {
|
|
131
131
|
this.accessory.context.On = this.Switch.On;
|
|
132
132
|
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch.On);
|
|
133
|
-
|
|
133
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Switch.On}`);
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
package/src/irdevice/fan.ts
CHANGED
|
@@ -68,9 +68,9 @@ export class IRFan extends irdeviceBase {
|
|
|
68
68
|
} else if (this.Fan.Service.testCharacteristic(this.hap.Characteristic.RotationSpeed) && !device.irfan?.swing_mode) {
|
|
69
69
|
const characteristic = this.Fan.Service.getCharacteristic(this.hap.Characteristic.RotationSpeed);
|
|
70
70
|
this.Fan.Service.removeCharacteristic(characteristic);
|
|
71
|
-
this.debugLog(
|
|
71
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Rotation Speed Characteristic was removed.`);
|
|
72
72
|
} else {
|
|
73
|
-
this.debugLog(
|
|
73
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed Characteristic was not removed/added, `
|
|
74
74
|
+ `Clear Cache on ${this.accessory.displayName} to remove Chracteristic`);
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -85,15 +85,15 @@ export class IRFan extends irdeviceBase {
|
|
|
85
85
|
} else if (this.Fan.Service.testCharacteristic(this.hap.Characteristic.SwingMode) && !device.irfan?.swing_mode) {
|
|
86
86
|
const characteristic = this.Fan.Service.getCharacteristic(this.hap.Characteristic.SwingMode);
|
|
87
87
|
this.Fan.Service.removeCharacteristic(characteristic);
|
|
88
|
-
this.debugLog(
|
|
88
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Swing Mode Characteristic was removed.`);
|
|
89
89
|
} else {
|
|
90
|
-
this.debugLog(
|
|
90
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Swing Mode Characteristic was not removed/added, `
|
|
91
91
|
+ `Clear Cache on ${this.accessory.displayName} To Remove Chracteristic`);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
async SwingModeSet(value: CharacteristicValue): Promise<void> {
|
|
96
|
-
|
|
96
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} SwingMode: ${value}`);
|
|
97
97
|
if (value > this.Fan.SwingMode) {
|
|
98
98
|
this.Fan.SwingMode = 1;
|
|
99
99
|
await this.pushFanOnChanges();
|
|
@@ -108,7 +108,7 @@ export class IRFan extends irdeviceBase {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
async RotationSpeedSet(value: CharacteristicValue): Promise<void> {
|
|
111
|
-
|
|
111
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed: ${value}`);
|
|
112
112
|
if (value > this.Fan.RotationSpeed) {
|
|
113
113
|
this.Fan.RotationSpeed = 1;
|
|
114
114
|
this.pushFanSpeedUpChanges();
|
|
@@ -122,7 +122,7 @@ export class IRFan extends irdeviceBase {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
125
|
-
|
|
125
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${value}`);
|
|
126
126
|
|
|
127
127
|
this.Fan.Active = value;
|
|
128
128
|
if (this.Fan.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
@@ -142,7 +142,7 @@ export class IRFan extends irdeviceBase {
|
|
|
142
142
|
* Fan - "command" "highSpeed" "default" = fan speed to high
|
|
143
143
|
*/
|
|
144
144
|
async pushFanOnChanges(): Promise<void> {
|
|
145
|
-
|
|
145
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushFanOnChanges Active: ${this.Fan.Active},`
|
|
146
146
|
+ ` disablePushOn: ${this.disablePushOn}`);
|
|
147
147
|
if (this.Fan.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
148
148
|
const commandType: string = await this.commandType();
|
|
@@ -157,7 +157,7 @@ export class IRFan extends irdeviceBase {
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
async pushFanOffChanges(): Promise<void> {
|
|
160
|
-
|
|
160
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushLightOffChanges Active: ${this.Fan.Active},`
|
|
161
161
|
+ ` disablePushOff: ${this.disablePushOff}`);
|
|
162
162
|
if (this.Fan.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
163
163
|
const commandType: string = await this.commandType();
|
|
@@ -199,9 +199,9 @@ export class IRFan extends irdeviceBase {
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
async pushChanges(bodyChange: any): Promise<void> {
|
|
202
|
-
|
|
202
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
|
|
203
203
|
if (this.device.connectionType === 'OpenAPI') {
|
|
204
|
-
this.infoLog(
|
|
204
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
205
205
|
try {
|
|
206
206
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
207
207
|
const deviceStatus: any = await body.json();
|
|
@@ -218,32 +218,32 @@ export class IRFan extends irdeviceBase {
|
|
|
218
218
|
await this.pushChangeError(e);
|
|
219
219
|
}
|
|
220
220
|
} else {
|
|
221
|
-
|
|
221
|
+
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
222
|
+
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
222
223
|
}
|
|
223
224
|
}
|
|
224
225
|
|
|
225
226
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
226
|
-
await this.debugLog('updateHomeKitCharacteristics');
|
|
227
227
|
if (this.Fan.Active === undefined) {
|
|
228
|
-
|
|
228
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Fan.Active}`);
|
|
229
229
|
} else {
|
|
230
230
|
this.accessory.context.Active = this.Fan.Active;
|
|
231
231
|
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.Fan.Active);
|
|
232
|
-
|
|
232
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Fan.Active}`);
|
|
233
233
|
}
|
|
234
234
|
if (this.Fan.SwingMode === undefined) {
|
|
235
|
-
|
|
235
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} SwingMode: ${this.Fan.SwingMode}`);
|
|
236
236
|
} else {
|
|
237
237
|
this.accessory.context.SwingMode = this.Fan.SwingMode;
|
|
238
238
|
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.SwingMode, this.Fan.SwingMode);
|
|
239
|
-
|
|
239
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.Fan.SwingMode}`);
|
|
240
240
|
}
|
|
241
241
|
if (this.Fan.RotationSpeed === undefined) {
|
|
242
|
-
|
|
242
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed: ${this.Fan.RotationSpeed}`);
|
|
243
243
|
} else {
|
|
244
244
|
this.accessory.context.RotationSpeed = this.Fan.RotationSpeed;
|
|
245
245
|
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, this.Fan.RotationSpeed);
|
|
246
|
-
|
|
246
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.Fan.RotationSpeed}`);
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
|
package/src/irdevice/irdevice.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { request } from 'undici';
|
|
|
6
6
|
import { Devices } from '../settings.js';
|
|
7
7
|
|
|
8
8
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
9
|
-
import type { API, HAP, Logging, PlatformAccessory
|
|
9
|
+
import type { API, HAP, Logging, PlatformAccessory } from 'homebridge';
|
|
10
10
|
import type { SwitchBotPlatformConfig, irDevicesConfig } from '../settings.js';
|
|
11
11
|
import type { irdevice } from '../types/irdevicelist.js';
|
|
12
12
|
|
|
@@ -53,16 +53,16 @@ export abstract class irdeviceBase {
|
|
|
53
53
|
async getDeviceLogSettings(device: irdevice & irDevicesConfig): Promise<void> {
|
|
54
54
|
if (this.platform.debugMode) {
|
|
55
55
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
56
|
-
|
|
56
|
+
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
57
57
|
} else if (device.logging) {
|
|
58
58
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
59
|
-
|
|
59
|
+
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
60
60
|
} else if (this.config.logging) {
|
|
61
61
|
this.deviceLogging = this.accessory.context.logging = this.config.logging;
|
|
62
|
-
|
|
62
|
+
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
63
63
|
} else {
|
|
64
64
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
65
|
-
|
|
65
|
+
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -137,7 +137,7 @@ export abstract class irdeviceBase {
|
|
|
137
137
|
const config = Object.assign({}, deviceConfig, irairConfig, irpurConfig, ircamConfig, irfanConfig, irlightConfig, otherConfig,
|
|
138
138
|
irtvConfig, irvcConfig, irwhConfig);
|
|
139
139
|
if (Object.entries(config).length !== 0) {
|
|
140
|
-
this.debugSuccessLog(
|
|
140
|
+
this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
|
|
@@ -172,7 +172,7 @@ export abstract class irdeviceBase {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
const version = deviceFirmwareVersion.toString();
|
|
175
|
-
|
|
175
|
+
this.debugLog(`${this.device.remoteType}: ${accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
|
|
176
176
|
let deviceVersion: string;
|
|
177
177
|
if (version?.includes('.') === false) {
|
|
178
178
|
const replace = version?.replace(/^V|-.*$/g, '');
|
|
@@ -201,48 +201,21 @@ export abstract class irdeviceBase {
|
|
|
201
201
|
});
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
async successfulStatusCodes(statusCode: any, deviceStatus: any) {
|
|
205
|
-
return (statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Update the characteristic value and log the change.
|
|
210
|
-
*
|
|
211
|
-
* @param Service: Service
|
|
212
|
-
* @param Characteristic: Characteristic
|
|
213
|
-
* @param CharacteristicValue: CharacteristicValue | undefined
|
|
214
|
-
* @param CharacteristicName: string
|
|
215
|
-
* @return: void
|
|
216
|
-
*
|
|
217
|
-
*/
|
|
218
|
-
async updateCharacteristic(Service: Service, Characteristic: any,
|
|
219
|
-
CharacteristicValue: CharacteristicValue | undefined, CharacteristicName: string): Promise<void> {
|
|
220
|
-
if (CharacteristicValue === undefined) {
|
|
221
|
-
await this.debugLog(`${CharacteristicName}: ${CharacteristicValue}`);
|
|
222
|
-
} else {
|
|
223
|
-
Service.updateCharacteristic(Characteristic, CharacteristicValue);
|
|
224
|
-
await this.debugLog(`updateCharacteristic ${CharacteristicName}: ${CharacteristicValue}`);
|
|
225
|
-
await this.debugWarnLog(`context before: ${this.accessory.context[CharacteristicName]}`);
|
|
226
|
-
this.accessory.context[CharacteristicName] = CharacteristicValue;
|
|
227
|
-
await this.debugWarnLog(`context after: ${this.accessory.context[CharacteristicName]}`);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
204
|
async pushStatusCodes(statusCode: any, deviceStatus: any) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
205
|
+
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
206
|
+
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
207
|
+
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
235
208
|
}
|
|
236
209
|
|
|
237
210
|
async successfulPushChange(statusCode: any, deviceStatus: any, bodyChange: any) {
|
|
238
|
-
this.debugSuccessLog(
|
|
211
|
+
this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode} & deviceStatus `
|
|
239
212
|
+ `StatusCode: ${deviceStatus.statusCode}`);
|
|
240
|
-
this.successLog(
|
|
213
|
+
this.successLog(`${this.device.remoteType}: ${this.accessory.displayName} request to SwitchBot API,`
|
|
241
214
|
+ ` body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
242
215
|
}
|
|
243
216
|
|
|
244
217
|
async pushChangeError(e: Error) {
|
|
245
|
-
this.errorLog(
|
|
218
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
|
|
246
219
|
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
247
220
|
}
|
|
248
221
|
|
|
@@ -305,66 +278,69 @@ export abstract class irdeviceBase {
|
|
|
305
278
|
async statusCode(statusCode: number): Promise<void> {
|
|
306
279
|
switch (statusCode) {
|
|
307
280
|
case 151:
|
|
308
|
-
this.errorLog(
|
|
281
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
309
282
|
break;
|
|
310
283
|
case 152:
|
|
311
|
-
this.errorLog(
|
|
284
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
312
285
|
break;
|
|
313
286
|
case 160:
|
|
314
|
-
this.errorLog(
|
|
287
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
315
288
|
break;
|
|
316
289
|
case 161:
|
|
317
|
-
this.errorLog(
|
|
290
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
318
291
|
break;
|
|
319
292
|
case 171:
|
|
320
|
-
this.errorLog(
|
|
293
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. `
|
|
294
|
+
+ `Hub: ${this.device.hubDeviceId}`);
|
|
321
295
|
break;
|
|
322
296
|
case 190:
|
|
323
|
-
this.errorLog(
|
|
324
|
-
+ ` statusCode: ${statusCode}`);
|
|
297
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with`
|
|
298
|
+
+ ` server, Or command format is invalid, statusCode: ${statusCode}`);
|
|
325
299
|
break;
|
|
326
300
|
case 100:
|
|
327
|
-
|
|
301
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
328
302
|
break;
|
|
329
303
|
case 200:
|
|
330
|
-
|
|
304
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
331
305
|
break;
|
|
332
306
|
case 400:
|
|
333
|
-
this.errorLog(
|
|
334
|
-
+ ` payload, statusCode: ${statusCode}`);
|
|
307
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
308
|
+
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
335
309
|
break;
|
|
336
310
|
case 401:
|
|
337
|
-
this.errorLog(
|
|
311
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
312
|
+
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
338
313
|
break;
|
|
339
314
|
case 403:
|
|
340
|
-
this.errorLog(
|
|
341
|
-
+ ` found, statusCode: ${statusCode}`);
|
|
315
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
316
|
+
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
342
317
|
break;
|
|
343
318
|
case 404:
|
|
344
|
-
this.errorLog(
|
|
319
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
320
|
+
+ `statusCode: ${statusCode}`);
|
|
345
321
|
break;
|
|
346
322
|
case 406:
|
|
347
|
-
this.errorLog(
|
|
348
|
-
+ ` statusCode: ${statusCode}`);
|
|
323
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
324
|
+
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
349
325
|
break;
|
|
350
326
|
case 415:
|
|
351
|
-
this.errorLog(
|
|
352
|
-
+ ` statusCode: ${statusCode}`);
|
|
327
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
328
|
+
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
353
329
|
break;
|
|
354
330
|
case 422:
|
|
355
|
-
this.errorLog(
|
|
356
|
-
+ ` for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
331
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, `
|
|
332
|
+
+ `but the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
357
333
|
break;
|
|
358
334
|
case 429:
|
|
359
|
-
this.errorLog(
|
|
360
|
-
+ ` statusCode: ${statusCode}`);
|
|
335
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
336
|
+
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
361
337
|
break;
|
|
362
338
|
case 500:
|
|
363
|
-
this.errorLog(
|
|
364
|
-
+ ` statusCode: ${statusCode}`);
|
|
339
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
340
|
+
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
365
341
|
break;
|
|
366
342
|
default:
|
|
367
|
-
this.infoLog(
|
|
343
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: `
|
|
368
344
|
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
369
345
|
}
|
|
370
346
|
}
|
|
@@ -372,65 +348,65 @@ export abstract class irdeviceBase {
|
|
|
372
348
|
/**
|
|
373
349
|
* Logging for Device
|
|
374
350
|
*/
|
|
375
|
-
|
|
376
|
-
if (
|
|
377
|
-
this.log.info(
|
|
351
|
+
infoLog(...log: any[]): void {
|
|
352
|
+
if (this.enablingDeviceLogging()) {
|
|
353
|
+
this.log.info(String(...log));
|
|
378
354
|
}
|
|
379
355
|
}
|
|
380
356
|
|
|
381
|
-
|
|
382
|
-
if (
|
|
383
|
-
this.log.success(
|
|
357
|
+
successLog(...log: any[]): void {
|
|
358
|
+
if (this.enablingDeviceLogging()) {
|
|
359
|
+
this.platform.log.success(String(...log));
|
|
384
360
|
}
|
|
385
361
|
}
|
|
386
362
|
|
|
387
|
-
|
|
388
|
-
if (
|
|
363
|
+
debugSuccessLog(...log: any[]): void {
|
|
364
|
+
if (this.enablingDeviceLogging()) {
|
|
389
365
|
if (this.deviceLogging?.includes('debug')) {
|
|
390
|
-
this.log.success(
|
|
366
|
+
this.log.success('[DEBUG]', String(...log));
|
|
391
367
|
}
|
|
392
368
|
}
|
|
393
369
|
}
|
|
394
370
|
|
|
395
|
-
|
|
396
|
-
if (
|
|
397
|
-
this.log.warn(
|
|
371
|
+
warnLog(...log: any[]): void {
|
|
372
|
+
if (this.enablingDeviceLogging()) {
|
|
373
|
+
this.log.warn(String(...log));
|
|
398
374
|
}
|
|
399
375
|
}
|
|
400
376
|
|
|
401
|
-
|
|
402
|
-
if (
|
|
377
|
+
debugWarnLog(...log: any[]): void {
|
|
378
|
+
if (this.enablingDeviceLogging()) {
|
|
403
379
|
if (this.deviceLogging?.includes('debug')) {
|
|
404
|
-
this.log.warn(
|
|
380
|
+
this.log.warn('[DEBUG]', String(...log));
|
|
405
381
|
}
|
|
406
382
|
}
|
|
407
383
|
}
|
|
408
384
|
|
|
409
|
-
|
|
410
|
-
if (
|
|
411
|
-
this.log.error(
|
|
385
|
+
errorLog(...log: any[]): void {
|
|
386
|
+
if (this.enablingDeviceLogging()) {
|
|
387
|
+
this.log.error(String(...log));
|
|
412
388
|
}
|
|
413
389
|
}
|
|
414
390
|
|
|
415
|
-
|
|
416
|
-
if (
|
|
391
|
+
debugErrorLog(...log: any[]): void {
|
|
392
|
+
if (this.enablingDeviceLogging()) {
|
|
417
393
|
if (this.deviceLogging?.includes('debug')) {
|
|
418
|
-
this.log.error(
|
|
394
|
+
this.log.error('[DEBUG]', String(...log));
|
|
419
395
|
}
|
|
420
396
|
}
|
|
421
397
|
}
|
|
422
398
|
|
|
423
|
-
|
|
424
|
-
if (
|
|
399
|
+
debugLog(...log: any[]): void {
|
|
400
|
+
if (this.enablingDeviceLogging()) {
|
|
425
401
|
if (this.deviceLogging === 'debug') {
|
|
426
|
-
this.log.info(
|
|
402
|
+
this.log.info('[DEBUG]', String(...log));
|
|
427
403
|
} else {
|
|
428
|
-
this.log.debug(
|
|
404
|
+
this.log.debug(String(...log));
|
|
429
405
|
}
|
|
430
406
|
}
|
|
431
407
|
}
|
|
432
408
|
|
|
433
|
-
|
|
409
|
+
enablingDeviceLogging(): boolean {
|
|
434
410
|
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
435
411
|
}
|
|
436
412
|
}
|