@switchbot/homebridge-switchbot 2.0.0-beta.9 → 2.0.1-beta.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 +119 -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 +12 -12
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +316 -234
- 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 +530 -421
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +22 -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 +322 -245
- 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 +528 -449
- package/src/settings.ts +23 -11
|
@@ -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,20 +164,26 @@ 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
|
|
187
|
-
|
|
167
|
+
const commandType: string = await this.commandType();
|
|
168
|
+
const command: string = await this.commandOn();
|
|
169
|
+
|
|
170
|
+
const body = superStringify({
|
|
171
|
+
'command': command,
|
|
188
172
|
'parameter': 'default',
|
|
189
|
-
'commandType':
|
|
173
|
+
'commandType': commandType,
|
|
190
174
|
});
|
|
191
175
|
await this.pushChanges(body);
|
|
192
176
|
}
|
|
193
177
|
}
|
|
194
178
|
|
|
195
179
|
async pushAirConditionerOffChanges(): Promise<void> {
|
|
196
|
-
const
|
|
197
|
-
|
|
180
|
+
const commandType: string = await this.commandType();
|
|
181
|
+
const command: string = await this.commandOff();
|
|
182
|
+
|
|
183
|
+
const body = superStringify({
|
|
184
|
+
'command': command,
|
|
198
185
|
'parameter': 'default',
|
|
199
|
-
'commandType':
|
|
186
|
+
'commandType': commandType,
|
|
200
187
|
});
|
|
201
188
|
await this.pushChanges(body);
|
|
202
189
|
}
|
|
@@ -228,22 +215,23 @@ export class AirConditioner {
|
|
|
228
215
|
if (this.CurrentMode === 1) {
|
|
229
216
|
this.CurrentTemperature = 25;
|
|
230
217
|
this.debugLog(
|
|
231
|
-
|
|
218
|
+
`${this.device.remoteType}: ${this.accessory.displayName} CurrentMode: ${this.CurrentMode},`
|
|
219
|
+
+ ` CurrentTemperature: ${this.CurrentTemperature}`,
|
|
232
220
|
);
|
|
233
221
|
}
|
|
234
222
|
const parameter = `${this.CurrentTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`;
|
|
235
223
|
|
|
236
224
|
if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
237
225
|
this.CurrentTemperatureUndefined();
|
|
238
|
-
if (this.CurrentTemperature < this.
|
|
226
|
+
if (this.CurrentTemperature < this.accessory.context.CurrentTemperature) {
|
|
239
227
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
|
|
240
|
-
} else if (this.CurrentTemperature > this.
|
|
228
|
+
} else if (this.CurrentTemperature > this.accessory.context.CurrentTemperature) {
|
|
241
229
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
|
|
242
230
|
}
|
|
243
231
|
} else {
|
|
244
232
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
|
|
245
233
|
}
|
|
246
|
-
const body =
|
|
234
|
+
const body = superStringify({
|
|
247
235
|
'command': 'setAll',
|
|
248
236
|
'parameter': `${parameter}`,
|
|
249
237
|
'commandType': 'command',
|
|
@@ -253,166 +241,72 @@ export class AirConditioner {
|
|
|
253
241
|
}
|
|
254
242
|
|
|
255
243
|
async pushChanges(body): Promise<void> {
|
|
256
|
-
|
|
244
|
+
if (this.device.connectionType === 'OpenAPI') {
|
|
245
|
+
try {
|
|
257
246
|
// 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
|
-
|
|
247
|
+
const t = Date.now();
|
|
248
|
+
const nonce = 'requestID';
|
|
249
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
250
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
251
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
252
|
+
.digest();
|
|
253
|
+
const sign = signTerm.toString('base64');
|
|
254
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
255
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
256
|
+
const options = {
|
|
257
|
+
hostname: HostDomain,
|
|
258
|
+
port: 443,
|
|
259
|
+
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
260
|
+
method: 'POST',
|
|
261
|
+
headers: {
|
|
262
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
263
|
+
'sign': sign,
|
|
264
|
+
'nonce': nonce,
|
|
265
|
+
't': t,
|
|
266
|
+
'Content-Type': 'application/json',
|
|
267
|
+
'Content-Length': body.length,
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
const req = https.request(options, res => {
|
|
271
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges statusCode: ${res.statusCode}`);
|
|
272
|
+
this.statusCode({ res });
|
|
273
|
+
res.on('data', d => {
|
|
274
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
|
|
275
|
+
});
|
|
286
276
|
});
|
|
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`,
|
|
277
|
+
req.on('error', (e: any) => {
|
|
278
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
279
|
+
});
|
|
280
|
+
req.write(body);
|
|
281
|
+
req.end();
|
|
282
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
|
|
283
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
284
|
+
this.HeatingThresholdTemperature = this.CurrentTemperature;
|
|
285
|
+
this.CoolingThresholdTemperature = this.CurrentTemperature;
|
|
286
|
+
this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
|
|
287
|
+
this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
|
|
288
|
+
this.updateHomeKitCharacteristics();
|
|
289
|
+
} catch (e: any) {
|
|
290
|
+
this.apiError(e);
|
|
291
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
|
|
292
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
333
293
|
);
|
|
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}`);
|
|
294
|
+
}
|
|
372
295
|
} else {
|
|
373
|
-
this.
|
|
374
|
-
this.
|
|
375
|
-
`Air Conditioner: ${this.accessory.displayName}` + ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
|
|
376
|
-
);
|
|
296
|
+
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
297
|
+
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
377
298
|
}
|
|
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}`);
|
|
388
|
-
} else {
|
|
389
|
-
this.coolerService?.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, this.CoolingThresholdTemperature);
|
|
390
|
-
this.debugLog(
|
|
391
|
-
`Air Conditioner: ${this.accessory.displayName}` + ` updateCharacteristic CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`,
|
|
392
|
-
);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
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
299
|
}
|
|
406
300
|
|
|
407
301
|
async CurrentTemperatureGet(): Promise<CharacteristicValue> {
|
|
408
302
|
if (this.CurrentTemperature === undefined) {
|
|
409
303
|
this.CurrentTemperature = 24;
|
|
410
|
-
this.
|
|
304
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
411
305
|
} else {
|
|
412
|
-
this.
|
|
306
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
413
307
|
}
|
|
414
|
-
this.debugLog(
|
|
415
|
-
this.accessory.context.CurrentTemperature = this.
|
|
308
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get CurrentTemperature: ${this.CurrentTemperature}`);
|
|
309
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
416
310
|
return this.CurrentTemperature;
|
|
417
311
|
}
|
|
418
312
|
|
|
@@ -424,9 +318,8 @@ export class AirConditioner {
|
|
|
424
318
|
} else {
|
|
425
319
|
this.RotationSpeed = this.CurrentFanSpeed - 1;
|
|
426
320
|
}
|
|
427
|
-
this.debugLog(
|
|
428
|
-
this.
|
|
429
|
-
this.accessory.context.RotationSpeed = this.RotationSpeedCached;
|
|
321
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get RotationSpeed: ${this.RotationSpeed}`);
|
|
322
|
+
this.accessory.context.RotationSpeed = this.RotationSpeed;
|
|
430
323
|
return this.RotationSpeed;
|
|
431
324
|
}
|
|
432
325
|
|
|
@@ -437,23 +330,19 @@ export class AirConditioner {
|
|
|
437
330
|
this.CurrentFanSpeed = Number(value) + 1;
|
|
438
331
|
}
|
|
439
332
|
this.RotationSpeed = this.CurrentFanSpeed;
|
|
440
|
-
this.
|
|
441
|
-
this.accessory.context.RotationSpeed = this.RotationSpeedCached;
|
|
333
|
+
this.accessory.context.RotationSpeed = this.RotationSpeed;
|
|
442
334
|
this.pushAirConditionerStatusChanges();
|
|
443
335
|
}
|
|
444
336
|
|
|
445
337
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
446
|
-
this.debugLog(
|
|
447
|
-
|
|
338
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
|
|
448
339
|
this.Active = value;
|
|
449
|
-
this.
|
|
450
|
-
this.accessory.context.Active = this.ActiveCached;
|
|
451
|
-
|
|
340
|
+
this.accessory.context.Active = this.Active;
|
|
452
341
|
if (value === this.platform.Characteristic.Active.INACTIVE) {
|
|
453
|
-
this.debugLog(
|
|
342
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
|
|
454
343
|
this.pushAirConditionerOffChanges();
|
|
455
344
|
} else {
|
|
456
|
-
this.debugLog(
|
|
345
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushAirConditionerOnChanges, Active: ${this.Active}`);
|
|
457
346
|
if (this.pushOn) {
|
|
458
347
|
this.pushAirConditionerOnChanges();
|
|
459
348
|
} else {
|
|
@@ -466,24 +355,23 @@ export class AirConditioner {
|
|
|
466
355
|
if (this.ValidValues === this.valid012) {
|
|
467
356
|
this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
|
|
468
357
|
this.debugLog(
|
|
469
|
-
|
|
358
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Get (AUTO) TargetHeaterCoolerState: ${this.CurrentHeaterCoolerState},` +
|
|
470
359
|
` ValidValues: ${this.ValidValues}`,
|
|
471
360
|
);
|
|
472
361
|
} else if (this.ValidValues === this.valid12) {
|
|
473
362
|
this.TargetHeaterCoolerState =
|
|
474
363
|
this.platform.Characteristic.TargetHeaterCoolerState.COOL || this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
|
|
475
364
|
this.debugLog(
|
|
476
|
-
|
|
365
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Get (COOL/HEAT) TargetHeaterCoolerState: ${this.CurrentHeaterCoolerState},` +
|
|
477
366
|
` ValidValues: ${this.ValidValues}`,
|
|
478
367
|
);
|
|
479
368
|
} else {
|
|
480
369
|
this.debugLog(
|
|
481
|
-
|
|
370
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Get TargetHeaterCoolerState: ${this.CurrentHeaterCoolerState},` +
|
|
482
371
|
` ValidValues: ${this.ValidValues}`,
|
|
483
372
|
);
|
|
484
373
|
}
|
|
485
|
-
this.
|
|
486
|
-
this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerStateCached;
|
|
374
|
+
this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerState;
|
|
487
375
|
return this.TargetHeaterCoolerState;
|
|
488
376
|
}
|
|
489
377
|
|
|
@@ -495,7 +383,7 @@ export class AirConditioner {
|
|
|
495
383
|
this.TargetHeaterCoolerStateCOOL();
|
|
496
384
|
} else {
|
|
497
385
|
this.errorLog(
|
|
498
|
-
|
|
386
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set TargetHeaterCoolerState: ${this.TargetHeaterCoolerState},` +
|
|
499
387
|
` hide_automode: ${this.hide_automode} `,
|
|
500
388
|
);
|
|
501
389
|
}
|
|
@@ -508,96 +396,93 @@ export class AirConditioner {
|
|
|
508
396
|
this.TargetHeaterCoolerStateCOOL();
|
|
509
397
|
} else {
|
|
510
398
|
this.errorLog(
|
|
511
|
-
|
|
399
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set TargetHeaterCoolerState: ${this.TargetHeaterCoolerState},` +
|
|
512
400
|
` hide_automode: ${this.hide_automode} `,
|
|
513
401
|
);
|
|
514
402
|
}
|
|
515
403
|
}
|
|
516
|
-
this.
|
|
517
|
-
this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerStateCached;
|
|
404
|
+
this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerState;
|
|
518
405
|
this.pushAirConditionerStatusChanges();
|
|
519
406
|
}
|
|
520
407
|
|
|
521
408
|
async TargetHeaterCoolerStateAUTO(): Promise<void> {
|
|
522
409
|
this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.AUTO;
|
|
523
410
|
this.CurrentMode = 1;
|
|
524
|
-
this.debugLog(
|
|
525
|
-
this.debugLog(
|
|
411
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (AUTO) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
|
|
412
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
|
|
526
413
|
}
|
|
527
414
|
|
|
528
415
|
async TargetHeaterCoolerStateCOOL(): Promise<void> {
|
|
529
416
|
this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.COOL;
|
|
530
417
|
this.CurrentMode = 2;
|
|
531
|
-
this.debugLog(
|
|
532
|
-
this.debugLog(
|
|
418
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (COOL) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
|
|
419
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
|
|
533
420
|
}
|
|
534
421
|
|
|
535
422
|
async TargetHeaterCoolerStateHEAT(): Promise<void> {
|
|
536
423
|
this.TargetHeaterCoolerState = this.platform.Characteristic.TargetHeaterCoolerState.HEAT;
|
|
537
424
|
this.CurrentMode = 5;
|
|
538
|
-
this.debugLog(
|
|
539
|
-
this.debugLog(
|
|
425
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set (HEAT) TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
|
|
426
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Switchbot CurrentMode: ${this.CurrentMode}`);
|
|
540
427
|
}
|
|
541
428
|
|
|
542
429
|
async CurrentHeaterCoolerStateGet(): Promise<CharacteristicValue> {
|
|
543
430
|
if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
544
431
|
this.CurrentTemperatureUndefined();
|
|
545
|
-
if (this.CurrentTemperature < this.
|
|
432
|
+
if (this.CurrentTemperature < this.accessory.context.CurrentTemperature) {
|
|
546
433
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
|
|
547
|
-
this.debugLog(
|
|
548
|
-
|
|
434
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
435
|
+
+` Get (COOLLING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
436
|
+
} else if (this.CurrentTemperature > this.accessory.context.CurrentTemperature) {
|
|
549
437
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.HEATING;
|
|
550
|
-
this.debugLog(
|
|
438
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
439
|
+
+` Get (HEATING) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
551
440
|
}
|
|
552
441
|
} else {
|
|
553
442
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.INACTIVE;
|
|
554
|
-
this.debugLog(
|
|
443
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
444
|
+
+` Get (INACTIVE) CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
555
445
|
}
|
|
556
|
-
this.
|
|
557
|
-
this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerStateCached;
|
|
446
|
+
this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
|
|
558
447
|
return this.CurrentHeaterCoolerState;
|
|
559
448
|
}
|
|
560
449
|
|
|
561
450
|
async HeatingThresholdTemperatureGet(): Promise<CharacteristicValue> {
|
|
562
451
|
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}`);
|
|
452
|
+
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
453
|
+
this.HeatingThresholdTemperature = this.accessory.context.CurrentTemperature;
|
|
454
|
+
this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
|
|
455
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
|
|
568
456
|
return this.HeatingThresholdTemperature;
|
|
569
457
|
}
|
|
570
458
|
|
|
571
459
|
async HeatingThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
|
|
572
|
-
this.
|
|
460
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
573
461
|
this.CurrentTemperature = value;
|
|
574
|
-
this.
|
|
575
|
-
this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperatureCached;
|
|
462
|
+
this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
|
|
576
463
|
this.debugLog(
|
|
577
|
-
|
|
578
|
-
` CurrentTemperatureCached: ${this.
|
|
464
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set HeatingThresholdTemperature: ${this.HeatingThresholdTemperature},` +
|
|
465
|
+
` CurrentTemperatureCached: ${this.accessory.context.CurrentTemperature}`,
|
|
579
466
|
);
|
|
580
467
|
this.pushAirConditionerStatusChanges();
|
|
581
468
|
}
|
|
582
469
|
|
|
583
470
|
async CoolingThresholdTemperatureGet(): Promise<CharacteristicValue> {
|
|
584
471
|
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}`);
|
|
472
|
+
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
473
|
+
this.CoolingThresholdTemperature = this.accessory.context.CurrentTemperature;
|
|
474
|
+
this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
|
|
475
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`);
|
|
590
476
|
return this.CoolingThresholdTemperature;
|
|
591
477
|
}
|
|
592
478
|
|
|
593
479
|
async CoolingThresholdTemperatureSet(value: CharacteristicValue): Promise<void> {
|
|
594
|
-
this.
|
|
480
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
595
481
|
this.CurrentTemperature = value;
|
|
596
|
-
this.
|
|
597
|
-
this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperatureCached;
|
|
482
|
+
this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
|
|
598
483
|
this.debugLog(
|
|
599
|
-
|
|
600
|
-
` CurrentTemperatureCached: ${this.
|
|
484
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Set CoolingThresholdTemperature: ${this.CoolingThresholdTemperature},` +
|
|
485
|
+
` CurrentTemperatureCached: ${this.accessory.context.CurrentTemperature}`,
|
|
601
486
|
);
|
|
602
487
|
this.pushAirConditionerStatusChanges();
|
|
603
488
|
}
|
|
@@ -606,11 +491,181 @@ export class AirConditioner {
|
|
|
606
491
|
if (this.CurrentTemperature === undefined) {
|
|
607
492
|
this.CurrentTemperature = 24;
|
|
608
493
|
}
|
|
609
|
-
if (this.
|
|
494
|
+
if (this.accessory.context.CurrentTemperature === undefined) {
|
|
610
495
|
this.CurrentTemperature = 30;
|
|
611
496
|
}
|
|
612
497
|
}
|
|
613
498
|
|
|
499
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
500
|
+
if (this.Active === undefined) {
|
|
501
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
502
|
+
} else {
|
|
503
|
+
this.accessory.context.Active = this.Active;
|
|
504
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
505
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
506
|
+
}
|
|
507
|
+
if (this.RotationSpeed === undefined) {
|
|
508
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
|
|
509
|
+
} else {
|
|
510
|
+
this.accessory.context.RotationSpeed = this.RotationSpeed;
|
|
511
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
|
|
512
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
|
|
513
|
+
}
|
|
514
|
+
if (this.CurrentTemperature === undefined) {
|
|
515
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
516
|
+
} else {
|
|
517
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
518
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
519
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
520
|
+
}
|
|
521
|
+
if (this.TargetHeaterCoolerState === undefined) {
|
|
522
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`);
|
|
523
|
+
} else {
|
|
524
|
+
this.accessory.context.TargetHeaterCoolerState = this.TargetHeaterCoolerState;
|
|
525
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, this.TargetHeaterCoolerState);
|
|
526
|
+
this.debugLog(
|
|
527
|
+
`${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic TargetHeaterCoolerState: ${this.TargetHeaterCoolerState}`,
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
if (this.CurrentHeaterCoolerState === undefined) {
|
|
531
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
|
|
532
|
+
} else {
|
|
533
|
+
this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
|
|
534
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
|
|
535
|
+
this.debugLog(
|
|
536
|
+
`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
537
|
+
+ ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
if (this.HeatingThresholdTemperature === undefined) {
|
|
541
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`);
|
|
542
|
+
} else {
|
|
543
|
+
this.accessory.context.HeatingThresholdTemperature = this.HeatingThresholdTemperature;
|
|
544
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, this.HeatingThresholdTemperature);
|
|
545
|
+
this.debugLog(
|
|
546
|
+
`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
547
|
+
+ ` updateCharacteristic HeatingThresholdTemperature: ${this.HeatingThresholdTemperature}`,
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
if (this.CoolingThresholdTemperature === undefined) {
|
|
551
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`);
|
|
552
|
+
} else {
|
|
553
|
+
this.accessory.context.CoolingThresholdTemperature = this.CoolingThresholdTemperature;
|
|
554
|
+
this.coolerService?.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, this.CoolingThresholdTemperature);
|
|
555
|
+
this.debugLog(
|
|
556
|
+
`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
557
|
+
+ ` updateCharacteristic CoolingThresholdTemperature: ${this.CoolingThresholdTemperature}`,
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
async commandType() {
|
|
563
|
+
let commandType: string;
|
|
564
|
+
if (this.device.customize) {
|
|
565
|
+
commandType = 'customize';
|
|
566
|
+
} else {
|
|
567
|
+
commandType = 'command';
|
|
568
|
+
}
|
|
569
|
+
return commandType;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
async commandOn() {
|
|
573
|
+
let command: string;
|
|
574
|
+
if (this.device.customize && this.device.customOn) {
|
|
575
|
+
command = this.device.customOn;
|
|
576
|
+
} else {
|
|
577
|
+
command = 'turnOn';
|
|
578
|
+
}
|
|
579
|
+
return command;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
async commandOff() {
|
|
583
|
+
let command: string;
|
|
584
|
+
if (this.device.customize && this.device.customOn) {
|
|
585
|
+
command = this.device.customOn;
|
|
586
|
+
} else {
|
|
587
|
+
command = 'turnOff';
|
|
588
|
+
}
|
|
589
|
+
return command;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
|
|
593
|
+
switch (res.statusCode) {
|
|
594
|
+
case 151:
|
|
595
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
596
|
+
break;
|
|
597
|
+
case 152:
|
|
598
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found.`);
|
|
599
|
+
break;
|
|
600
|
+
case 160:
|
|
601
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported.`);
|
|
602
|
+
break;
|
|
603
|
+
case 161:
|
|
604
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline.`);
|
|
605
|
+
break;
|
|
606
|
+
case 171:
|
|
607
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
608
|
+
break;
|
|
609
|
+
case 190:
|
|
610
|
+
this.errorLog(
|
|
611
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
|
|
612
|
+
` with server, Or command: ${superStringify(res)} format is invalid`,
|
|
613
|
+
);
|
|
614
|
+
break;
|
|
615
|
+
case 100:
|
|
616
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
617
|
+
break;
|
|
618
|
+
default:
|
|
619
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
async apiError(e: any): Promise<void> {
|
|
624
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
625
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
|
|
626
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
|
|
627
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.TargetHeaterCoolerState, e);
|
|
628
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.CurrentHeaterCoolerState, e);
|
|
629
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.HeatingThresholdTemperature, e);
|
|
630
|
+
this.coolerService.updateCharacteristic(this.platform.Characteristic.CoolingThresholdTemperature, e);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
FirmwareRevision(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): string {
|
|
634
|
+
let FirmwareRevision: string;
|
|
635
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
636
|
+
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
637
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
638
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
639
|
+
if (accessory.context.FirmwareRevision) {
|
|
640
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
641
|
+
} else if (device.firmware) {
|
|
642
|
+
FirmwareRevision = device.firmware;
|
|
643
|
+
} else {
|
|
644
|
+
FirmwareRevision = this.platform.version;
|
|
645
|
+
}
|
|
646
|
+
return FirmwareRevision;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
async context(device: irdevice & irDevicesConfig) {
|
|
650
|
+
if (this.Active === undefined) {
|
|
651
|
+
this.Active = this.platform.Characteristic.Active.INACTIVE;
|
|
652
|
+
} else {
|
|
653
|
+
this.Active = this.accessory.context.Active;
|
|
654
|
+
}
|
|
655
|
+
if (this.CurrentTemperature === undefined) {
|
|
656
|
+
this.CurrentTemperature = 24;
|
|
657
|
+
} else {
|
|
658
|
+
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
659
|
+
}
|
|
660
|
+
if (device.irair?.hide_automode) {
|
|
661
|
+
this.hide_automode = device.irair?.hide_automode;
|
|
662
|
+
this.accessory.context.hide_automode = this.hide_automode;
|
|
663
|
+
} else {
|
|
664
|
+
this.hide_automode = device.irair?.hide_automode;
|
|
665
|
+
this.accessory.context.hide_automode = this.hide_automode;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
614
669
|
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
615
670
|
let config = {};
|
|
616
671
|
if (device.irair) {
|
|
@@ -619,24 +674,30 @@ export class AirConditioner {
|
|
|
619
674
|
if (device.logging !== undefined) {
|
|
620
675
|
config['logging'] = device.logging;
|
|
621
676
|
}
|
|
677
|
+
if (device.connectionType !== undefined) {
|
|
678
|
+
config['connectionType'] = device.connectionType;
|
|
679
|
+
}
|
|
680
|
+
if (device.external !== undefined) {
|
|
681
|
+
config['external'] = device.external;
|
|
682
|
+
}
|
|
622
683
|
if (Object.entries(config).length !== 0) {
|
|
623
|
-
this.infoLog(
|
|
684
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
624
685
|
}
|
|
625
686
|
}
|
|
626
687
|
|
|
627
688
|
async logs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
628
689
|
if (this.platform.debugMode) {
|
|
629
690
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
630
|
-
this.debugLog(
|
|
691
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
631
692
|
} else if (device.logging) {
|
|
632
693
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
633
|
-
this.debugLog(
|
|
694
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
634
695
|
} else if (this.platform.config.options?.logging) {
|
|
635
696
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
636
|
-
this.debugLog(
|
|
697
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
637
698
|
} else {
|
|
638
699
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
639
|
-
this.debugLog(
|
|
700
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
640
701
|
}
|
|
641
702
|
}
|
|
642
703
|
|
|
@@ -664,12 +725,28 @@ export class AirConditioner {
|
|
|
664
725
|
}
|
|
665
726
|
}
|
|
666
727
|
|
|
728
|
+
debugWarnLog(...log: any[]): void {
|
|
729
|
+
if (this.enablingDeviceLogging()) {
|
|
730
|
+
if (this.deviceLogging?.includes('debug')) {
|
|
731
|
+
this.platform.log.warn('[DEBUG]', String(...log));
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
667
736
|
errorLog(...log: any[]): void {
|
|
668
737
|
if (this.enablingDeviceLogging()) {
|
|
669
738
|
this.platform.log.error(String(...log));
|
|
670
739
|
}
|
|
671
740
|
}
|
|
672
741
|
|
|
742
|
+
debugErrorLog(...log: any[]): void {
|
|
743
|
+
if (this.enablingDeviceLogging()) {
|
|
744
|
+
if (this.deviceLogging?.includes('debug')) {
|
|
745
|
+
this.platform.log.error('[DEBUG]', String(...log));
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
673
750
|
debugLog(...log: any[]): void {
|
|
674
751
|
if (this.enablingDeviceLogging()) {
|
|
675
752
|
if (this.deviceLogging === 'debug') {
|