@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.
Files changed (75) hide show
  1. package/dist/device/blindtilt.js.map +1 -1
  2. package/dist/device/bot.js.map +1 -1
  3. package/dist/device/ceilinglight.d.ts.map +1 -1
  4. package/dist/device/ceilinglight.js +9 -6
  5. package/dist/device/ceilinglight.js.map +1 -1
  6. package/dist/device/colorbulb.d.ts.map +1 -1
  7. package/dist/device/colorbulb.js +3 -7
  8. package/dist/device/colorbulb.js.map +1 -1
  9. package/dist/device/curtain.js.map +1 -1
  10. package/dist/device/device.js +9 -9
  11. package/dist/device/device.js.map +1 -1
  12. package/dist/device/fan.js.map +1 -1
  13. package/dist/device/waterdetector.d.ts.map +1 -1
  14. package/dist/device/waterdetector.js +3 -5
  15. package/dist/device/waterdetector.js.map +1 -1
  16. package/dist/irdevice/airconditioner.d.ts +3 -1
  17. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  18. package/dist/irdevice/airconditioner.js +103 -44
  19. package/dist/irdevice/airconditioner.js.map +1 -1
  20. package/dist/irdevice/airpurifier.d.ts +1 -0
  21. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  22. package/dist/irdevice/airpurifier.js +49 -18
  23. package/dist/irdevice/airpurifier.js.map +1 -1
  24. package/dist/irdevice/camera.d.ts.map +1 -1
  25. package/dist/irdevice/camera.js +9 -9
  26. package/dist/irdevice/camera.js.map +1 -1
  27. package/dist/irdevice/fan.d.ts.map +1 -1
  28. package/dist/irdevice/fan.js +19 -19
  29. package/dist/irdevice/fan.js.map +1 -1
  30. package/dist/irdevice/irdevice.d.ts +10 -22
  31. package/dist/irdevice/irdevice.d.ts.map +1 -1
  32. package/dist/irdevice/irdevice.js +67 -89
  33. package/dist/irdevice/irdevice.js.map +1 -1
  34. package/dist/irdevice/light.d.ts.map +1 -1
  35. package/dist/irdevice/light.js +17 -15
  36. package/dist/irdevice/light.js.map +1 -1
  37. package/dist/irdevice/other.d.ts.map +1 -1
  38. package/dist/irdevice/other.js +76 -76
  39. package/dist/irdevice/other.js.map +1 -1
  40. package/dist/irdevice/tv.d.ts.map +1 -1
  41. package/dist/irdevice/tv.js +35 -35
  42. package/dist/irdevice/tv.js.map +1 -1
  43. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  44. package/dist/irdevice/vacuumcleaner.js +9 -9
  45. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  46. package/dist/irdevice/waterheater.d.ts.map +1 -1
  47. package/dist/irdevice/waterheater.js +9 -9
  48. package/dist/irdevice/waterheater.js.map +1 -1
  49. package/dist/platform.d.ts +12 -14
  50. package/dist/platform.d.ts.map +1 -1
  51. package/dist/platform.js +245 -245
  52. package/dist/platform.js.map +1 -1
  53. package/dist/types/devicewebhookstatus.d.ts +1 -1
  54. package/dist/types/devicewebhookstatus.d.ts.map +1 -1
  55. package/package.json +1 -1
  56. package/src/device/blindtilt.ts +1 -1
  57. package/src/device/bot.ts +1 -1
  58. package/src/device/ceilinglight.ts +15 -7
  59. package/src/device/colorbulb.ts +11 -8
  60. package/src/device/curtain.ts +1 -1
  61. package/src/device/device.ts +9 -9
  62. package/src/device/fan.ts +1 -1
  63. package/src/device/waterdetector.ts +3 -5
  64. package/src/irdevice/airconditioner.ts +97 -53
  65. package/src/irdevice/airpurifier.ts +45 -23
  66. package/src/irdevice/camera.ts +9 -9
  67. package/src/irdevice/fan.ts +19 -19
  68. package/src/irdevice/irdevice.ts +68 -92
  69. package/src/irdevice/light.ts +17 -15
  70. package/src/irdevice/other.ts +76 -76
  71. package/src/irdevice/tv.ts +35 -35
  72. package/src/irdevice/vacuumcleaner.ts +9 -9
  73. package/src/irdevice/waterheater.ts +9 -9
  74. package/src/platform.ts +247 -247
  75. 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
