@switchbot/homebridge-switchbot 2.8.0-beta.0 → 2.8.0-beta.2
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/.prettierrc +1 -1
- package/.vscode/settings.json +1 -1
- package/CHANGELOG.md +10 -0
- package/config.schema.json +8 -0
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +49 -59
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +44 -50
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +60 -63
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +68 -70
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +22 -25
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +50 -58
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +6 -0
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +168 -26
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +49 -56
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +18 -20
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +59 -61
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +40 -41
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +3 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +65 -68
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +18 -20
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +20 -23
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +30 -33
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +48 -51
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +58 -62
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +29 -31
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +17 -20
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +27 -29
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +23 -26
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +19 -20
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +44 -47
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +17 -20
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +19 -20
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +44 -43
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/device/blindtilt.ts +106 -72
- package/src/device/bot.ts +94 -58
- package/src/device/ceilinglight.ts +102 -68
- package/src/device/colorbulb.ts +134 -82
- package/src/device/contact.ts +54 -33
- package/src/device/curtain.ts +130 -101
- package/src/device/hub.ts +198 -35
- package/src/device/humidifier.ts +128 -80
- package/src/device/iosensor.ts +43 -27
- package/src/device/lightstrip.ts +108 -67
- package/src/device/lock.ts +73 -45
- package/src/device/meter.ts +94 -75
- package/src/device/meterplus.ts +43 -27
- package/src/device/motion.ts +50 -32
- package/src/device/plug.ts +62 -39
- package/src/device/robotvacuumcleaner.ts +78 -54
- package/src/irdevice/airconditioner.ts +112 -84
- package/src/irdevice/airpurifier.ts +55 -34
- package/src/irdevice/camera.ts +35 -23
- package/src/irdevice/fan.ts +47 -33
- package/src/irdevice/light.ts +43 -29
- package/src/irdevice/other.ts +39 -23
- package/src/irdevice/tv.ts +65 -51
- package/src/irdevice/vacuumcleaner.ts +35 -23
- package/src/irdevice/waterheater.ts +43 -27
- package/src/platform.ts +85 -55
- package/src/settings.ts +41 -40
- package/src/utils.ts +1 -1
|
@@ -43,7 +43,11 @@ export class AirConditioner {
|
|
|
43
43
|
private readonly valid12 = [1, 2];
|
|
44
44
|
private readonly valid012 = [0, 1, 2];
|
|
45
45
|
|
|
46
|
-
constructor(
|
|
46
|
+
constructor(
|
|
47
|
+
private readonly platform: SwitchBotPlatform,
|
|
48
|
+
private accessory: PlatformAccessory,
|
|
49
|
+
public device: irdevice & irDevicesConfig,
|
|
50
|
+
) {
|
|
47
51
|
// default placeholders
|
|
48
52
|
this.logs({ device });
|
|
49
53
|
this.config({ device });
|
|
@@ -65,7 +69,7 @@ export class AirConditioner {
|
|
|
65
69
|
// get the Television service if it exists, otherwise create a new Television service
|
|
66
70
|
// you can create multiple services for each accessory
|
|
67
71
|
(this.coolerService = accessory.getService(this.platform.Service.HeaterCooler) || accessory.addService(this.platform.Service.HeaterCooler)),
|
|
68
|
-
|
|
72
|
+
`${accessory.displayName} ${device.remoteType}`;
|
|
69
73
|
|
|
70
74
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
71
75
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
@@ -79,11 +83,9 @@ export class AirConditioner {
|
|
|
79
83
|
}
|
|
80
84
|
|
|
81
85
|
// handle on / off events using the Active characteristic
|
|
82
|
-
this.coolerService.getCharacteristic(this.platform.Characteristic.Active)
|
|
83
|
-
.onSet(this.ActiveSet.bind(this));
|
|
86
|
+
this.coolerService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
84
87
|
|
|
85
|
-
this.coolerService.getCharacteristic(this.platform.Characteristic.CurrentTemperature)
|
|
86
|
-
.onGet(this.CurrentTemperatureGet.bind(this));
|
|
88
|
+
this.coolerService.getCharacteristic(this.platform.Characteristic.CurrentTemperature).onGet(this.CurrentTemperatureGet.bind(this));
|
|
87
89
|
|
|
88
90
|
if (this.hide_automode) {
|
|
89
91
|
this.TargetHeaterCoolerState = 1 || 2;
|
|
@@ -102,39 +104,39 @@ export class AirConditioner {
|
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
if (this.meter) {
|
|
105
|
-
this.coolerService
|
|
106
|
-
.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity)
|
|
107
|
-
.onGet(this.CurrentRelativeHumidityGet.bind(this));
|
|
107
|
+
this.coolerService.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).onGet(this.CurrentRelativeHumidityGet.bind(this));
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
this.coolerService
|
|
110
|
+
this.coolerService
|
|
111
|
+
.getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState)
|
|
111
112
|
.setProps({
|
|
112
113
|
validValues: this.ValidValues,
|
|
113
114
|
})
|
|
114
115
|
.onGet(this.TargetHeaterCoolerStateGet.bind(this))
|
|
115
116
|
.onSet(this.TargetHeaterCoolerStateSet.bind(this));
|
|
116
117
|
|
|
117
|
-
this.coolerService.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState)
|
|
118
|
-
.onGet(this.CurrentHeaterCoolerStateGet.bind(this));
|
|
118
|
+
this.coolerService.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState).onGet(this.CurrentHeaterCoolerStateGet.bind(this));
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
this.coolerService
|
|
121
|
+
.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature)
|
|
122
122
|
.setProps({
|
|
123
123
|
minStep: 0.5,
|
|
124
124
|
})
|
|
125
125
|
.onGet(this.ThresholdTemperatureGet.bind(this))
|
|
126
126
|
.onSet(this.ThresholdTemperatureSet.bind(this));
|
|
127
127
|
|
|
128
|
-
this.coolerService
|
|
128
|
+
this.coolerService
|
|
129
|
+
.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature)
|
|
129
130
|
.setProps({
|
|
130
131
|
minStep: 0.5,
|
|
131
132
|
})
|
|
132
133
|
.onGet(this.ThresholdTemperatureGet.bind(this))
|
|
133
134
|
.onSet(this.ThresholdTemperatureSet.bind(this));
|
|
134
135
|
|
|
135
|
-
this.coolerService
|
|
136
|
+
this.coolerService
|
|
137
|
+
.getCharacteristic(this.platform.Characteristic.RotationSpeed)
|
|
136
138
|
.setProps({
|
|
137
|
-
format:
|
|
139
|
+
format: 'int',
|
|
138
140
|
minStep: 1,
|
|
139
141
|
minValue: 1,
|
|
140
142
|
maxValue: 4,
|
|
@@ -153,38 +155,44 @@ export class AirConditioner {
|
|
|
153
155
|
* AirConditioner: "command" "highSpeed" "default" = fan speed to high
|
|
154
156
|
*/
|
|
155
157
|
async pushAirConditionerOnChanges(): Promise<void> {
|
|
156
|
-
this.debugLog(
|
|
157
|
-
|
|
158
|
+
this.debugLog(
|
|
159
|
+
`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges Active: ${this.Active},` +
|
|
160
|
+
` disablePushOn: ${this.disablePushOn}`,
|
|
161
|
+
);
|
|
158
162
|
if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
159
163
|
const commandType: string = await this.commandType();
|
|
160
164
|
const command: string = await this.commandOn();
|
|
161
165
|
const bodyChange = JSON.stringify({
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
166
|
+
command: command,
|
|
167
|
+
parameter: 'default',
|
|
168
|
+
commandType: commandType,
|
|
165
169
|
});
|
|
166
170
|
await this.pushChanges(bodyChange);
|
|
167
171
|
}
|
|
168
172
|
}
|
|
169
173
|
|
|
170
174
|
async pushAirConditionerOffChanges(): Promise<void> {
|
|
171
|
-
this.debugLog(
|
|
172
|
-
|
|
175
|
+
this.debugLog(
|
|
176
|
+
`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges Active: ${this.Active},` +
|
|
177
|
+
` disablePushOff: ${this.disablePushOff}`,
|
|
178
|
+
);
|
|
173
179
|
if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
174
180
|
const commandType: string = await this.commandType();
|
|
175
181
|
const command: string = await this.commandOff();
|
|
176
182
|
const bodyChange = JSON.stringify({
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
183
|
+
command: command,
|
|
184
|
+
parameter: 'default',
|
|
185
|
+
commandType: commandType,
|
|
180
186
|
});
|
|
181
187
|
await this.pushChanges(bodyChange);
|
|
182
188
|
}
|
|
183
189
|
}
|
|
184
190
|
|
|
185
191
|
async pushAirConditionerStatusChanges(): Promise<void> {
|
|
186
|
-
this.debugLog(
|
|
187
|
-
|
|
192
|
+
this.debugLog(
|
|
193
|
+
`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerStatusChanges Active: ${this.Active},` +
|
|
194
|
+
` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`,
|
|
195
|
+
);
|
|
188
196
|
if (!this.Busy) {
|
|
189
197
|
this.Busy = true;
|
|
190
198
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
|
|
@@ -196,8 +204,10 @@ export class AirConditioner {
|
|
|
196
204
|
}
|
|
197
205
|
|
|
198
206
|
async pushAirConditionerDetailsChanges(): Promise<void> {
|
|
199
|
-
this.debugLog(
|
|
200
|
-
|
|
207
|
+
this.debugLog(
|
|
208
|
+
`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerDetailsChanges Active: ${this.Active},` +
|
|
209
|
+
` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`,
|
|
210
|
+
);
|
|
201
211
|
//await this.context();
|
|
202
212
|
if (this.CurrentMode === undefined) {
|
|
203
213
|
this.CurrentMode = 1;
|
|
@@ -214,8 +224,8 @@ export class AirConditioner {
|
|
|
214
224
|
// Remove or make configurable?
|
|
215
225
|
this.ThresholdTemperature = 25;
|
|
216
226
|
this.debugLog(
|
|
217
|
-
`${this.device.remoteType}: ${this.accessory.displayName} CurrentMode: ${this.CurrentMode},`
|
|
218
|
-
|
|
227
|
+
`${this.device.remoteType}: ${this.accessory.displayName} CurrentMode: ${this.CurrentMode},` +
|
|
228
|
+
` ThresholdTemperature: ${this.ThresholdTemperature}`,
|
|
219
229
|
);
|
|
220
230
|
}
|
|
221
231
|
const parameter = `${this.ThresholdTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`;
|
|
@@ -231,9 +241,9 @@ export class AirConditioner {
|
|
|
231
241
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
|
|
232
242
|
}
|
|
233
243
|
const bodyChange = JSON.stringify({
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
244
|
+
command: 'setAll',
|
|
245
|
+
parameter: `${parameter}`,
|
|
246
|
+
commandType: 'command',
|
|
237
247
|
});
|
|
238
248
|
|
|
239
249
|
await this.pushChanges(bodyChange);
|
|
@@ -242,7 +252,7 @@ export class AirConditioner {
|
|
|
242
252
|
async pushChanges(bodyChange: any): Promise<void> {
|
|
243
253
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushChanges`);
|
|
244
254
|
if (this.device.connectionType === 'OpenAPI' && !this.disablePushDetail) {
|
|
245
|
-
this.
|
|
255
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
246
256
|
try {
|
|
247
257
|
const { body, statusCode, headers } = await request(`${Devices}/${this.device.deviceId}/commands`, {
|
|
248
258
|
body: bodyChange,
|
|
@@ -256,25 +266,33 @@ export class AirConditioner {
|
|
|
256
266
|
this.updateHomeKitCharacteristics();
|
|
257
267
|
} catch (e: any) {
|
|
258
268
|
this.apiError(e);
|
|
259
|
-
this.errorLog(
|
|
260
|
-
|
|
269
|
+
this.errorLog(
|
|
270
|
+
`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}` +
|
|
271
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
261
272
|
);
|
|
262
273
|
}
|
|
263
274
|
} else {
|
|
264
|
-
this.warnLog(
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
275
|
+
this.warnLog(
|
|
276
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` +
|
|
277
|
+
` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
|
|
278
|
+
);
|
|
279
|
+
this.debugLog(
|
|
280
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` +
|
|
281
|
+
` Connection Type: ${this.device.connectionType}, disablePushDetails: ${this.disablePushDetail}`,
|
|
282
|
+
);
|
|
268
283
|
this.updateHomeKitCharacteristics();
|
|
269
284
|
}
|
|
270
285
|
}
|
|
271
286
|
|
|
272
287
|
async CurrentTemperatureGet(): Promise<CharacteristicValue> {
|
|
273
288
|
if (this.meter) {
|
|
274
|
-
this.CurrentTemperature =
|
|
275
|
-
|
|
276
|
-
||
|
|
277
|
-
|
|
289
|
+
this.CurrentTemperature =
|
|
290
|
+
this.meter.context?.CurrentTemperature ||
|
|
291
|
+
this.meter.getService(this.platform.Service.TemperatureSensor)?.getCharacteristic(this.platform.Characteristic.CurrentTemperature).value ||
|
|
292
|
+
24;
|
|
293
|
+
this.debugLog(
|
|
294
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Using CurrentTemperature from ${this.meter.context?.deviceType} (${this.meter.context?.deviceID})`,
|
|
295
|
+
);
|
|
278
296
|
} else if (this.CurrentTemperature === undefined) {
|
|
279
297
|
this.CurrentTemperature = 24;
|
|
280
298
|
} else {
|
|
@@ -286,15 +304,16 @@ export class AirConditioner {
|
|
|
286
304
|
|
|
287
305
|
async CurrentRelativeHumidityGet(): Promise<CharacteristicValue> {
|
|
288
306
|
if (this.meter) {
|
|
289
|
-
this.CurrentRelativeHumidity =
|
|
290
|
-
|
|
291
|
-
||
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
307
|
+
this.CurrentRelativeHumidity =
|
|
308
|
+
this.meter.context?.CurrentRelativeHumidity ||
|
|
309
|
+
this.meter.getService(this.platform.Service.HumiditySensor)?.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value ||
|
|
310
|
+
0;
|
|
311
|
+
this.debugLog(
|
|
312
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Using CurrentRelativeHumidity from ${this.meter.context?.deviceType} (${this.meter.context?.deviceID})`,
|
|
313
|
+
);
|
|
314
|
+
} else if (this.CurrentRelativeHumidity === undefined) {
|
|
295
315
|
this.CurrentRelativeHumidity = 0;
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
316
|
+
} else {
|
|
298
317
|
this.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity;
|
|
299
318
|
}
|
|
300
319
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
@@ -402,17 +421,20 @@ export class AirConditioner {
|
|
|
402
421
|
if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
403
422
|
if (this.ThresholdTemperature < this.accessory.context.CurrentTemperature) {
|
|
404
423
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
|
|
405
|
-
this.debugLog(
|
|
406
|
-
+ ` Get (COOLING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}
|
|
424
|
+
this.debugLog(
|
|
425
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` + ` Get (COOLING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
|
|
426
|
+
);
|
|
407
427
|
} else if (this.ThresholdTemperature > this.accessory.context.CurrentTemperature) {
|
|
408
428
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
|
|
409
|
-
this.debugLog(
|
|
410
|
-
+ ` Get (HEATING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}
|
|
429
|
+
this.debugLog(
|
|
430
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` + ` Get (HEATING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
|
|
431
|
+
);
|
|
411
432
|
}
|
|
412
433
|
} else {
|
|
413
434
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
|
|
414
|
-
this.debugLog(
|
|
415
|
-
+ ` Get (INACTIVE) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}
|
|
435
|
+
this.debugLog(
|
|
436
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` + ` Get (INACTIVE) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
|
|
437
|
+
);
|
|
416
438
|
}
|
|
417
439
|
return this.CurrentHeaterCoolerState;
|
|
418
440
|
}
|
|
@@ -425,8 +447,10 @@ export class AirConditioner {
|
|
|
425
447
|
|
|
426
448
|
async ThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
|
|
427
449
|
this.ThresholdTemperature = value;
|
|
428
|
-
this.debugLog(
|
|
429
|
-
|
|
450
|
+
this.debugLog(
|
|
451
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set ThresholdTemperature: ${this.ThresholdTemperature},` +
|
|
452
|
+
` ThresholdTemperatureCached: ${this.accessory.context.ThresholdTemperature}`,
|
|
453
|
+
);
|
|
430
454
|
this.pushAirConditionerStatusChanges();
|
|
431
455
|
}
|
|
432
456
|
|
|
@@ -455,11 +479,12 @@ export class AirConditioner {
|
|
|
455
479
|
if (this.meter) {
|
|
456
480
|
if (this.CurrentRelativeHumidity === undefined) {
|
|
457
481
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
458
|
-
}
|
|
459
|
-
else {
|
|
482
|
+
} else {
|
|
460
483
|
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
|
|
461
484
|
this.coolerService?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
462
|
-
this.debugLog(
|
|
485
|
+
this.debugLog(
|
|
486
|
+
`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`,
|
|
487
|
+
);
|
|
463
488
|
}
|
|
464
489
|
}
|
|
465
490
|
if (this.TargetHeaterCoolerState === undefined) {
|
|
@@ -477,8 +502,8 @@ export class AirConditioner {
|
|
|
477
502
|
this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
|
|
478
503
|
this.coolerService?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
|
|
479
504
|
this.debugLog(
|
|
480
|
-
`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
481
|
-
|
|
505
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` +
|
|
506
|
+
` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
|
|
482
507
|
);
|
|
483
508
|
}
|
|
484
509
|
if (this.ThresholdTemperature === undefined) {
|
|
@@ -488,13 +513,12 @@ export class AirConditioner {
|
|
|
488
513
|
this.coolerService?.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.ThresholdTemperature);
|
|
489
514
|
this.coolerService?.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, this.ThresholdTemperature);
|
|
490
515
|
this.debugLog(
|
|
491
|
-
`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
492
|
-
+ ` updateCharacteristic ThresholdTemperature: ${this.ThresholdTemperature}`,
|
|
516
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic ThresholdTemperature: ${this.ThresholdTemperature}`,
|
|
493
517
|
);
|
|
494
518
|
}
|
|
495
519
|
}
|
|
496
520
|
|
|
497
|
-
async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig
|
|
521
|
+
async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
498
522
|
if (device.disablePushOn === undefined) {
|
|
499
523
|
this.disablePushOn = false;
|
|
500
524
|
} else {
|
|
@@ -502,7 +526,7 @@ export class AirConditioner {
|
|
|
502
526
|
}
|
|
503
527
|
}
|
|
504
528
|
|
|
505
|
-
async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig
|
|
529
|
+
async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
506
530
|
if (device.disablePushOff === undefined) {
|
|
507
531
|
this.disablePushOff = false;
|
|
508
532
|
} else {
|
|
@@ -510,7 +534,7 @@ export class AirConditioner {
|
|
|
510
534
|
}
|
|
511
535
|
}
|
|
512
536
|
|
|
513
|
-
async disablePushDetailChanges({ device }: { device: irdevice & irDevicesConfig
|
|
537
|
+
async disablePushDetailChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
514
538
|
if (device.disablePushDetail === undefined) {
|
|
515
539
|
this.disablePushDetail = false;
|
|
516
540
|
} else {
|
|
@@ -563,8 +587,10 @@ export class AirConditioner {
|
|
|
563
587
|
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
564
588
|
break;
|
|
565
589
|
case 171:
|
|
566
|
-
this.errorLog(
|
|
567
|
-
|
|
590
|
+
this.errorLog(
|
|
591
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
592
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
593
|
+
);
|
|
568
594
|
break;
|
|
569
595
|
case 190:
|
|
570
596
|
this.errorLog(
|
|
@@ -579,12 +605,14 @@ export class AirConditioner {
|
|
|
579
605
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
580
606
|
break;
|
|
581
607
|
default:
|
|
582
|
-
this.infoLog(
|
|
583
|
-
|
|
608
|
+
this.infoLog(
|
|
609
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
610
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
611
|
+
);
|
|
584
612
|
}
|
|
585
613
|
}
|
|
586
614
|
|
|
587
|
-
async apiError({ e }: { e: any
|
|
615
|
+
async apiError({ e }: { e: any }): Promise<void> {
|
|
588
616
|
this.coolerService.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
589
617
|
this.coolerService.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
|
|
590
618
|
this.coolerService.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
|
|
@@ -595,10 +623,11 @@ export class AirConditioner {
|
|
|
595
623
|
this.coolerService.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, e);
|
|
596
624
|
}
|
|
597
625
|
|
|
598
|
-
FirmwareRevision({ accessory, device }: { accessory: PlatformAccessory; device: irdevice & irDevicesConfig
|
|
626
|
+
FirmwareRevision({ accessory, device }: { accessory: PlatformAccessory; device: irdevice & irDevicesConfig }): string {
|
|
599
627
|
let FirmwareRevision: string;
|
|
600
|
-
this.debugLog(
|
|
601
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
628
|
+
this.debugLog(
|
|
629
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
630
|
+
);
|
|
602
631
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
603
632
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
604
633
|
if (accessory.context.FirmwareRevision) {
|
|
@@ -653,7 +682,7 @@ export class AirConditioner {
|
|
|
653
682
|
}
|
|
654
683
|
}
|
|
655
684
|
|
|
656
|
-
async config({ device }: { device: irdevice & irDevicesConfig
|
|
685
|
+
async config({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
657
686
|
let config = {};
|
|
658
687
|
if (device.irair) {
|
|
659
688
|
config = device.irair;
|
|
@@ -690,7 +719,7 @@ export class AirConditioner {
|
|
|
690
719
|
}
|
|
691
720
|
}
|
|
692
721
|
|
|
693
|
-
async logs({ device }: { device: irdevice & irDevicesConfig
|
|
722
|
+
async logs({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
694
723
|
if (this.platform.debugMode) {
|
|
695
724
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
696
725
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -753,4 +782,3 @@ export class AirConditioner {
|
|
|
753
782
|
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
754
783
|
}
|
|
755
784
|
}
|
|
756
|
-
|
|
@@ -38,7 +38,11 @@ export class AirPurifier {
|
|
|
38
38
|
disablePushOff?: boolean;
|
|
39
39
|
deviceLogging!: string;
|
|
40
40
|
|
|
41
|
-
constructor(
|
|
41
|
+
constructor(
|
|
42
|
+
private readonly platform: SwitchBotPlatform,
|
|
43
|
+
private accessory: PlatformAccessory,
|
|
44
|
+
public device: irdevice & irDevicesConfig,
|
|
45
|
+
) {
|
|
42
46
|
// default placeholders
|
|
43
47
|
this.logs(device);
|
|
44
48
|
this.config(device);
|
|
@@ -129,38 +133,44 @@ export class AirPurifier {
|
|
|
129
133
|
* AirPurifier: "command" "highSpeed" "default" = fan speed to high
|
|
130
134
|
*/
|
|
131
135
|
async pushAirPurifierOnChanges(): Promise<void> {
|
|
132
|
-
this.debugLog(
|
|
133
|
-
|
|
136
|
+
this.debugLog(
|
|
137
|
+
`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierOnChanges Active: ${this.Active},` +
|
|
138
|
+
` disablePushOn: ${this.disablePushOn}`,
|
|
139
|
+
);
|
|
134
140
|
if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
135
141
|
const commandType: string = await this.commandType();
|
|
136
142
|
const command: string = await this.commandOn();
|
|
137
143
|
const bodyChange = JSON.stringify({
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
144
|
+
command: command,
|
|
145
|
+
parameter: 'default',
|
|
146
|
+
commandType: commandType,
|
|
141
147
|
});
|
|
142
148
|
await this.pushChanges(bodyChange);
|
|
143
149
|
}
|
|
144
150
|
}
|
|
145
151
|
|
|
146
152
|
async pushAirPurifierOffChanges(): Promise<void> {
|
|
147
|
-
this.debugLog(
|
|
148
|
-
|
|
153
|
+
this.debugLog(
|
|
154
|
+
`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierOffChanges Active: ${this.Active},` +
|
|
155
|
+
` disablePushOff: ${this.disablePushOff}`,
|
|
156
|
+
);
|
|
149
157
|
if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOn) {
|
|
150
158
|
const commandType: string = await this.commandType();
|
|
151
159
|
const command: string = await this.commandOff();
|
|
152
160
|
const bodyChange = JSON.stringify({
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
161
|
+
command: command,
|
|
162
|
+
parameter: 'default',
|
|
163
|
+
commandType: commandType,
|
|
156
164
|
});
|
|
157
165
|
await this.pushChanges(bodyChange);
|
|
158
166
|
}
|
|
159
167
|
}
|
|
160
168
|
|
|
161
169
|
async pushAirPurifierStatusChanges(): Promise<void> {
|
|
162
|
-
this.debugLog(
|
|
163
|
-
|
|
170
|
+
this.debugLog(
|
|
171
|
+
`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierStatusChanges Active: ${this.Active},` +
|
|
172
|
+
` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`,
|
|
173
|
+
);
|
|
164
174
|
if (!this.Busy) {
|
|
165
175
|
this.Busy = true;
|
|
166
176
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
|
|
@@ -172,17 +182,19 @@ export class AirPurifier {
|
|
|
172
182
|
}
|
|
173
183
|
|
|
174
184
|
async pushAirPurifierDetailsChanges(): Promise<void> {
|
|
175
|
-
this.debugLog(
|
|
176
|
-
|
|
185
|
+
this.debugLog(
|
|
186
|
+
`${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierDetailsChanges Active: ${this.Active},` +
|
|
187
|
+
` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`,
|
|
188
|
+
);
|
|
177
189
|
this.CurrentAPTemp = this.CurrentTemperature || 24;
|
|
178
190
|
this.CurrentAPMode = this.CurrentMode || 1;
|
|
179
191
|
this.CurrentAPFanSpeed = this.CurrentFanSpeed || 1;
|
|
180
192
|
this.APActive = this.Active === 1 ? 'on' : 'off';
|
|
181
193
|
const parameter = `${this.CurrentAPTemp},${this.CurrentAPMode},${this.CurrentAPFanSpeed},${this.APActive}`;
|
|
182
194
|
const bodyChange = JSON.stringify({
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
195
|
+
command: 'setAll',
|
|
196
|
+
parameter: `${parameter}`,
|
|
197
|
+
commandType: 'command',
|
|
186
198
|
});
|
|
187
199
|
if (this.Active === 1) {
|
|
188
200
|
if ((Number(this.CurrentTemperature) || 24) < (this.LastTemperature || 30)) {
|
|
@@ -213,13 +225,16 @@ export class AirPurifier {
|
|
|
213
225
|
this.updateHomeKitCharacteristics();
|
|
214
226
|
} catch (e: any) {
|
|
215
227
|
this.apiError(e);
|
|
216
|
-
this.errorLog(
|
|
217
|
-
|
|
228
|
+
this.errorLog(
|
|
229
|
+
`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}` +
|
|
230
|
+
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
218
231
|
);
|
|
219
232
|
}
|
|
220
233
|
} else {
|
|
221
|
-
this.warnLog(
|
|
222
|
-
|
|
234
|
+
this.warnLog(
|
|
235
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` +
|
|
236
|
+
` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
|
|
237
|
+
);
|
|
223
238
|
}
|
|
224
239
|
}
|
|
225
240
|
|
|
@@ -236,8 +251,9 @@ export class AirPurifier {
|
|
|
236
251
|
} else {
|
|
237
252
|
this.accessory.context.CurrentAirPurifierState = this.CurrentAirPurifierState;
|
|
238
253
|
this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, this.CurrentAirPurifierState);
|
|
239
|
-
this.debugLog(
|
|
240
|
-
+ ` updateCharacteristic CurrentAirPurifierState: ${this.CurrentAirPurifierState}
|
|
254
|
+
this.debugLog(
|
|
255
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic CurrentAirPurifierState: ${this.CurrentAirPurifierState}`,
|
|
256
|
+
);
|
|
241
257
|
}
|
|
242
258
|
if (this.CurrentHeaterCoolerState === undefined) {
|
|
243
259
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
@@ -245,13 +261,13 @@ export class AirPurifier {
|
|
|
245
261
|
this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
|
|
246
262
|
this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
|
|
247
263
|
this.debugLog(
|
|
248
|
-
`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
249
|
-
|
|
264
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` +
|
|
265
|
+
` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
|
|
250
266
|
);
|
|
251
267
|
}
|
|
252
268
|
}
|
|
253
269
|
|
|
254
|
-
async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig
|
|
270
|
+
async disablePushOnChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
255
271
|
if (device.disablePushOn === undefined) {
|
|
256
272
|
this.disablePushOn = false;
|
|
257
273
|
} else {
|
|
@@ -259,7 +275,7 @@ export class AirPurifier {
|
|
|
259
275
|
}
|
|
260
276
|
}
|
|
261
277
|
|
|
262
|
-
async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig
|
|
278
|
+
async disablePushOffChanges({ device }: { device: irdevice & irDevicesConfig }): Promise<void> {
|
|
263
279
|
if (device.disablePushOff === undefined) {
|
|
264
280
|
this.disablePushOff = false;
|
|
265
281
|
} else {
|
|
@@ -312,8 +328,10 @@ export class AirPurifier {
|
|
|
312
328
|
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
313
329
|
break;
|
|
314
330
|
case 171:
|
|
315
|
-
this.errorLog(
|
|
316
|
-
|
|
331
|
+
this.errorLog(
|
|
332
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
333
|
+
`Hub: ${this.device.hubDeviceId}`,
|
|
334
|
+
);
|
|
317
335
|
break;
|
|
318
336
|
case 190:
|
|
319
337
|
this.errorLog(
|
|
@@ -328,8 +346,10 @@ export class AirPurifier {
|
|
|
328
346
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
329
347
|
break;
|
|
330
348
|
default:
|
|
331
|
-
this.infoLog(
|
|
332
|
-
|
|
349
|
+
this.infoLog(
|
|
350
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
351
|
+
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
352
|
+
);
|
|
333
353
|
}
|
|
334
354
|
}
|
|
335
355
|
|
|
@@ -342,8 +362,9 @@ export class AirPurifier {
|
|
|
342
362
|
|
|
343
363
|
FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
|
|
344
364
|
let FirmwareRevision: string;
|
|
345
|
-
this.debugLog(
|
|
346
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}
|
|
365
|
+
this.debugLog(
|
|
366
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` + ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`,
|
|
367
|
+
);
|
|
347
368
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
348
369
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
349
370
|
if (accessory.context.FirmwareRevision) {
|