@switchbot/homebridge-switchbot 1.11.0 → 1.11.1
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/CHANGELOG.md +10 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +15 -7
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +22 -22
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +44 -44
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +12 -9
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +20 -20
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +10 -7
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +11 -11
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +12 -9
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +29 -29
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +10 -7
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +13 -13
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +12 -9
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +17 -17
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +13 -10
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +25 -25
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +10 -7
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +13 -13
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +10 -7
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +16 -16
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/device/colorbulb.ts +15 -9
- package/src/irdevice/airconditioner.ts +54 -54
- package/src/irdevice/airpurifier.ts +30 -30
- package/src/irdevice/camera.ts +19 -19
- package/src/irdevice/fan.ts +40 -40
- package/src/irdevice/light.ts +23 -23
- package/src/irdevice/other.ts +25 -25
- package/src/irdevice/tv.ts +42 -42
- package/src/irdevice/vacuumcleaner.ts +21 -21
- package/src/irdevice/waterheater.ts +24 -24
- package/src/platform.ts +4 -4
package/src/device/colorbulb.ts
CHANGED
|
@@ -65,6 +65,14 @@ export class ColorBulb {
|
|
|
65
65
|
} else {
|
|
66
66
|
this.On = this.accessory.context.On;
|
|
67
67
|
}
|
|
68
|
+
this.Hue = 0;
|
|
69
|
+
this.Brightness = 0;
|
|
70
|
+
this.Saturation = 0;
|
|
71
|
+
if (device.deviceType === 'Color Bulb') {
|
|
72
|
+
this.ColorTemperature = 140;
|
|
73
|
+
}
|
|
74
|
+
this.minKelvin = 2000;
|
|
75
|
+
this.maxKelvin = 9000;
|
|
68
76
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
69
77
|
this.doColorBulbUpdate = new Subject();
|
|
70
78
|
this.colorBulbUpdateInProgress = false;
|
|
@@ -82,13 +90,13 @@ export class ColorBulb {
|
|
|
82
90
|
// get the Lightbulb service if it exists, otherwise create a new Lightbulb service
|
|
83
91
|
// you can create multiple services for each accessory
|
|
84
92
|
(this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
|
|
85
|
-
`${accessory.displayName} ${
|
|
93
|
+
`${accessory.displayName} ${device.deviceType}`;
|
|
86
94
|
|
|
87
95
|
if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
|
|
88
96
|
this.accessory.removeService(this.lightBulbService);
|
|
89
97
|
this.lightBulbService = this.accessory.addService(this.platform.Service.Lightbulb);
|
|
90
98
|
this.accessory.context.adaptiveLighting = false;
|
|
91
|
-
this.debugLog(`${
|
|
99
|
+
this.debugLog(`${device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
|
|
92
100
|
}
|
|
93
101
|
|
|
94
102
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
@@ -160,7 +168,7 @@ export class ColorBulb {
|
|
|
160
168
|
})
|
|
161
169
|
.onSet(this.SaturationSet.bind(this));
|
|
162
170
|
|
|
163
|
-
this.debugLog(`${
|
|
171
|
+
this.debugLog(`${device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
164
172
|
if (this.adaptiveLightingShift !== -1) {
|
|
165
173
|
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.lightBulbService, {
|
|
166
174
|
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
@@ -168,7 +176,7 @@ export class ColorBulb {
|
|
|
168
176
|
this.accessory.configureController(this.AdaptiveLightingController);
|
|
169
177
|
this.accessory.context.adaptiveLighting = true;
|
|
170
178
|
this.debugLog(
|
|
171
|
-
`${
|
|
179
|
+
`${device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
|
|
172
180
|
` adaptiveLightingShift: ${this.adaptiveLightingShift}`,
|
|
173
181
|
);
|
|
174
182
|
}
|
|
@@ -196,14 +204,12 @@ export class ColorBulb {
|
|
|
196
204
|
try {
|
|
197
205
|
await this.pushChanges();
|
|
198
206
|
} catch (e: any) {
|
|
199
|
-
this.errorLog(`${
|
|
207
|
+
this.errorLog(`${device.deviceType}: ${this.accessory.displayName} failed pushChanges`);
|
|
200
208
|
if (this.deviceLogging === 'debug') {
|
|
201
|
-
this.errorLog(
|
|
202
|
-
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
203
|
-
);
|
|
209
|
+
this.errorLog(`${device.deviceType}: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
204
210
|
}
|
|
205
211
|
if (this.platform.debugMode) {
|
|
206
|
-
this.errorLog(`${
|
|
212
|
+
this.errorLog(`${device.deviceType}: ${this.accessory.displayName} failed pushChanges,` + ` Error: ${JSON.stringify(e)}`);
|
|
207
213
|
}
|
|
208
214
|
this.apiError(e);
|
|
209
215
|
}
|
|
@@ -10,7 +10,7 @@ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
|
10
10
|
*/
|
|
11
11
|
export class AirConditioner {
|
|
12
12
|
// Services
|
|
13
|
-
|
|
13
|
+
coolerService!: Service;
|
|
14
14
|
|
|
15
15
|
// Characteristic Values
|
|
16
16
|
Active!: CharacteristicValue;
|
|
@@ -76,7 +76,7 @@ export class AirConditioner {
|
|
|
76
76
|
|
|
77
77
|
// get the Television service if it exists, otherwise create a new Television service
|
|
78
78
|
// you can create multiple services for each accessory
|
|
79
|
-
(this.
|
|
79
|
+
(this.coolerService = accessory.getService(this.platform.Service.HeaterCooler) || accessory.addService(this.platform.Service.HeaterCooler)),
|
|
80
80
|
`${accessory.displayName} Air Conditioner`;
|
|
81
81
|
|
|
82
82
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
@@ -85,12 +85,12 @@ export class AirConditioner {
|
|
|
85
85
|
|
|
86
86
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
87
87
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
88
|
-
this.
|
|
88
|
+
this.coolerService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
89
89
|
|
|
90
90
|
// handle on / off events using the Active characteristic
|
|
91
|
-
this.
|
|
91
|
+
this.coolerService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
92
92
|
|
|
93
|
-
this.
|
|
93
|
+
this.coolerService
|
|
94
94
|
.getCharacteristic(this.platform.Characteristic.CurrentTemperature)
|
|
95
95
|
.setProps({
|
|
96
96
|
minValue: 0,
|
|
@@ -116,7 +116,7 @@ export class AirConditioner {
|
|
|
116
116
|
` hide_automode: ${this.hide_automode}, TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`,
|
|
117
117
|
);
|
|
118
118
|
}
|
|
119
|
-
this.
|
|
119
|
+
this.coolerService
|
|
120
120
|
.getCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState)
|
|
121
121
|
.setProps({
|
|
122
122
|
validValues: this.ValidValues,
|
|
@@ -126,11 +126,11 @@ export class AirConditioner {
|
|
|
126
126
|
})
|
|
127
127
|
.onSet(this.TargetHeaterCoolerStateSet.bind(this));
|
|
128
128
|
|
|
129
|
-
this.
|
|
129
|
+
this.coolerService.getCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState).onGet(async () => {
|
|
130
130
|
return this.CurrentHeaterCoolerStateGet();
|
|
131
131
|
});
|
|
132
132
|
|
|
133
|
-
this.
|
|
133
|
+
this.coolerService
|
|
134
134
|
.getCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature)
|
|
135
135
|
.setProps({
|
|
136
136
|
minValue: 16,
|
|
@@ -142,7 +142,7 @@ export class AirConditioner {
|
|
|
142
142
|
})
|
|
143
143
|
.onSet(this.HeatingThresholdTemperatureSet.bind(this));
|
|
144
144
|
|
|
145
|
-
this.
|
|
145
|
+
this.coolerService
|
|
146
146
|
.getCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature)
|
|
147
147
|
.setProps({
|
|
148
148
|
minValue: 16,
|
|
@@ -154,7 +154,7 @@ export class AirConditioner {
|
|
|
154
154
|
})
|
|
155
155
|
.onSet(this.CoolingThresholdTemperatureSet.bind(this));
|
|
156
156
|
|
|
157
|
-
this.
|
|
157
|
+
this.coolerService
|
|
158
158
|
.getCharacteristic(this.platform.Characteristic.RotationSpeed)
|
|
159
159
|
.setProps({
|
|
160
160
|
minStep: 1,
|
|
@@ -176,7 +176,7 @@ export class AirConditioner {
|
|
|
176
176
|
* AirConditioner: "command" "middleSpeed" "default" = fan speed to medium
|
|
177
177
|
* AirConditioner: "command" "highSpeed" "default" = fan speed to high
|
|
178
178
|
*/
|
|
179
|
-
async pushAirConditionerOnChanges() {
|
|
179
|
+
async pushAirConditionerOnChanges(): Promise<void> {
|
|
180
180
|
if (this.Active !== this.platform.Characteristic.Active.ACTIVE || this.pushOn) {
|
|
181
181
|
const payload = {
|
|
182
182
|
commandType: 'command',
|
|
@@ -187,7 +187,7 @@ export class AirConditioner {
|
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
async pushAirConditionerOffChanges() {
|
|
190
|
+
async pushAirConditionerOffChanges(): Promise<void> {
|
|
191
191
|
const payload = {
|
|
192
192
|
commandType: 'command',
|
|
193
193
|
parameter: 'default',
|
|
@@ -196,7 +196,7 @@ export class AirConditioner {
|
|
|
196
196
|
await this.pushChanges(payload);
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
async pushAirConditionerStatusChanges() {
|
|
199
|
+
async pushAirConditionerStatusChanges(): Promise<void> {
|
|
200
200
|
if (!this.Busy) {
|
|
201
201
|
this.Busy = true;
|
|
202
202
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
|
|
@@ -207,7 +207,7 @@ export class AirConditioner {
|
|
|
207
207
|
this.Timeout = setTimeout(this.pushAirConditionerDetailsChanges.bind(this), 1500);
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
async pushAirConditionerDetailsChanges() {
|
|
210
|
+
async pushAirConditionerDetailsChanges(): Promise<void> {
|
|
211
211
|
const payload = {
|
|
212
212
|
commandType: 'command',
|
|
213
213
|
command: 'setAll',
|
|
@@ -247,7 +247,7 @@ export class AirConditioner {
|
|
|
247
247
|
await this.pushChanges(payload);
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
|
|
250
|
+
async pushChanges(payload: payload): Promise<void> {
|
|
251
251
|
try {
|
|
252
252
|
this.infoLog(
|
|
253
253
|
`Air Conditioner: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
@@ -279,7 +279,7 @@ export class AirConditioner {
|
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
-
statusCode(push: AxiosResponse<{ statusCode: number }>) {
|
|
282
|
+
async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void> {
|
|
283
283
|
switch (push.data.statusCode) {
|
|
284
284
|
case 151:
|
|
285
285
|
this.errorLog(`Air Conditioner: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
@@ -310,29 +310,29 @@ export class AirConditioner {
|
|
|
310
310
|
}
|
|
311
311
|
}
|
|
312
312
|
|
|
313
|
-
updateHomeKitCharacteristics() {
|
|
313
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
314
314
|
if (this.Active === undefined) {
|
|
315
315
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
316
316
|
} else {
|
|
317
|
-
this.
|
|
317
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
318
318
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
319
319
|
}
|
|
320
320
|
if (this.RotationSpeed === undefined) {
|
|
321
321
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
|
|
322
322
|
} else {
|
|
323
|
-
this.
|
|
323
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
|
|
324
324
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
|
|
325
325
|
}
|
|
326
326
|
if (this.CurrentTemperature === undefined) {
|
|
327
327
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
328
328
|
} else {
|
|
329
|
-
this.
|
|
329
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
330
330
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
331
331
|
}
|
|
332
332
|
if (this.TargetHeaterCoolerState === undefined) {
|
|
333
333
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
|
|
334
334
|
} else {
|
|
335
|
-
this.
|
|
335
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
|
|
336
336
|
this.debugLog(
|
|
337
337
|
`Air Conditioner: ${this.accessory.displayName}` + ` updateCharacteristic TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`,
|
|
338
338
|
);
|
|
@@ -340,7 +340,7 @@ export class AirConditioner {
|
|
|
340
340
|
if (this.CurrentHeaterCoolerState === undefined) {
|
|
341
341
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
342
342
|
} else {
|
|
343
|
-
this.
|
|
343
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
|
|
344
344
|
this.debugLog(
|
|
345
345
|
`Air Conditioner: ${this.accessory.displayName}` + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
|
|
346
346
|
);
|
|
@@ -348,7 +348,7 @@ export class AirConditioner {
|
|
|
348
348
|
if (this.HeatingThresholdTemperature === undefined) {
|
|
349
349
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
|
|
350
350
|
} else {
|
|
351
|
-
this.
|
|
351
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.HeatingThresholdTemperature);
|
|
352
352
|
this.debugLog(
|
|
353
353
|
`Air Conditioner: ${this.accessory.displayName}` + ` updateCharacteristic HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`,
|
|
354
354
|
);
|
|
@@ -356,25 +356,25 @@ export class AirConditioner {
|
|
|
356
356
|
if (this.CoolingThresholdTemperature === undefined) {
|
|
357
357
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`);
|
|
358
358
|
} else {
|
|
359
|
-
this.
|
|
359
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, this.CoolingThresholdTemperature);
|
|
360
360
|
this.debugLog(
|
|
361
361
|
`Air Conditioner: ${this.accessory.displayName}` + ` updateCharacteristic CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`,
|
|
362
362
|
);
|
|
363
363
|
}
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
-
|
|
367
|
-
this.
|
|
368
|
-
this.
|
|
369
|
-
this.
|
|
370
|
-
this.
|
|
371
|
-
this.
|
|
372
|
-
this.
|
|
373
|
-
this.
|
|
366
|
+
async apiError(e: any): Promise<void> {
|
|
367
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
368
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
|
|
369
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
|
|
370
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, e);
|
|
371
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, e);
|
|
372
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, e);
|
|
373
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, e);
|
|
374
374
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
375
375
|
}
|
|
376
376
|
|
|
377
|
-
CurrentTemperatureGet() {
|
|
377
|
+
async CurrentTemperatureGet(): Promise<CharacteristicValue> {
|
|
378
378
|
if (this.CurrentTemperature === undefined) {
|
|
379
379
|
this.CurrentTemperature = 24;
|
|
380
380
|
this.CurrentTemperatureCached = this.CurrentTemperature;
|
|
@@ -386,7 +386,7 @@ export class AirConditioner {
|
|
|
386
386
|
return this.CurrentTemperature;
|
|
387
387
|
}
|
|
388
388
|
|
|
389
|
-
RotationSpeedGet() {
|
|
389
|
+
async RotationSpeedGet(): Promise<number> {
|
|
390
390
|
if (!this.CurrentFanSpeed) {
|
|
391
391
|
this.RotationSpeed = 4;
|
|
392
392
|
} else if (this.CurrentFanSpeed === 1) {
|
|
@@ -400,7 +400,7 @@ export class AirConditioner {
|
|
|
400
400
|
return this.RotationSpeed;
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
-
RotationSpeedSet(value: CharacteristicValue) {
|
|
403
|
+
async RotationSpeedSet(value: CharacteristicValue): Promise<void> {
|
|
404
404
|
if (value === 4) {
|
|
405
405
|
this.CurrentFanSpeed = 1;
|
|
406
406
|
} else {
|
|
@@ -412,7 +412,7 @@ export class AirConditioner {
|
|
|
412
412
|
this.pushAirConditionerStatusChanges();
|
|
413
413
|
}
|
|
414
414
|
|
|
415
|
-
ActiveSet(value: CharacteristicValue) {
|
|
415
|
+
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
416
416
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set Active: ${value}`);
|
|
417
417
|
|
|
418
418
|
this.Active = value;
|
|
@@ -432,7 +432,7 @@ export class AirConditioner {
|
|
|
432
432
|
}
|
|
433
433
|
}
|
|
434
434
|
|
|
435
|
-
TargetHeaterCoolerStateGet() {
|
|
435
|
+
async TargetHeaterCoolerStateGet(): Promise<CharacteristicValue> {
|
|
436
436
|
if (this.ValidValues === [0, 1, 2]) {
|
|
437
437
|
this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
|
|
438
438
|
this.debugLog(
|
|
@@ -457,7 +457,7 @@ export class AirConditioner {
|
|
|
457
457
|
return this.TargetHeaterCoolerState;
|
|
458
458
|
}
|
|
459
459
|
|
|
460
|
-
TargetHeaterCoolerStateSet(value: CharacteristicValue) {
|
|
460
|
+
async TargetHeaterCoolerStateSet(value: CharacteristicValue): Promise<void> {
|
|
461
461
|
if (this.hide_automode) {
|
|
462
462
|
if (value === this.platform.Characteristic.TargetHeaterCoolerState.HEAT) {
|
|
463
463
|
this.TargetHeaterCoolerStateHEAT();
|
|
@@ -488,28 +488,28 @@ export class AirConditioner {
|
|
|
488
488
|
this.pushAirConditionerStatusChanges();
|
|
489
489
|
}
|
|
490
490
|
|
|
491
|
-
|
|
491
|
+
async TargetHeaterCoolerStateAUTO(): Promise<void> {
|
|
492
492
|
this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
|
|
493
493
|
this.CurrentMode = 1;
|
|
494
494
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set (AUTO) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
|
|
495
495
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
|
|
496
496
|
}
|
|
497
497
|
|
|
498
|
-
|
|
498
|
+
async TargetHeaterCoolerStateCOOL(): Promise<void> {
|
|
499
499
|
this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.COOL;
|
|
500
500
|
this.CurrentMode = 2;
|
|
501
501
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set (COOL) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
|
|
502
502
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
|
|
503
503
|
}
|
|
504
504
|
|
|
505
|
-
|
|
505
|
+
async TargetHeaterCoolerStateHEAT(): Promise<void> {
|
|
506
506
|
this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
|
|
507
507
|
this.CurrentMode = 5;
|
|
508
508
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} Set (HEAT) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
|
|
509
509
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
|
|
510
510
|
}
|
|
511
511
|
|
|
512
|
-
CurrentHeaterCoolerStateGet() {
|
|
512
|
+
async CurrentHeaterCoolerStateGet(): Promise<CharacteristicValue> {
|
|
513
513
|
if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
514
514
|
this.CurrentTemperatureUndefined();
|
|
515
515
|
if (this.CurrentTemperature < this.CurrentTemperatureCached) {
|
|
@@ -528,7 +528,7 @@ export class AirConditioner {
|
|
|
528
528
|
return this.CurrentHeaterCoolerState;
|
|
529
529
|
}
|
|
530
530
|
|
|
531
|
-
|
|
531
|
+
async HeatingThresholdTemperatureGet(): Promise<CharacteristicValue> {
|
|
532
532
|
this.CurrentTemperatureUndefined;
|
|
533
533
|
this.CurrentTemperature = this.CurrentTemperatureCached;
|
|
534
534
|
this.HeatingThresholdTemperature = this.CurrentTemperatureCached;
|
|
@@ -538,7 +538,7 @@ export class AirConditioner {
|
|
|
538
538
|
return this.HeatingThresholdTemperature;
|
|
539
539
|
}
|
|
540
540
|
|
|
541
|
-
|
|
541
|
+
async HeatingThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
|
|
542
542
|
this.CurrentTemperatureCached = this.CurrentTemperature;
|
|
543
543
|
this.CurrentTemperature = value;
|
|
544
544
|
this.HeatingThresholdTemperatureCached = this.HeatingThresholdTemperature;
|
|
@@ -550,7 +550,7 @@ export class AirConditioner {
|
|
|
550
550
|
this.pushAirConditionerStatusChanges();
|
|
551
551
|
}
|
|
552
552
|
|
|
553
|
-
|
|
553
|
+
async CoolingThresholdTemperatureGet(): Promise<CharacteristicValue> {
|
|
554
554
|
this.CurrentTemperatureUndefined;
|
|
555
555
|
this.CurrentTemperature = this.CurrentTemperatureCached;
|
|
556
556
|
this.CoolingThresholdTemperature = this.CurrentTemperatureCached;
|
|
@@ -560,7 +560,7 @@ export class AirConditioner {
|
|
|
560
560
|
return this.CoolingThresholdTemperature;
|
|
561
561
|
}
|
|
562
562
|
|
|
563
|
-
|
|
563
|
+
async CoolingThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
|
|
564
564
|
this.CurrentTemperatureCached = this.CurrentTemperature;
|
|
565
565
|
this.CurrentTemperature = value;
|
|
566
566
|
this.CoolingThresholdTemperatureCached = this.CoolingThresholdTemperature;
|
|
@@ -572,7 +572,7 @@ export class AirConditioner {
|
|
|
572
572
|
this.pushAirConditionerStatusChanges();
|
|
573
573
|
}
|
|
574
574
|
|
|
575
|
-
|
|
575
|
+
async CurrentTemperatureUndefined(): Promise<void> {
|
|
576
576
|
if (this.CurrentTemperature === undefined) {
|
|
577
577
|
this.CurrentTemperature = 24;
|
|
578
578
|
}
|
|
@@ -581,7 +581,7 @@ export class AirConditioner {
|
|
|
581
581
|
}
|
|
582
582
|
}
|
|
583
583
|
|
|
584
|
-
config(device: irdevice & irDevicesConfig) {
|
|
584
|
+
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
585
585
|
let config = {};
|
|
586
586
|
if (device.irair) {
|
|
587
587
|
config = device.irair;
|
|
@@ -594,7 +594,7 @@ export class AirConditioner {
|
|
|
594
594
|
}
|
|
595
595
|
}
|
|
596
596
|
|
|
597
|
-
logs(device: irdevice & irDevicesConfig) {
|
|
597
|
+
async logs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
598
598
|
if (this.platform.debugMode) {
|
|
599
599
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
600
600
|
this.debugLog(`Air Conditioner: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -611,7 +611,7 @@ export class AirConditioner {
|
|
|
611
611
|
}
|
|
612
612
|
|
|
613
613
|
|
|
614
|
-
pushOnChanges(device: irdevice & irDevicesConfig) {
|
|
614
|
+
async pushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
615
615
|
if (device.irair?.pushOn) {
|
|
616
616
|
this.pushOn = true;
|
|
617
617
|
} else {
|
|
@@ -622,25 +622,25 @@ export class AirConditioner {
|
|
|
622
622
|
/**
|
|
623
623
|
* Logging for Device
|
|
624
624
|
*/
|
|
625
|
-
infoLog(...log: any[]) {
|
|
625
|
+
infoLog(...log: any[]): void {
|
|
626
626
|
if (this.enablingDeviceLogging()) {
|
|
627
627
|
this.platform.log.info(String(...log));
|
|
628
628
|
}
|
|
629
629
|
}
|
|
630
630
|
|
|
631
|
-
warnLog(...log: any[]) {
|
|
631
|
+
warnLog(...log: any[]): void {
|
|
632
632
|
if (this.enablingDeviceLogging()) {
|
|
633
633
|
this.platform.log.warn(String(...log));
|
|
634
634
|
}
|
|
635
635
|
}
|
|
636
636
|
|
|
637
|
-
errorLog(...log: any[]) {
|
|
637
|
+
errorLog(...log: any[]): void {
|
|
638
638
|
if (this.enablingDeviceLogging()) {
|
|
639
639
|
this.platform.log.error(String(...log));
|
|
640
640
|
}
|
|
641
641
|
}
|
|
642
642
|
|
|
643
|
-
debugLog(...log: any[]) {
|
|
643
|
+
debugLog(...log: any[]): void {
|
|
644
644
|
if (this.enablingDeviceLogging()) {
|
|
645
645
|
if (this.deviceLogging === 'debug') {
|
|
646
646
|
this.platform.log.info('[DEBUG]', String(...log));
|
|
@@ -10,7 +10,7 @@ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
|
10
10
|
*/
|
|
11
11
|
export class AirPurifier {
|
|
12
12
|
// Services
|
|
13
|
-
|
|
13
|
+
airPurifierService!: Service;
|
|
14
14
|
|
|
15
15
|
// Characteristic Values
|
|
16
16
|
Active!: CharacteristicValue;
|
|
@@ -62,7 +62,7 @@ export class AirPurifier {
|
|
|
62
62
|
|
|
63
63
|
// get the Television service if it exists, otherwise create a new Television service
|
|
64
64
|
// you can create multiple services for each accessory
|
|
65
|
-
(this.
|
|
65
|
+
(this.airPurifierService = accessory.getService(this.platform.Service.AirPurifier) || accessory.addService(this.platform.Service.AirPurifier)),
|
|
66
66
|
`${accessory.displayName} Air Purifier`;
|
|
67
67
|
|
|
68
68
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
@@ -71,19 +71,19 @@ export class AirPurifier {
|
|
|
71
71
|
|
|
72
72
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
73
73
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
74
|
-
this.
|
|
74
|
+
this.airPurifierService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
75
75
|
|
|
76
76
|
// handle on / off events using the Active characteristic
|
|
77
|
-
this.
|
|
77
|
+
this.airPurifierService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
78
78
|
|
|
79
|
-
this.
|
|
79
|
+
this.airPurifierService.getCharacteristic(this.platform.Characteristic.CurrentAirPurifierState).onGet(() => {
|
|
80
80
|
return this.CurrentAirPurifierStateGet();
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
-
this.
|
|
83
|
+
this.airPurifierService.getCharacteristic(this.platform.Characteristic.TargetAirPurifierState).onSet(this.TargetAirPurifierStateSet.bind(this));
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
87
87
|
this.debugLog(`Air Purifier: ${this.accessory.displayName} Set Active: ${value}`);
|
|
88
88
|
if (value === this.platform.Characteristic.Active.INACTIVE) {
|
|
89
89
|
this.pushAirPurifierOffChanges();
|
|
@@ -95,30 +95,30 @@ export class AirPurifier {
|
|
|
95
95
|
this.accessory.context.Active = this.ActiveCached;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
99
99
|
if (this.Active === undefined) {
|
|
100
100
|
this.debugLog(`Air Purifier: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
101
101
|
} else {
|
|
102
|
-
this.
|
|
102
|
+
this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
103
103
|
this.debugLog(`Air Purifier: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
104
104
|
}
|
|
105
105
|
if (this.CurrentAirPurifierState === undefined) {
|
|
106
106
|
this.debugLog(`Air Purifier: ${this.accessory.displayName} CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
|
|
107
107
|
} else {
|
|
108
|
-
this.
|
|
108
|
+
this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, this.CurrentAirPurifierState);
|
|
109
109
|
this.debugLog(`Air Purifier: ${this.accessory.displayName}` + ` updateCharacteristic CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
|
|
110
110
|
}
|
|
111
111
|
if (this.CurrentHeaterCoolerState === undefined) {
|
|
112
112
|
this.debugLog(`Air Purifier: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
113
113
|
} else {
|
|
114
|
-
this.
|
|
114
|
+
this.airPurifierService?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
|
|
115
115
|
this.debugLog(
|
|
116
116
|
`Air Purifier: ${this.accessory.displayName}` + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
|
|
117
117
|
);
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
async TargetAirPurifierStateSet(value: CharacteristicValue): Promise<void> {
|
|
122
122
|
switch (value) {
|
|
123
123
|
case this.platform.Characteristic.CurrentAirPurifierState.PURIFYING_AIR:
|
|
124
124
|
this.CurrentMode = AirPurifier.PURIFYING_AIR;
|
|
@@ -134,7 +134,7 @@ export class AirPurifier {
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
async CurrentAirPurifierStateGet(): Promise<number> {
|
|
138
138
|
if (this.Active === 1) {
|
|
139
139
|
this.CurrentAirPurifierState = this.platform.Characteristic.CurrentAirPurifierState.PURIFYING_AIR;
|
|
140
140
|
} else {
|
|
@@ -154,7 +154,7 @@ export class AirPurifier {
|
|
|
154
154
|
* AirPurifier: "command" "middleSpeed" "default" = fan speed to medium
|
|
155
155
|
* AirPurifier: "command" "highSpeed" "default" = fan speed to high
|
|
156
156
|
*/
|
|
157
|
-
async pushAirPurifierOnChanges() {
|
|
157
|
+
async pushAirPurifierOnChanges(): Promise<void> {
|
|
158
158
|
if (this.Active !== 1) {
|
|
159
159
|
const payload = {
|
|
160
160
|
commandType: 'command',
|
|
@@ -165,7 +165,7 @@ export class AirPurifier {
|
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
async pushAirPurifierOffChanges() {
|
|
168
|
+
async pushAirPurifierOffChanges(): Promise<void> {
|
|
169
169
|
if (this.Active !== 0) {
|
|
170
170
|
const payload = {
|
|
171
171
|
commandType: 'command',
|
|
@@ -176,7 +176,7 @@ export class AirPurifier {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
async pushAirConditionerStatusChanges() {
|
|
179
|
+
async pushAirConditionerStatusChanges(): Promise<void> {
|
|
180
180
|
if (!this.Busy) {
|
|
181
181
|
this.Busy = true;
|
|
182
182
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.IDLE;
|
|
@@ -187,7 +187,7 @@ export class AirPurifier {
|
|
|
187
187
|
this.Timeout = setTimeout(this.pushAirConditionerDetailsChanges.bind(this), 1500);
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
async pushAirConditionerDetailsChanges() {
|
|
190
|
+
async pushAirConditionerDetailsChanges(): Promise<void> {
|
|
191
191
|
const payload = {
|
|
192
192
|
commandType: 'command',
|
|
193
193
|
command: 'setAll',
|
|
@@ -212,7 +212,7 @@ export class AirPurifier {
|
|
|
212
212
|
await this.pushChanges(payload);
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
|
|
215
|
+
async pushChanges(payload: payload): Promise<void> {
|
|
216
216
|
try {
|
|
217
217
|
this.infoLog(
|
|
218
218
|
`Air Purifier: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
@@ -240,7 +240,7 @@ export class AirPurifier {
|
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
-
|
|
243
|
+
async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void> {
|
|
244
244
|
switch (push.data.statusCode) {
|
|
245
245
|
case 151:
|
|
246
246
|
this.errorLog(`Air Purifier: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
@@ -271,15 +271,15 @@ export class AirPurifier {
|
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
-
|
|
275
|
-
this.
|
|
276
|
-
this.
|
|
277
|
-
this.
|
|
278
|
-
this.
|
|
274
|
+
async apiError(e: any): Promise<void> {
|
|
275
|
+
this.airPurifierService.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, e);
|
|
276
|
+
this.airPurifierService.updateCharacteristic(this.platform.Characteristic.CurrentAirPurifierState, e);
|
|
277
|
+
this.airPurifierService.updateCharacteristic(this.platform.Characteristic.TargetAirPurifierState, e);
|
|
278
|
+
this.airPurifierService.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
279
279
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
-
config(device: irdevice & irDevicesConfig) {
|
|
282
|
+
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
283
283
|
let config = {};
|
|
284
284
|
if (device.irpur) {
|
|
285
285
|
config = device.irpur;
|
|
@@ -292,7 +292,7 @@ export class AirPurifier {
|
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
-
logs(device: irdevice & irDevicesConfig) {
|
|
295
|
+
async logs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
296
296
|
if (this.platform.debugMode) {
|
|
297
297
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
298
298
|
this.debugLog(`Air Purifier: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -311,25 +311,25 @@ export class AirPurifier {
|
|
|
311
311
|
/**
|
|
312
312
|
* Logging for Device
|
|
313
313
|
*/
|
|
314
|
-
infoLog(...log: any[]) {
|
|
314
|
+
infoLog(...log: any[]): void {
|
|
315
315
|
if (this.enablingDeviceLogging()) {
|
|
316
316
|
this.platform.log.info(String(...log));
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
|
|
320
|
-
warnLog(...log: any[]) {
|
|
320
|
+
warnLog(...log: any[]): void {
|
|
321
321
|
if (this.enablingDeviceLogging()) {
|
|
322
322
|
this.platform.log.warn(String(...log));
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
-
errorLog(...log: any[]) {
|
|
326
|
+
errorLog(...log: any[]): void {
|
|
327
327
|
if (this.enablingDeviceLogging()) {
|
|
328
328
|
this.platform.log.error(String(...log));
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
debugLog(...log: any[]) {
|
|
332
|
+
debugLog(...log: any[]): void {
|
|
333
333
|
if (this.enablingDeviceLogging()) {
|
|
334
334
|
if (this.deviceLogging === 'debug') {
|
|
335
335
|
this.platform.log.info('[DEBUG]', String(...log));
|