- await this.debugLog(`Set Active: ${value}`);
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
- await this.debugLog(`pushAirPurifierOnChanges Active: ${this.AirPurifier.Active},`
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
- await this.debugLog(`pushAirPurifierOffChanges Active: ${this.AirPurifier.Active},`
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
- await this.debugLog(`pushAirPurifierStatusChanges Active: ${this.AirPurifier.Active},`
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.AirPurifier.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.IDLE;
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
- await this.debugLog(`pushAirPurifierDetailsChanges Active: ${this.AirPurifier.Active},`
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.AirPurifier.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.COOLING;
213
+ this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.COOLING;
215
214
  } else {
216
- this.AirPurifier.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.HEATING;
215
+ this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.HEATING;
217
216
  }
218
217
  } else {
219
- this.AirPurifier.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.INACTIVE;
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
- await this.debugLog('pushChanges');
224
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
226
225
  if (this.device.connectionType === 'OpenAPI') {
227
- this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
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(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
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
- await this.updateCharacteristic(this.AirPurifier.Service, this.hap.Characteristic.Active,
252
- this.AirPurifier.Active, 'Active');
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
- await this.updateCharacteristic(this.AirPurifier.Service, this.hap.Characteristic.CurrentAirPurifierState,
255
- this.AirPurifier.CurrentAirPurifierState, 'CurrentAirPurifierState');
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
- await this.updateCharacteristic(this.AirPurifier.Service, this.hap.Characteristic.CurrentHeaterCoolerState,
258
- this.AirPurifier.CurrentHeaterCoolerState, 'CurrentHeaterCoolerState');
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
- await this.updateCharacteristic(this.TemperatureSensor.Service, this.hap.Characteristic.CurrentTemperature,
261
- this.TemperatureSensor.CurrentTemperature, 'CurrentTemperature');
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> {
@@ -48,7 +48,7 @@ export class Camera extends irdeviceBase {
48
48
  }
49
49
 
50
50
  async OnSet(value: CharacteristicValue): Promise<void> {
51
- await this.debugLog(`On: ${value}`);
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
- await this.debugLog(`pushOnChanges On: ${this.Switch.On},`
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
- await this.debugLog(`pushOffChanges On: ${this.Switch.On},`
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
- await this.debugLog('pushChanges');
102
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
103
103
  if (this.device.connectionType === 'OpenAPI') {
104
- this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
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
- await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
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
- await this.debugLog(`On: ${this.Switch.On}`);
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
- await this.debugLog(`updateCharacteristic On: ${this.Switch.On}`);
133
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Switch.On}`);
134
134
  }
135
135
  }
136
136
 
@@ -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('Rotation Speed Characteristic was removed.');
71
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Rotation Speed Characteristic was removed.`);
72
72
  } else {
73
- this.debugLog('RotationSpeed Characteristic was not removed/added, '
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('Swing Mode Characteristic was removed.');
88
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Swing Mode Characteristic was removed.`);
89
89
  } else {
90
- this.debugLog('Swing Mode Characteristic was not removed/added, '
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
- await this.debugLog(`SwingMode: ${value}`);
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
- await this.debugLog(`RotationSpeed: ${value}`);
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
- await this.debugLog(`Active: ${value}`);
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
- await this.debugLog(`pushFanOnChanges Active: ${this.Fan.Active},`
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
- await this.debugLog(`pushLightOffChanges Active: ${this.Fan.Active},`
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
- await this.debugLog('pushChanges');
202
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
203
203
  if (this.device.connectionType === 'OpenAPI') {
204
- this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
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
- await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
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
- await this.debugLog(`Active: ${this.Fan.Active}`);
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
- await this.debugLog(`updateCharacteristic Active: ${this.Fan.Active}`);
232
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Fan.Active}`);
233
233
  }
234
234
  if (this.Fan.SwingMode === undefined) {
235
- await this.debugLog(`SwingMode: ${this.Fan.SwingMode}`);
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
- await this.debugLog(`updateCharacteristic SwingMode: ${this.Fan.SwingMode}`);
239
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.Fan.SwingMode}`);
240
240
  }
241
241
  if (this.Fan.RotationSpeed === undefined) {
242
- await this.debugLog(`RotationSpeed: ${this.Fan.RotationSpeed}`);
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
- await this.debugLog(`updateCharacteristic RotationSpeed: ${this.Fan.RotationSpeed}`);
246
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.Fan.RotationSpeed}`);
247
247
  }
248
248
  }
249
249
 
@@ -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, Service, CharacteristicValue } from 'homebridge';
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
- await this.debugWarnLog(`Using Debug Mode Logging: ${this.deviceLogging}`);
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
- await this.debugWarnLog(`Using Device Config Logging: ${this.deviceLogging}`);
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
- await this.debugWarnLog(`Using Platform Config Logging: ${this.deviceLogging}`);
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
- await this.debugWarnLog(`Logging Not Set, Using: ${this.deviceLogging}`);
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(`Config: ${JSON.stringify(config)}`);
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
- await this.debugLog(`${this.device.remoteType}: ${accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
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
- await this.debugWarnLog(`statusCode: ${statusCode}`);
233
- await this.debugWarnLog(`deviceStatus: ${JSON.stringify(deviceStatus)}`);
234
- await this.debugWarnLog(`deviceStatus statusCode: ${deviceStatus.statusCode}`);
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(`statusCode: ${statusCode} & deviceStatus `
211
+ this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode} & deviceStatus `
239
212
  + `StatusCode: ${deviceStatus.statusCode}`);
240
- this.successLog('request to SwitchBot API,'
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(`failed pushChanges with ${this.device.connectionType}`
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(`Command not supported by this deviceType, statusCode: ${statusCode}`);
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(`Device not found, statusCode: ${statusCode}`);
284
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
312
285
  break;
313
286
  case 160:
314
- this.errorLog(`Command is not supported, statusCode: ${statusCode}`);
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(`Device is offline, statusCode: ${statusCode}`);
290
+ this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
318
291
  break;
319
292
  case 171:
320
- this.errorLog(`Hub Device is offline, statusCode: ${statusCode}. Hub: ${this.device.hubDeviceId}`);
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('Device internal error due to device states not synchronized with server, Or command format is invalid,'
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
- await this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
301
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
328
302
  break;
329
303
  case 200:
330
- await this.debugLog(`Request successful, statusCode: ${statusCode}`);
304
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
331
305
  break;
332
306
  case 400:
333
- this.errorLog('Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request'
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(`Unauthorized, Authorization for the API is required, but the request has not been authenticated, statusCode: ${statusCode}`);
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('Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not'
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(`Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`);
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('Not Acceptable, The client has requested a MIME type via the Accept header for a value not supported by the server,'
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('Unsupported Media Type, The client has defined a contentType header that is not supported by the server,'
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('Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for APIs'
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('Too Many Requests, The client has exceeded the number of requests allowed for a given time window,'
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('Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare,'
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('Unknown statusCode: '
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
- async infoLog(...log: any[]): Promise<void> {
376
- if (await this.enablingDeviceLogging()) {
377
- this.log.info(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
351
+ infoLog(...log: any[]): void {
352
+ if (this.enablingDeviceLogging()) {
353
+ this.log.info(String(...log));
378
354
  }
379
355
  }
380
356
 
381
- async successLog(...log: any[]): Promise<void> {
382
- if (await this.enablingDeviceLogging()) {
383
- this.log.success(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
357
+ successLog(...log: any[]): void {
358
+ if (this.enablingDeviceLogging()) {
359
+ this.platform.log.success(String(...log));
384
360
  }
385
361
  }
386
362
 
387
- async debugSuccessLog(...log: any[]): Promise<void> {
388
- if (await this.enablingDeviceLogging()) {
363
+ debugSuccessLog(...log: any[]): void {
364
+ if (this.enablingDeviceLogging()) {
389
365
  if (this.deviceLogging?.includes('debug')) {
390
- this.log.success(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
366
+ this.log.success('[DEBUG]', String(...log));
391
367
  }
392
368
  }
393
369
  }
394
370
 
395
- async warnLog(...log: any[]): Promise<void> {
396
- if (await this.enablingDeviceLogging()) {
397
- this.log.warn(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
371
+ warnLog(...log: any[]): void {
372
+ if (this.enablingDeviceLogging()) {
373
+ this.log.warn(String(...log));
398
374
  }
399
375
  }
400
376
 
401
- async debugWarnLog(...log: any[]): Promise<void> {
402
- if (await this.enablingDeviceLogging()) {
377
+ debugWarnLog(...log: any[]): void {
378
+ if (this.enablingDeviceLogging()) {
403
379
  if (this.deviceLogging?.includes('debug')) {
404
- this.log.warn(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
380
+ this.log.warn('[DEBUG]', String(...log));
405
381
  }
406
382
  }
407
383
  }
408
384
 
409
- async errorLog(...log: any[]): Promise<void> {
410
- if (await this.enablingDeviceLogging()) {
411
- this.log.error(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
385
+ errorLog(...log: any[]): void {
386
+ if (this.enablingDeviceLogging()) {
387
+ this.log.error(String(...log));
412
388
  }
413
389
  }
414
390
 
415
- async debugErrorLog(...log: any[]): Promise<void> {
416
- if (await this.enablingDeviceLogging()) {
391
+ debugErrorLog(...log: any[]): void {
392
+ if (this.enablingDeviceLogging()) {
417
393
  if (this.deviceLogging?.includes('debug')) {
418
- this.log.error(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
394
+ this.log.error('[DEBUG]', String(...log));
419
395
  }
420
396
  }
421
397
  }
422
398
 
423
- async debugLog(...log: any[]): Promise<void> {
424
- if (await this.enablingDeviceLogging()) {
399
+ debugLog(...log: any[]): void {
400
+ if (this.enablingDeviceLogging()) {
425
401
  if (this.deviceLogging === 'debug') {
426
- this.log.info(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
402
+ this.log.info('[DEBUG]', String(...log));
427
403
  } else {
428
- this.log.debug(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
404
+ this.log.debug(String(...log));
429
405
  }
430
406
  }
431
407
  }
432
408
 
433
- async enablingDeviceLogging(): Promise<boolean> {
409
+ enablingDeviceLogging(): boolean {
434
410
  return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
435
411
  }
436
412
  }