@switchbot/homebridge-switchbot 2.0.0-beta.9 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -1
- package/README.md +3 -2
- package/config.schema.json +91 -19
- package/dist/device/bot.d.ts +34 -28
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +657 -648
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +137 -0
- package/dist/device/ceilinglight.d.ts.map +1 -0
- package/dist/device/ceilinglight.js +1127 -0
- package/dist/device/ceilinglight.js.map +1 -0
- package/dist/device/colorbulb.d.ts +36 -14
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +472 -297
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +18 -8
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +306 -237
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +23 -16
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +566 -502
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +24 -18
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +453 -369
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +27 -8
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +305 -148
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +22 -16
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +367 -267
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +24 -12
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +381 -213
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +18 -8
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +279 -216
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +27 -17
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +295 -251
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +43 -19
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +506 -262
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +9 -12
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +278 -230
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +5 -3
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +154 -104
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +11 -8
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +133 -86
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +10 -7
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +160 -109
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +11 -8
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +137 -103
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +11 -8
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +145 -98
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +12 -9
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +143 -93
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +9 -10
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +132 -89
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +8 -9
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +132 -89
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +13 -12
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +524 -418
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +19 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/homebridge-ui/public/index.html +1 -0
- package/package.json +11 -9
- package/src/device/bot.ts +656 -659
- package/src/device/ceilinglight.ts +1208 -0
- package/src/device/colorbulb.ts +482 -334
- package/src/device/contact.ts +309 -241
- package/src/device/curtain.ts +571 -516
- package/src/device/humidifier.ts +456 -403
- package/src/device/lock.ts +314 -149
- package/src/device/meter.ts +378 -280
- package/src/device/meterplus.ts +391 -219
- package/src/device/motion.ts +285 -222
- package/src/device/plug.ts +299 -260
- package/src/device/striplight.ts +522 -289
- package/src/irdevice/airconditioner.ts +282 -241
- package/src/irdevice/airpurifier.ts +151 -103
- package/src/irdevice/camera.ts +131 -85
- package/src/irdevice/fan.ts +157 -106
- package/src/irdevice/light.ts +135 -103
- package/src/irdevice/other.ts +143 -97
- package/src/irdevice/tv.ts +142 -93
- package/src/irdevice/vacuumcleaner.ts +131 -89
- package/src/irdevice/waterheater.ts +130 -89
- package/src/platform.ts +522 -446
- package/src/settings.ts +20 -11
- package/.github/npm-version-script.js +0 -81
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import https from 'https';
|
|
2
2
|
import crypto from 'crypto';
|
|
3
3
|
import { IncomingMessage } from 'http';
|
|
4
|
+
import superStringify from 'super-stringify';
|
|
4
5
|
import { SwitchBotPlatform } from '../platform';
|
|
5
6
|
import { irDevicesConfig, irdevice, HostDomain, DevicePath } from '../settings';
|
|
6
7
|
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
@@ -16,19 +17,12 @@ export class AirConditioner {
|
|
|
16
17
|
|
|
17
18
|
// Characteristic Values
|
|
18
19
|
Active!: CharacteristicValue;
|
|
19
|
-
ActiveCached!: CharacteristicValue;
|
|
20
20
|
RotationSpeed!: CharacteristicValue;
|
|
21
|
-
RotationSpeedCached!: CharacteristicValue;
|
|
22
21
|
CurrentTemperature!: CharacteristicValue;
|
|
23
|
-
CurrentTemperatureCached!: CharacteristicValue;
|
|
24
22
|
TargetHeaterCoolerState!: CharacteristicValue;
|
|
25
|
-
TargetHeaterCoolerStateCached!: CharacteristicValue;
|
|
26
23
|
CurrentHeaterCoolerState!: CharacteristicValue;
|
|
27
|
-
CurrentHeaterCoolerStateCached!: CharacteristicValue;
|
|
28
24
|
HeatingThresholdTemperature!: CharacteristicValue;
|
|
29
|
-
HeatingThresholdTemperatureCached!: CharacteristicValue;
|
|
30
25
|
CoolingThresholdTemperature!: CharacteristicValue;
|
|
31
|
-
CoolingThresholdTemperatureCached!: CharacteristicValue;
|
|
32
26
|
|
|
33
27
|
// Others
|
|
34
28
|
state!: string;
|
|
@@ -54,30 +48,17 @@ export class AirConditioner {
|
|
|
54
48
|
this.logs(device);
|
|
55
49
|
this.config(device);
|
|
56
50
|
this.pushOnChanges(device);
|
|
57
|
-
|
|
58
|
-
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
59
|
-
} else {
|
|
60
|
-
this.Active = this.accessory.context.Active;
|
|
61
|
-
}
|
|
62
|
-
if (this.CurrentTemperature === undefined) {
|
|
63
|
-
this.CurrentTemperature = 24;
|
|
64
|
-
} else {
|
|
65
|
-
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
66
|
-
}
|
|
67
|
-
if (device.irair?.hide_automode) {
|
|
68
|
-
this.hide_automode = device.irair?.hide_automode;
|
|
69
|
-
this.accessory.context.hide_automode = this.hide_automode;
|
|
70
|
-
} else {
|
|
71
|
-
this.hide_automode = device.irair?.hide_automode;
|
|
72
|
-
this.accessory.context.hide_automode = this.hide_automode;
|
|
73
|
-
}
|
|
51
|
+
this.context(device);
|
|
74
52
|
|
|
75
53
|
// set accessory information
|
|
76
54
|
accessory
|
|
77
55
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
78
56
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
79
57
|
.setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
|
|
80
|
-
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
58
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
59
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
60
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
61
|
+
.updateValue(this.FirmwareRevision(accessory, device));
|
|
81
62
|
|
|
82
63
|
// get the Television service if it exists, otherwise create a new Television service
|
|
83
64
|
// you can create multiple services for each accessory
|
|
@@ -110,14 +91,14 @@ export class AirConditioner {
|
|
|
110
91
|
this.TargetHeaterCoolerState = 1 || 2;
|
|
111
92
|
this.ValidValues = [1, 2];
|
|
112
93
|
this.debugLog(
|
|
113
|
-
|
|
94
|
+
`${this.device.remoteType}: ${this.accessory.displayName} ValidValues: ${superStringify(this.ValidValues)},` +
|
|
114
95
|
` hide_automode: ${this.hide_automode}, TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`,
|
|
115
96
|
);
|
|
116
97
|
} else {
|
|
117
98
|
this.TargetHeaterCoolerState = 0 || 1 || 2;
|
|
118
99
|
this.ValidValues = [0, 1, 2];
|
|
119
100
|
this.debugLog(
|
|
120
|
-
|
|
101
|
+
`${this.device.remoteType}: ${this.accessory.displayName} ValidValues: ${superStringify(this.ValidValues)},` +
|
|
121
102
|
` hide_automode: ${this.hide_automode}, TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`,
|
|
122
103
|
);
|
|
123
104
|
}
|
|
@@ -183,7 +164,7 @@ export class AirConditioner {
|
|
|
183
164
|
*/
|
|
184
165
|
async pushAirConditionerOnChanges(): Promise<void> {
|
|
185
166
|
if (this.Active !== this.platform.Characteristic.Active.ACTIVE || this.pushOn) {
|
|
186
|
-
const body =
|
|
167
|
+
const body = superStringify({
|
|
187
168
|
'command': 'turnOn',
|
|
188
169
|
'parameter': 'default',
|
|
189
170
|
'commandType': 'command',
|
|
@@ -193,7 +174,7 @@ export class AirConditioner {
|
|
|
193
174
|
}
|
|
194
175
|
|
|
195
176
|
async pushAirConditionerOffChanges(): Promise<void> {
|
|
196
|
-
const body =
|
|
177
|
+
const body = superStringify({
|
|
197
178
|
'command': 'turnOff',
|
|
198
179
|
'parameter': 'default',
|
|
199
180
|
'commandType': 'command',
|
|
@@ -228,22 +209,23 @@ export class AirConditioner {
|
|
|
228
209
|
if (this.CurrentMode === 1) {
|
|
229
210
|
this.CurrentTemperature = 25;
|
|
230
211
|
this.debugLog(
|
|
231
|
-
|
|
212
|
+
`${this.device.remoteType}: ${this.accessory.displayName} CurrentMode: ${this.CurrentMode},`
|
|
213
|
+
+ ` CurrentTemperature: ${this.CurrentTemperature}`,
|
|
232
214
|
);
|
|
233
215
|
}
|
|
234
216
|
const parameter = `${this.CurrentTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`;
|
|
235
217
|
|
|
236
218
|
if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
237
219
|
this.CurrentTemperatureUndefined();
|
|
238
|
-
if (this.CurrentTemperature < this.
|
|
220
|
+
if (this.CurrentTemperature < this.accessory.context.CurrentTemperature) {
|
|
239
221
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
|
|
240
|
-
} else if (this.CurrentTemperature > this.
|
|
222
|
+
} else if (this.CurrentTemperature > this.accessory.context.CurrentTemperature) {
|
|
241
223
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
|
|
242
224
|
}
|
|
243
225
|
} else {
|
|
244
226
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
|
|
245
227
|
}
|
|
246
|
-
const body =
|
|
228
|
+
const body = superStringify({
|
|
247
229
|
'command': 'setAll',
|
|
248
230
|
'parameter': `${parameter}`,
|
|
249
231
|
'commandType': 'command',
|
|
@@ -253,166 +235,72 @@ export class AirConditioner {
|
|
|
253
235
|
}
|
|
254
236
|
|
|
255
237
|
async pushChanges(body): Promise<void> {
|
|
256
|
-
|
|
238
|
+
if (this.device.connectionType === 'OpenAPI') {
|
|
239
|
+
try {
|
|
257
240
|
// Make Push On request to the API
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
241
|
+
const t = Date.now();
|
|
242
|
+
const nonce = 'requestID';
|
|
243
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
244
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
245
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
246
|
+
.digest();
|
|
247
|
+
const sign = signTerm.toString('base64');
|
|
248
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
249
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
250
|
+
const options = {
|
|
251
|
+
hostname: HostDomain,
|
|
252
|
+
port: 443,
|
|
253
|
+
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
254
|
+
method: 'POST',
|
|
255
|
+
headers: {
|
|
256
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
257
|
+
'sign': sign,
|
|
258
|
+
'nonce': nonce,
|
|
259
|
+
't': t,
|
|
260
|
+
'Content-Type': 'application/json',
|
|
261
|
+
'Content-Length': body.length,
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
const req = https.request(options, res => {
|
|
265
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges statusCode: ${res.statusCode}`);
|
|
266
|
+
this.statusCode({ res });
|
|
267
|
+
res.on('data', d => {
|
|
268
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
|
|
269
|
+
});
|
|
286
270
|
});
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
} catch (e: any) {
|
|
304
|
-
this.errorLog(`Air Conditioner: ${this.accessory.displayName} failed pushChanges`);
|
|
305
|
-
if (this.deviceLogging.includes('debug')) {
|
|
306
|
-
this.errorLog(`Air Conditioner: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
307
|
-
}
|
|
308
|
-
this.apiError(e);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
|
|
313
|
-
switch (res.statusCode) {
|
|
314
|
-
case 151:
|
|
315
|
-
this.errorLog(`Air Conditioner: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
316
|
-
break;
|
|
317
|
-
case 152:
|
|
318
|
-
this.errorLog(`Air Conditioner: ${this.accessory.displayName} Device not found.`);
|
|
319
|
-
break;
|
|
320
|
-
case 160:
|
|
321
|
-
this.errorLog(`Air Conditioner: ${this.accessory.displayName} Command is not supported.`);
|
|
322
|
-
break;
|
|
323
|
-
case 161:
|
|
324
|
-
this.errorLog(`Air Conditioner: ${this.accessory.displayName} Device is offline.`);
|
|
325
|
-
break;
|
|
326
|
-
case 171:
|
|
327
|
-
this.errorLog(`Air Conditioner: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
328
|
-
break;
|
|
329
|
-
case 190:
|
|
330
|
-
this.errorLog(
|
|
331
|
-
`Air Conditioner: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
|
|
332
|
-
` with server, Or command: ${JSON.stringify(res)} format is invalid`,
|
|
271
|
+
req.on('error', (e: any) => {
|
|
272
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
273
|
+
});
|
|
274
|
+
req.write(body);
|
|
275
|
+
req.end();
|
|
276
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
|
|
277
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
278
|
+
this.HeatingThresholdTemperature = this.CurrentTemperature;
|
|
279
|
+
this.CoolingThresholdTemperature = this.CurrentTemperature;
|
|
280
|
+
this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
|
|
281
|
+
this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
|
|
282
|
+
this.updateHomeKitCharacteristics();
|
|
283
|
+
} catch (e: any) {
|
|
284
|
+
this.apiError(e);
|
|
285
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
|
|
286
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
333
287
|
);
|
|
334
|
-
|
|
335
|
-
case 100:
|
|
336
|
-
this.debugLog(`Air Conditioner: ${this.accessory.displayName} Command successfully sent.`);
|
|
337
|
-
break;
|
|
338
|
-
default:
|
|
339
|
-
this.debugLog(`Air Conditioner: ${this.accessory.displayName} Unknown statusCode.`);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
async updateHomeKitCharacteristics(): Promise<void> {
|
|
344
|
-
if (this.Active === undefined) {
|
|
345
|
-
this.debugLog(`Air Conditioner: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
346
|
-
} else {
|
|
347
|
-
this.coolerService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
348
|
-
this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
349
|
-
}
|
|
350
|
-
if (this.RotationSpeed === undefined) {
|
|
351
|
-
this.debugLog(`Air Conditioner: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
|
|
352
|
-
} else {
|
|
353
|
-
this.coolerService?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
|
|
354
|
-
this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
|
|
355
|
-
}
|
|
356
|
-
if (this.CurrentTemperature === undefined) {
|
|
357
|
-
this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
358
|
-
} else {
|
|
359
|
-
this.coolerService?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
360
|
-
this.debugLog(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
361
|
-
}
|
|
362
|
-
if (this.TargetHeaterCoolerState === undefined) {
|
|
363
|
-
this.debugLog(`Air Conditioner: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
|
|
364
|
-
} else {
|
|
365
|
-
this.coolerService?.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
|
|
366
|
-
this.debugLog(
|
|
367
|
-
`Air Conditioner: ${this.accessory.displayName}` + ` updateCharacteristic TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`,
|
|
368
|
-
);
|
|
369
|
-
}
|
|
370
|
-
if (this.CurrentHeaterCoolerState === undefined) {
|
|
371
|
-
this.debugLog(`Air Conditioner: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
372
|
-
} else {
|
|
373
|
-
this.coolerService?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
|
|
374
|
-
this.debugLog(
|
|
375
|
-
`Air Conditioner: ${this.accessory.displayName}` + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
if (this.HeatingThresholdTemperature === undefined) {
|
|
379
|
-
this.debugLog(`Air Conditioner: ${this.accessory.displayName} HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
|
|
380
|
-
} else {
|
|
381
|
-
this.coolerService?.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.HeatingThresholdTemperature);
|
|
382
|
-
this.debugLog(
|
|
383
|
-
`Air Conditioner: ${this.accessory.displayName}` + ` updateCharacteristic HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`,
|
|
384
|
-
);
|
|
385
|
-
}
|
|
386
|
-
if (this.CoolingThresholdTemperature === undefined) {
|
|
387
|
-
this.debugLog(`Air Conditioner: ${this.accessory.displayName} CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`);
|
|
288
|
+
}
|
|
388
289
|
} else {
|
|
389
|
-
this.
|
|
390
|
-
this.
|
|
391
|
-
`Air Conditioner: ${this.accessory.displayName}` + ` updateCharacteristic CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`,
|
|
392
|
-
);
|
|
290
|
+
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
291
|
+
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
393
292
|
}
|
|
394
293
|
}
|
|
395
294
|
|
|
396
|
-
async apiError(e: any): Promise<void> {
|
|
397
|
-
this.coolerService.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
398
|
-
this.coolerService.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
|
|
399
|
-
this.coolerService.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
|
|
400
|
-
this.coolerService.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, e);
|
|
401
|
-
this.coolerService.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, e);
|
|
402
|
-
this.coolerService.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, e);
|
|
403
|
-
this.coolerService.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, e);
|
|
404
|
-
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
295
|
async CurrentTemperatureGet(): Promise<CharacteristicValue> {
|
|
408
296
|
if (this.CurrentTemperature === undefined) {
|
|
409
297
|
this.CurrentTemperature = 24;
|
|
410
|
-
this.
|
|
298
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
411
299
|
} else {
|
|
412
|
-
this.
|
|
300
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
413
301
|
}
|
|
414
|
-
this.debugLog(
|
|
415
|
-
this.accessory.context.CurrentTemperature = this.
|
|
302
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get CurrentTemperature: ${this.CurrentTemperature}`);
|
|
303
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
416
304
|
return this.CurrentTemperature;
|
|
417
305
|
}
|
|
418
306
|
|
|
@@ -424,9 +312,8 @@ export class AirConditioner {
|
|
|
424
312
|
} else {
|
|
425
313
|
this.RotationSpeed = this.CurrentFanSpeed - 1;
|
|
426
314
|
}
|
|
427
|
-
this.debugLog(
|
|
428
|
-
this.
|
|
429
|
-
this.accessory.context.RotationSpeed = this.RotationSpeedCached;
|
|
315
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get RotationSpeed: ${this.RotationSpeed}`);
|
|
316
|
+
this.accessory.context.RotationSpeed = this.RotationSpeed;
|
|
430
317
|
return this.RotationSpeed;
|
|
431
318
|
}
|
|
432
319
|
|
|
@@ -437,23 +324,19 @@ export class AirConditioner {
|
|
|
437
324
|
this.CurrentFanSpeed = Number(value) + 1;
|
|
438
325
|
}
|
|
439
326
|
this.RotationSpeed = this.CurrentFanSpeed;
|
|
440
|
-
this.
|
|
441
|
-
this.accessory.context.RotationSpeed = this.RotationSpeedCached;
|
|
327
|
+
this.accessory.context.RotationSpeed = this.RotationSpeed;
|
|
442
328
|
this.pushAirConditionerStatusChanges();
|
|
443
329
|
}
|
|
444
330
|
|
|
445
331
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
446
|
-
this.debugLog(
|
|
447
|
-
|
|
332
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
|
|
448
333
|
this.Active = value;
|
|
449
|
-
this.
|
|
450
|
-
this.accessory.context.Active = this.ActiveCached;
|
|
451
|
-
|
|
334
|
+
this.accessory.context.Active = this.Active;
|
|
452
335
|
if (value === this.platform.Characteristic.Active.INACTIVE) {
|
|
453
|
-
this.debugLog(
|
|
336
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
|
|
454
337
|
this.pushAirConditionerOffChanges();
|
|
455
338
|
} else {
|
|
456
|
-
this.debugLog(
|
|
339
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges, Active: ${this.Active}`);
|
|
457
340
|
if (this.pushOn) {
|
|
458
341
|
this.pushAirConditionerOnChanges();
|
|
459
342
|
} else {
|
|
@@ -466,24 +349,23 @@ export class AirConditioner {
|
|
|
466
349
|
if (this.ValidValues === this.valid012) {
|
|
467
350
|
this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
|
|
468
351
|
this.debugLog(
|
|
469
|
-
|
|
352
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Get (AUTO) TargetHeaterCoolerState: ${this.CurrentHeaterCoolerState},` +
|
|
470
353
|
` ValidValues: ${this.ValidValues}`,
|
|
471
354
|
);
|
|
472
355
|
} else if (this.ValidValues === this.valid12) {
|
|
473
356
|
this.TargetHeaterCoolerState =
|
|
474
357
|
this.platform.Characteristic.TargetHeaterCoolerState.COOL || this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
|
|
475
358
|
this.debugLog(
|
|
476
|
-
|
|
359
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Get (COOL/HEAT) TargetHeaterCoolerState: ${this.CurrentHeaterCoolerState},` +
|
|
477
360
|
` ValidValues: ${this.ValidValues}`,
|
|
478
361
|
);
|
|
479
362
|
} else {
|
|
480
363
|
this.debugLog(
|
|
481
|
-
|
|
364
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Get TargetHeaterCoolerState: ${this.CurrentHeaterCoolerState},` +
|
|
482
365
|
` ValidValues: ${this.ValidValues}`,
|
|
483
366
|
);
|
|
484
367
|
}
|
|
485
|
-
this.
|
|
486
|
-
this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerStateCached;
|
|
368
|
+
this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerState;
|
|
487
369
|
return this.TargetHeaterCoolerState;
|
|
488
370
|
}
|
|
489
371
|
|
|
@@ -495,7 +377,7 @@ export class AirConditioner {
|
|
|
495
377
|
this.TargetHeaterCoolerStateCOOL();
|
|
496
378
|
} else {
|
|
497
379
|
this.errorLog(
|
|
498
|
-
|
|
380
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set TargetHeaterCoolerState: ${this.TargetHeaterCoolerState},` +
|
|
499
381
|
` hide_automode: ${this.hide_automode} `,
|
|
500
382
|
);
|
|
501
383
|
}
|
|
@@ -508,96 +390,93 @@ export class AirConditioner {
|
|
|
508
390
|
this.TargetHeaterCoolerStateCOOL();
|
|
509
391
|
} else {
|
|
510
392
|
this.errorLog(
|
|
511
|
-
|
|
393
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set TargetHeaterCoolerState: ${this.TargetHeaterCoolerState},` +
|
|
512
394
|
` hide_automode: ${this.hide_automode} `,
|
|
513
395
|
);
|
|
514
396
|
}
|
|
515
397
|
}
|
|
516
|
-
this.
|
|
517
|
-
this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerStateCached;
|
|
398
|
+
this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerState;
|
|
518
399
|
this.pushAirConditionerStatusChanges();
|
|
519
400
|
}
|
|
520
401
|
|
|
521
402
|
async TargetHeaterCoolerStateAUTO(): Promise<void> {
|
|
522
403
|
this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
|
|
523
404
|
this.CurrentMode = 1;
|
|
524
|
-
this.debugLog(
|
|
525
|
-
this.debugLog(
|
|
405
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (AUTO) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
|
|
406
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
|
|
526
407
|
}
|
|
527
408
|
|
|
528
409
|
async TargetHeaterCoolerStateCOOL(): Promise<void> {
|
|
529
410
|
this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.COOL;
|
|
530
411
|
this.CurrentMode = 2;
|
|
531
|
-
this.debugLog(
|
|
532
|
-
this.debugLog(
|
|
412
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (COOL) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
|
|
413
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
|
|
533
414
|
}
|
|
534
415
|
|
|
535
416
|
async TargetHeaterCoolerStateHEAT(): Promise<void> {
|
|
536
417
|
this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
|
|
537
418
|
this.CurrentMode = 5;
|
|
538
|
-
this.debugLog(
|
|
539
|
-
this.debugLog(
|
|
419
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (HEAT) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
|
|
420
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
|
|
540
421
|
}
|
|
541
422
|
|
|
542
423
|
async CurrentHeaterCoolerStateGet(): Promise<CharacteristicValue> {
|
|
543
424
|
if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
544
425
|
this.CurrentTemperatureUndefined();
|
|
545
|
-
if (this.CurrentTemperature < this.
|
|
426
|
+
if (this.CurrentTemperature < this.accessory.context.CurrentTemperature) {
|
|
546
427
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
|
|
547
|
-
this.debugLog(
|
|
548
|
-
|
|
428
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
429
|
+
+` Get (COOLLING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
430
|
+
} else if (this.CurrentTemperature > this.accessory.context.CurrentTemperature) {
|
|
549
431
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
|
|
550
|
-
this.debugLog(
|
|
432
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
433
|
+
+` Get (HEATING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
551
434
|
}
|
|
552
435
|
} else {
|
|
553
436
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
|
|
554
|
-
this.debugLog(
|
|
437
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
438
|
+
+` Get (INACTIVE) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
555
439
|
}
|
|
556
|
-
this.
|
|
557
|
-
this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerStateCached;
|
|
440
|
+
this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
|
|
558
441
|
return this.CurrentHeaterCoolerState;
|
|
559
442
|
}
|
|
560
443
|
|
|
561
444
|
async HeatingThresholdTemperatureGet(): Promise<CharacteristicValue> {
|
|
562
445
|
this.CurrentTemperatureUndefined;
|
|
563
|
-
this.CurrentTemperature = this.
|
|
564
|
-
this.HeatingThresholdTemperature = this.
|
|
565
|
-
this.
|
|
566
|
-
this.accessory.
|
|
567
|
-
this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
|
|
446
|
+
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
447
|
+
this.HeatingThresholdTemperature = this.accessory.context.CurrentTemperature;
|
|
448
|
+
this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
|
|
449
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
|
|
568
450
|
return this.HeatingThresholdTemperature;
|
|
569
451
|
}
|
|
570
452
|
|
|
571
453
|
async HeatingThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
|
|
572
|
-
this.
|
|
454
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
573
455
|
this.CurrentTemperature = value;
|
|
574
|
-
this.
|
|
575
|
-
this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperatureCached;
|
|
456
|
+
this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
|
|
576
457
|
this.debugLog(
|
|
577
|
-
|
|
578
|
-
` CurrentTemperatureCached: ${this.
|
|
458
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set HeatingThresholdTemperature: ${this.HeatingThresholdTemperature},` +
|
|
459
|
+
` CurrentTemperatureCached: ${this.accessory.context.CurrentTemperature}`,
|
|
579
460
|
);
|
|
580
461
|
this.pushAirConditionerStatusChanges();
|
|
581
462
|
}
|
|
582
463
|
|
|
583
464
|
async CoolingThresholdTemperatureGet(): Promise<CharacteristicValue> {
|
|
584
465
|
this.CurrentTemperatureUndefined;
|
|
585
|
-
this.CurrentTemperature = this.
|
|
586
|
-
this.CoolingThresholdTemperature = this.
|
|
587
|
-
this.
|
|
588
|
-
this.accessory.
|
|
589
|
-
this.debugLog(`Air Conditioner: ${this.accessory.displayName} Get CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`);
|
|
466
|
+
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
467
|
+
this.CoolingThresholdTemperature = this.accessory.context.CurrentTemperature;
|
|
468
|
+
this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
|
|
469
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`);
|
|
590
470
|
return this.CoolingThresholdTemperature;
|
|
591
471
|
}
|
|
592
472
|
|
|
593
473
|
async CoolingThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
|
|
594
|
-
this.
|
|
474
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
595
475
|
this.CurrentTemperature = value;
|
|
596
|
-
this.
|
|
597
|
-
this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperatureCached;
|
|
476
|
+
this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
|
|
598
477
|
this.debugLog(
|
|
599
|
-
|
|
600
|
-
` CurrentTemperatureCached: ${this.
|
|
478
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set CoolingThresholdTemperature: ${this.CoolingThresholdTemperature},` +
|
|
479
|
+
` CurrentTemperatureCached: ${this.accessory.context.CurrentTemperature}`,
|
|
601
480
|
);
|
|
602
481
|
this.pushAirConditionerStatusChanges();
|
|
603
482
|
}
|
|
@@ -606,11 +485,151 @@ export class AirConditioner {
|
|
|
606
485
|
if (this.CurrentTemperature === undefined) {
|
|
607
486
|
this.CurrentTemperature = 24;
|
|
608
487
|
}
|
|
609
|
-
if (this.
|
|
488
|
+
if (this.accessory.context.CurrentTemperature === undefined) {
|
|
610
489
|
this.CurrentTemperature = 30;
|
|
611
490
|
}
|
|
612
491
|
}
|
|
613
492
|
|
|
493
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
494
|
+
if (this.Active === undefined) {
|
|
495
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
496
|
+
} else {
|
|
497
|
+
this.accessory.context.Active = this.Active;
|
|
498
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
499
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
500
|
+
}
|
|
501
|
+
if (this.RotationSpeed === undefined) {
|
|
502
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
|
|
503
|
+
} else {
|
|
504
|
+
this.accessory.context.RotationSpeed = this.RotationSpeed;
|
|
505
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
|
|
506
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
|
|
507
|
+
}
|
|
508
|
+
if (this.CurrentTemperature === undefined) {
|
|
509
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
510
|
+
} else {
|
|
511
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
512
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
513
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
514
|
+
}
|
|
515
|
+
if (this.TargetHeaterCoolerState === undefined) {
|
|
516
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
|
|
517
|
+
} else {
|
|
518
|
+
this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerState;
|
|
519
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
|
|
520
|
+
this.debugLog(
|
|
521
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`,
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
if (this.CurrentHeaterCoolerState === undefined) {
|
|
525
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
526
|
+
} else {
|
|
527
|
+
this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
|
|
528
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
|
|
529
|
+
this.debugLog(
|
|
530
|
+
`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
531
|
+
+ ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
if (this.HeatingThresholdTemperature === undefined) {
|
|
535
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
|
|
536
|
+
} else {
|
|
537
|
+
this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
|
|
538
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.HeatingThresholdTemperature);
|
|
539
|
+
this.debugLog(
|
|
540
|
+
`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
541
|
+
+ ` updateCharacteristic HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`,
|
|
542
|
+
);
|
|
543
|
+
}
|
|
544
|
+
if (this.CoolingThresholdTemperature === undefined) {
|
|
545
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`);
|
|
546
|
+
} else {
|
|
547
|
+
this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
|
|
548
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, this.CoolingThresholdTemperature);
|
|
549
|
+
this.debugLog(
|
|
550
|
+
`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
551
|
+
+ ` updateCharacteristic CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`,
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
|
|
557
|
+
switch (res.statusCode) {
|
|
558
|
+
case 151:
|
|
559
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
560
|
+
break;
|
|
561
|
+
case 152:
|
|
562
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found.`);
|
|
563
|
+
break;
|
|
564
|
+
case 160:
|
|
565
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported.`);
|
|
566
|
+
break;
|
|
567
|
+
case 161:
|
|
568
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline.`);
|
|
569
|
+
break;
|
|
570
|
+
case 171:
|
|
571
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
572
|
+
break;
|
|
573
|
+
case 190:
|
|
574
|
+
this.errorLog(
|
|
575
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
|
|
576
|
+
` with server, Or command: ${superStringify(res)} format is invalid`,
|
|
577
|
+
);
|
|
578
|
+
break;
|
|
579
|
+
case 100:
|
|
580
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
581
|
+
break;
|
|
582
|
+
default:
|
|
583
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
async apiError(e: any): Promise<void> {
|
|
588
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
589
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
|
|
590
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
|
|
591
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, e);
|
|
592
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, e);
|
|
593
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, e);
|
|
594
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, e);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
|
|
598
|
+
let FirmwareRevision: string;
|
|
599
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
600
|
+
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
601
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
602
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
603
|
+
if (accessory.context.FirmwareRevision) {
|
|
604
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
605
|
+
} else if (device.firmware) {
|
|
606
|
+
FirmwareRevision = device.firmware;
|
|
607
|
+
} else {
|
|
608
|
+
FirmwareRevision = this.platform.version;
|
|
609
|
+
}
|
|
610
|
+
return FirmwareRevision;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
async context(device: irdevice & irDevicesConfig) {
|
|
614
|
+
if (this.Active === undefined) {
|
|
615
|
+
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
616
|
+
} else {
|
|
617
|
+
this.Active = this.accessory.context.Active;
|
|
618
|
+
}
|
|
619
|
+
if (this.CurrentTemperature === undefined) {
|
|
620
|
+
this.CurrentTemperature = 24;
|
|
621
|
+
} else {
|
|
622
|
+
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
623
|
+
}
|
|
624
|
+
if (device.irair?.hide_automode) {
|
|
625
|
+
this.hide_automode = device.irair?.hide_automode;
|
|
626
|
+
this.accessory.context.hide_automode = this.hide_automode;
|
|
627
|
+
} else {
|
|
628
|
+
this.hide_automode = device.irair?.hide_automode;
|
|
629
|
+
this.accessory.context.hide_automode = this.hide_automode;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
614
633
|
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
615
634
|
let config = {};
|
|
616
635
|
if (device.irair) {
|
|
@@ -619,24 +638,30 @@ export class AirConditioner {
|
|
|
619
638
|
if (device.logging !== undefined) {
|
|
620
639
|
config['logging'] = device.logging;
|
|
621
640
|
}
|
|
641
|
+
if (device.connectionType !== undefined) {
|
|
642
|
+
config['connectionType'] = device.connectionType;
|
|
643
|
+
}
|
|
644
|
+
if (device.external !== undefined) {
|
|
645
|
+
config['external'] = device.external;
|
|
646
|
+
}
|
|
622
647
|
if (Object.entries(config).length !== 0) {
|
|
623
|
-
this.infoLog(
|
|
648
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
624
649
|
}
|
|
625
650
|
}
|
|
626
651
|
|
|
627
652
|
async logs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
628
653
|
if (this.platform.debugMode) {
|
|
629
654
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
630
|
-
this.debugLog(
|
|
655
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
631
656
|
} else if (device.logging) {
|
|
632
657
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
633
|
-
this.debugLog(
|
|
658
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
634
659
|
} else if (this.platform.config.options?.logging) {
|
|
635
660
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
636
|
-
this.debugLog(
|
|
661
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
637
662
|
} else {
|
|
638
663
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
639
|
-
this.debugLog(
|
|
664
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
640
665
|
}
|
|
641
666
|
}
|
|
642
667
|
|
|
@@ -664,12 +689,28 @@ export class AirConditioner {
|
|
|
664
689
|
}
|
|
665
690
|
}
|
|
666
691
|
|
|
692
|
+
debugWarnLog(...log: any[]): void {
|
|
693
|
+
if (this.enablingDeviceLogging()) {
|
|
694
|
+
if (this.deviceLogging?.includes('debug')) {
|
|
695
|
+
this.platform.log.warn('[DEBUG]', String(...log));
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
667
700
|
errorLog(...log: any[]): void {
|
|
668
701
|
if (this.enablingDeviceLogging()) {
|
|
669
702
|
this.platform.log.error(String(...log));
|
|
670
703
|
}
|
|
671
704
|
}
|
|
672
705
|
|
|
706
|
+
debugErrorLog(...log: any[]): void {
|
|
707
|
+
if (this.enablingDeviceLogging()) {
|
|
708
|
+
if (this.deviceLogging?.includes('debug')) {
|
|
709
|
+
this.platform.log.error('[DEBUG]', String(...log));
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
673
714
|
debugLog(...log: any[]): void {
|
|
674
715
|
if (this.enablingDeviceLogging()) {
|
|
675
716
|
if (this.deviceLogging === 'debug') {
|