@switchbot/homebridge-switchbot 1.2.4 → 1.2.6-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -373,14 +373,16 @@ export class Curtain {
373
373
  + ` TargetPosition: ${this.TargetPosition}, PositionState: ${this.PositionState},`);
374
374
 
375
375
  if (!this.device.curtain?.hide_lightsensor) {
376
+ this.set_minLux = this.minLux();
377
+ this.set_maxLux = this.maxLux();
376
378
  // Brightness
377
379
  switch (this.deviceStatus.body.brightness) {
378
380
  case 'dim':
379
- this.CurrentAmbientLightLevel = 0.0001;
381
+ this.CurrentAmbientLightLevel = this.set_minLux;
380
382
  break;
381
383
  case 'bright':
382
384
  default:
383
- this.CurrentAmbientLightLevel = 100000;
385
+ this.CurrentAmbientLightLevel = this.set_maxLux;
384
386
  }
385
387
  this.platform.debug(`Curtain: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
386
388
  }
@@ -489,29 +491,34 @@ export class Curtain {
489
491
  }
490
492
 
491
493
  private async BLEpushChanges() {
492
- this.platform.debug(`Curtain: ${this.accessory.displayName} BLE pushChanges`);
493
- const switchbot = this.connectBLE();
494
- switchbot.discover({ model: 'c', quick: true, id: this.device.bleMac }).then((device_list) => {
495
- this.platform.log.info(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
496
- return device_list[0].runToPos(100 - Number(this.TargetPosition));
497
- }).then(() => {
498
- this.platform.device(`Curtain: ${this.accessory.displayName} Done.`);
499
- }).catch(async (e: any) => {
500
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
501
- if (this.deviceDebug) {
502
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
503
- + ` Error Message: ${JSON.stringify(e.message)}`);
504
- }
505
- if (this.debugDebug) {
506
- this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
507
- + ` Error: ${JSON.stringify(e)}`);
508
- }
509
- if (this.platform.config.credentials?.openToken) {
510
- this.platform.log.warn(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
511
- await this.OpenAPIpushChanges();
512
- }
513
- this.apiError(e);
514
- });
494
+ if (this.TargetPosition !== this.CurrentPosition) {
495
+ this.platform.debug(`Curtain: ${this.accessory.displayName} BLE pushChanges`);
496
+ const switchbot = this.connectBLE();
497
+ switchbot.discover({ model: 'c', quick: true, id: this.device.bleMac }).then((device_list) => {
498
+ this.platform.log.info(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
499
+ return device_list[0].runToPos(100 - Number(this.TargetPosition));
500
+ }).then(() => {
501
+ this.platform.device(`Curtain: ${this.accessory.displayName} Done.`);
502
+ }).catch(async (e: any) => {
503
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
504
+ if (this.deviceDebug) {
505
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
506
+ + ` Error Message: ${JSON.stringify(e.message)}`);
507
+ }
508
+ if (this.debugDebug) {
509
+ this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
510
+ + ` Error: ${JSON.stringify(e)}`);
511
+ }
512
+ if (this.platform.config.credentials?.openToken) {
513
+ this.platform.log.warn(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
514
+ await this.OpenAPIpushChanges();
515
+ }
516
+ this.apiError(e);
517
+ });
518
+ } else {
519
+ this.platform.debug(`Curtain: ${this.accessory.displayName} No BLE Changes, CurrentPosition & TargetPosition Are the Same.`
520
+ + ` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`);
521
+ }
515
522
  }
516
523
 
517
524
  private async OpenAPIpushChanges() {
@@ -534,6 +541,9 @@ export class Curtain {
534
541
  const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId!}/commands`, payload));
535
542
  this.platform.debug(`Curtain: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
536
543
  this.statusCode(push);
544
+ } else {
545
+ this.platform.debug(`Curtain: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.`
546
+ + ` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`);
537
547
  }
538
548
  } catch (e: any) {
539
549
  this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
@@ -14,18 +14,15 @@ export class AirConditioner {
14
14
 
15
15
  // Characteristic Values
16
16
  Active!: CharacteristicValue;
17
- ARActive!: CharacteristicValue;
18
17
  RotationSpeed!: CharacteristicValue;
19
- CurrentARTemp!: CharacteristicValue;
20
- CurrentARMode!: CharacteristicValue;
21
18
  LastTemperature!: CharacteristicValue;
22
- CurrentARFanSpeed!: CharacteristicValue;
23
19
  CurrentTemperature!: CharacteristicValue;
24
20
  TargetHeaterCoolerState?: CharacteristicValue;
25
21
  CurrentHeaterCoolerState!: CharacteristicValue;
26
22
  HeatingThresholdTemperature?: CharacteristicValue;
27
23
 
28
24
  // Others
25
+ state!: string;
29
26
  Busy: any;
30
27
  Timeout: any = null;
31
28
  CurrentMode!: number;
@@ -158,8 +155,10 @@ export class AirConditioner {
158
155
 
159
156
  if (value === this.platform.Characteristic.Active.INACTIVE) {
160
157
  this.pushAirConditionerOffChanges();
158
+ this.platform.device(`Air Conditioner: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
161
159
  } else {
162
160
  this.pushAirConditionerOnChanges();
161
+ this.platform.device(`Air Conditioner: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
163
162
  }
164
163
  this.Active = value;
165
164
  }
@@ -180,7 +179,7 @@ export class AirConditioner {
180
179
  if (this.CurrentTemperature === undefined) {
181
180
  this.platform.debug(`Air Conditioner: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
182
181
  } else {
183
- this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.CurrentTemperature);
182
+ this.service?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
184
183
  this.platform.device(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
185
184
  }
186
185
  if (this.TargetHeaterCoolerState === undefined) {
@@ -207,9 +206,8 @@ export class AirConditioner {
207
206
  }
208
207
 
209
208
  private CurrentTemperatureGet(value: CharacteristicValue) {
210
- this.platform.debug('Trigger Get CurrentTemperture');
211
-
212
209
  value = Number(this.CurrentTemperature) || 24;
210
+ this.platform.debug(`Air Conditioner: ${this.accessory.displayName} Trigger Get CurrentTemperature: ${value}` );
213
211
 
214
212
  this.service
215
213
  .getCharacteristic(this.platform.Characteristic.CurrentTemperature)
@@ -236,7 +234,7 @@ export class AirConditioner {
236
234
  }
237
235
 
238
236
  private CurrentHeaterCoolerStateGet() {
239
- if (this.Active === 1) {
237
+ if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
240
238
  if ((this.CurrentTemperature || 24) < (this.LastTemperature || 30)) {
241
239
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
242
240
  } else {
@@ -273,7 +271,7 @@ export class AirConditioner {
273
271
  * AirConditioner: "command" "highSpeed" "default" = fan speed to high
274
272
  */
275
273
  async pushAirConditionerOnChanges() {
276
- if (this.Active !== 1) {
274
+ if (this.Active !== this.platform.Characteristic.Active.ACTIVE) {
277
275
  const payload = {
278
276
  commandType: 'command',
279
277
  parameter: 'default',
@@ -284,7 +282,7 @@ export class AirConditioner {
284
282
  }
285
283
 
286
284
  async pushAirConditionerOffChanges() {
287
- if (this.Active !== 0) {
285
+ if (this.Active !== this.platform.Characteristic.Active.INACTIVE) {
288
286
  const payload = {
289
287
  commandType: 'command',
290
288
  parameter: 'default',
@@ -311,14 +309,25 @@ export class AirConditioner {
311
309
  command: 'setAll',
312
310
  } as any;
313
311
 
314
- this.CurrentARTemp = this.CurrentTemperature || 24;
315
- this.CurrentARMode = this.CurrentMode || 1;
316
- this.CurrentARFanSpeed = this.CurrentFanSpeed || 1;
317
- this.ARActive = this.Active === 1 ? 'on' : 'off';
318
- payload.parameter = `${this.CurrentARTemp},${this.CurrentARMode},${this.CurrentARFanSpeed},${this.ARActive}`;
312
+ if (this.CurrentTemperature === undefined) {
313
+ this.CurrentTemperature = 24;
314
+ }
315
+ if (this.CurrentMode === undefined) {
316
+ this.CurrentMode = 1;
317
+ }
318
+ if (this.CurrentFanSpeed === undefined) {
319
+ this.CurrentFanSpeed = 1;
320
+ }
321
+ this.Active = this.platform.Characteristic.Active.ACTIVE;
322
+ if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
323
+ this.state = 'on';
324
+ } else {
325
+ this.state = 'off';
326
+ }
327
+ payload.parameter = `${this.CurrentTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`;
319
328
 
320
329
 
321
- if (this.Active === 1) {
330
+ if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
322
331
  if ((this.CurrentTemperature || 24) < (this.LastTemperature || 30)) {
323
332
  this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
324
333
  } else {
@@ -334,11 +343,11 @@ export class AirConditioner {
334
343
  public async pushChanges(payload: payload) {
335
344
  try {
336
345
  this.platform.log.info(`Air Conditioner: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
337
- + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
346
+ + ` parameter: [${payload.parameter}], commandType: ${payload.commandType}`);
338
347
 
339
348
  // Make the API request
340
- const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
341
- this.platform.debug(`Air Conditioner: ${this.accessory.displayName} pushChanges: ${push.data}`);
349
+ const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
350
+ this.platform.log.error(`Air Conditioner: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
342
351
  this.statusCode(push);
343
352
  this.updateHomeKitCharacteristics();
344
353
  } catch (e: any) {
package/src/platform.ts CHANGED
@@ -1451,6 +1451,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1451
1451
  device(...log: any[]) {
1452
1452
  if (this.config.options!.debug === 'device') {
1453
1453
  this.log.warn('[DEVICE]', String(...log));
1454
+ } else if (this.config.options!.debug === 'debug') {
1455
+ this.log.info('[DEBUG]', String(...log));
1454
1456
  } else {
1455
1457
  this.log.debug(String(...log));
1456
1458
  }