@switchbot/homebridge-switchbot 3.5.1-beta.4 → 3.5.1-beta.5

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.
@@ -4,9 +4,9 @@ import type { UrlObject } from 'url';
4
4
  import type { MqttClient } from 'mqtt';
5
5
  import type { Dispatcher } from 'undici';
6
6
  import type { Server } from 'http';
7
+ import type { blindTilt, curtain, curtain3, device } from './types/devicelist.js';
7
8
  import type { API, DynamicPlatformPlugin, Logging, PlatformAccessory } from 'homebridge';
8
9
  import type { SwitchBotPlatformConfig, devicesConfig, irDevicesConfig } from './settings.js';
9
- import type { blindTilt, curtain, curtain3, device } from './types/devicelist.js';
10
10
  /**
11
11
  * HomebridgePlatform
12
12
  * This class is the main constructor for your plugin, this is where you should
@@ -28,7 +28,9 @@ export declare class SwitchBotPlatform implements DynamicPlatformPlugin {
28
28
  mqttClient: MqttClient | null;
29
29
  readonly fakegatoAPI: any;
30
30
  readonly eve: any;
31
- readonly webhookEventHandler: any;
31
+ readonly webhookEventHandler: {
32
+ [x: string]: (context: any) => void;
33
+ };
32
34
  constructor(log: Logging, config: SwitchBotPlatformConfig, api: API);
33
35
  setupMqtt(): Promise<void>;
34
36
  setupwebhook(): Promise<void>;
@@ -116,14 +118,14 @@ export declare class SwitchBotPlatform implements DynamicPlatformPlugin {
116
118
  * If device level logging is turned on, log to log.warn
117
119
  * Otherwise send debug logs to log.debug
118
120
  */
119
- infoLog(...log: any[]): void;
120
- successLog(...log: any[]): void;
121
- debugSuccessLog(...log: any[]): void;
122
- warnLog(...log: any[]): void;
123
- debugWarnLog(...log: any[]): void;
124
- errorLog(...log: any[]): void;
125
- debugErrorLog(...log: any[]): void;
126
- debugLog(...log: any[]): void;
127
- enablingPlatformLogging(): boolean;
121
+ infoLog(...log: any[]): Promise<void>;
122
+ successLog(...log: any[]): Promise<void>;
123
+ debugSuccessLog(...log: any[]): Promise<void>;
124
+ warnLog(...log: any[]): Promise<void>;
125
+ debugWarnLog(...log: any[]): Promise<void>;
126
+ errorLog(...log: any[]): Promise<void>;
127
+ debugErrorLog(...log: any[]): Promise<void>;
128
+ debugLog(...log: any[]): Promise<void>;
129
+ enablingPlatformLogging(): Promise<boolean>;
128
130
  }
129
131
  //# sourceMappingURL=platform.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":";;AA6CA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AACrC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,EAAmC,MAAM,MAAM,CAAC;AACpE,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAqB,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACzF,OAAO,KAAK,EAAE,uBAAuB,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAE7F,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAElF;;;;GAIG;AACH,qBAAa,iBAAkB,YAAW,qBAAqB;IACtD,WAAW,EAAE,iBAAiB,EAAE,CAAC;IACxC,SAAgB,GAAG,EAAE,GAAG,CAAC;IACzB,SAAgB,GAAG,EAAE,OAAO,CAAC;IAE7B,OAAO,EAAG,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAG,OAAO,CAAC;IACpB,UAAU,EAAG,MAAM,CAAC;IACpB,mBAAmB,EAAG,MAAM,CAAC;IAC7B,cAAc,EAAG,uBAAuB,CAAC,SAAS,CAAC,CAAC;IACpD,eAAe,EAAG,uBAAuB,CAAC,SAAS,CAAC,CAAC;IACrD,MAAM,EAAG,uBAAuB,CAAC;IAEjC,o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GAAG,OAAO,CAAC,IAAI,CAAC;IAQ7C,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAMrC,YAAY,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ1C,QAAQ,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAMtC,aAAa,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ3C,QAAQ,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAUtC,uBAAuB,IAAI,OAAO,CAAC,OAAO,CAAC;CAGlD"}
package/dist/platform.js CHANGED
@@ -32,13 +32,13 @@ import { AirConditioner } from './irdevice/airconditioner.js';
32
32
  import { Buffer } from 'buffer';
33
33
  import { request } from 'undici';
34
34
  import asyncmqtt from 'async-mqtt';
35
- import { isBlindTiltDevice, isCurtainDevice, sleep } from './utils.js';
36
35
  import { createServer } from 'http';
37
36
  import { queueScheduler } from 'rxjs';
38
37
  import fakegato from 'fakegato-history';
39
38
  import crypto, { randomUUID } from 'crypto';
40
39
  import { readFileSync, writeFileSync } from 'fs';
41
40
  import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
41
+ import { isBlindTiltDevice, isCurtainDevice, sleep } from './utils.js';
42
42
  import { PLATFORM_NAME, PLUGIN_NAME, Devices, setupWebhook, updateWebhook, deleteWebhook, queryWebhook } from './settings.js';
43
43
  /**
44
44
  * HomebridgePlatform
@@ -61,7 +61,7 @@ export class SwitchBotPlatform {
61
61
  mqttClient = null;
62
62
  fakegatoAPI;
63
63
  eve;
64
- webhookEventHandler;
64
+ webhookEventHandler = {};
65
65
  constructor(log, config, api) {
66
66
  // initialize
67
67
  this.accessories = [];
@@ -128,29 +128,29 @@ export class SwitchBotPlatform {
128
128
  try {
129
129
  const { connectAsync } = asyncmqtt;
130
130
  this.mqttClient = await connectAsync(this.config.options?.mqttURL, this.config.options.mqttOptions || {});
131
- this.debugLog('MQTT connection has been established successfully.');
132
- this.mqttClient.on('error', (e) => {
133
- this.errorLog(`Failed to publish MQTT messages. ${e}`);
131
+ await this.debugLog('MQTT connection has been established successfully.');
132
+ this.mqttClient.on('error', async (e) => {
133
+ await this.errorLog(`Failed to publish MQTT messages. ${e}`);
134
134
  });
135
135
  if (!this.config.options?.webhookURL) {
136
136
  // receive webhook events via MQTT
137
- this.infoLog(`Webhook is configured to be received through ${this.config.options.mqttURL}/homebridge-switchbot/webhook.`);
137
+ await this.infoLog(`Webhook is configured to be received through ${this.config.options.mqttURL}/homebridge-switchbot/webhook.`);
138
138
  this.mqttClient.subscribe('homebridge-switchbot/webhook/+');
139
139
  this.mqttClient.on('message', async (topic, message) => {
140
140
  try {
141
- this.debugLog(`Received Webhook via MQTT: ${topic}=${message}`);
141
+ await this.debugLog(`Received Webhook via MQTT: ${topic}=${message}`);
142
142
  const context = JSON.parse(message.toString());
143
143
  this.webhookEventHandler[context.deviceMac]?.(context);
144
144
  }
145
145
  catch (e) {
146
- this.errorLog(`Failed to handle webhook event. Error:${e}`);
146
+ await this.errorLog(`Failed to handle webhook event. Error:${e}`);
147
147
  }
148
148
  });
149
149
  }
150
150
  }
151
151
  catch (e) {
152
152
  this.mqttClient = null;
153
- this.errorLog(`Failed to establish MQTT connection. ${e}`);
153
+ await this.errorLog(`Failed to establish MQTT connection. ${e}`);
154
154
  }
155
155
  }
156
156
  }
@@ -275,9 +275,7 @@ export class SwitchBotPlatform {
275
275
  }),
276
276
  });
277
277
  const response = await body.json();
278
- this.debugLog(`deleteWebhook: url:${url}`);
279
- this.debugLog(`deleteWebhook: body:${JSON.stringify(response)}`);
280
- this.debugLog(`deleteWebhook: statusCode:${statusCode}`);
278
+ this.debugLog(`deleteWebhook: url:${url}, body:${JSON.stringify(response)}, statusCode:${statusCode}`);
281
279
  if (statusCode !== 200 || response?.statusCode !== 100) {
282
280
  this.errorLog(`Failed to delete webhook. HTTP:${statusCode} API:${response?.statusCode} message:${response?.message}`);
283
281
  }
@@ -2541,67 +2539,67 @@ export class SwitchBotPlatform {
2541
2539
  async statusCode(statusCode) {
2542
2540
  switch (statusCode) {
2543
2541
  case 151:
2544
- this.errorLog(`Command not supported by this device type, statusCode: ${statusCode}, Submit Feature Request Here: ` +
2542
+ await this.errorLog(`Command not supported by this device type, statusCode: ${statusCode}, Submit Feature Request Here: ` +
2545
2543
  'https://tinyurl.com/SwitchBotFeatureRequest');
2546
2544
  break;
2547
2545
  case 152:
2548
- this.errorLog(`Device not found, statusCode: ${statusCode}`);
2546
+ await this.errorLog(`Device not found, statusCode: ${statusCode}`);
2549
2547
  break;
2550
2548
  case 160:
2551
- this.errorLog(`Command is not supported, statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`);
2549
+ await this.errorLog(`Command is not supported, statusCode: ${statusCode}, Submit Bugs Here: https://tinyurl.com/SwitchBotBug`);
2552
2550
  break;
2553
2551
  case 161:
2554
- this.errorLog(`Device is offline, statusCode: ${statusCode}`);
2552
+ await this.errorLog(`Device is offline, statusCode: ${statusCode}`);
2555
2553
  break;
2556
2554
  case 171:
2557
- this.errorLog(`is offline, statusCode: ${statusCode}`);
2555
+ await this.errorLog(`is offline, statusCode: ${statusCode}`);
2558
2556
  break;
2559
2557
  case 190:
2560
- this.errorLog(`Requests reached the daily limit, statusCode: ${statusCode}`);
2558
+ await this.errorLog(`Requests reached the daily limit, statusCode: ${statusCode}`);
2561
2559
  break;
2562
2560
  case 100:
2563
- this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
2561
+ await this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
2564
2562
  break;
2565
2563
  case 200:
2566
- this.debugLog(`Request successful, statusCode: ${statusCode}`);
2564
+ await this.debugLog(`Request successful, statusCode: ${statusCode}`);
2567
2565
  break;
2568
2566
  case 400:
2569
- this.errorLog('Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request '
2567
+ await this.errorLog('Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request '
2570
2568
  + `payload, statusCode: ${statusCode}`);
2571
2569
  break;
2572
2570
  case 401:
2573
- this.errorLog('Unauthorized, Authorization for the API is required, but the request has not been authenticated, '
2571
+ await this.errorLog('Unauthorized, Authorization for the API is required, but the request has not been authenticated, '
2574
2572
  + `statusCode: ${statusCode}`);
2575
2573
  break;
2576
2574
  case 403:
2577
- this.errorLog('Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not '
2575
+ await this.errorLog('Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not '
2578
2576
  + `found, statusCode: ${statusCode}`);
2579
2577
  break;
2580
2578
  case 404:
2581
- this.errorLog(`Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`);
2579
+ await this.errorLog(`Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`);
2582
2580
  break;
2583
2581
  case 406:
2584
- this.errorLog('Not Acceptable, The client has requested a MIME type via the Accept header for a value not supported by the server, '
2582
+ await this.errorLog('Not Acceptable, The client has requested a MIME type via the Accept header for a value not supported by the server, '
2585
2583
  + `statusCode: ${statusCode}`);
2586
2584
  break;
2587
2585
  case 415:
2588
- this.errorLog('Unsupported Media Type, The client has defined a contentType header that is not supported by the server, '
2586
+ await this.errorLog('Unsupported Media Type, The client has defined a contentType header that is not supported by the server, '
2589
2587
  + `statusCode: ${statusCode}`);
2590
2588
  break;
2591
2589
  case 422:
2592
- this.errorLog('Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for '
2590
+ await this.errorLog('Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for '
2593
2591
  + `APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
2594
2592
  break;
2595
2593
  case 429:
2596
- this.errorLog('Too Many Requests, The client has exceeded the number of requests allowed for a given time window, '
2594
+ await this.errorLog('Too Many Requests, The client has exceeded the number of requests allowed for a given time window, '
2597
2595
  + `statusCode: ${statusCode}`);
2598
2596
  break;
2599
2597
  case 500:
2600
- this.errorLog('Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, '
2598
+ await this.errorLog('Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, '
2601
2599
  + `statusCode: ${statusCode}`);
2602
2600
  break;
2603
2601
  default:
2604
- this.errorLog(`Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
2602
+ await this.errorLog(`Unknown statusCode, statusCode: ${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
2605
2603
  }
2606
2604
  }
2607
2605
  async retryRequest(deviceMaxRetries, deviceDelayBetweenRetries, url, options) {
@@ -2615,14 +2613,14 @@ export class SwitchBotPlatform {
2615
2613
  return { body, statusCode };
2616
2614
  }
2617
2615
  else {
2618
- this.debugLog(`Received status code: ${statusCode}`);
2616
+ await this.debugLog(`Received status code: ${statusCode}`);
2619
2617
  }
2620
2618
  }
2621
2619
  catch (error) {
2622
- this.errorLog(`Error making request: ${error.message}`);
2620
+ await this.errorLog(`Error making request: ${error.message}`);
2623
2621
  }
2624
2622
  retryCount++;
2625
- this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
2623
+ await this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
2626
2624
  await sleep(delayBetweenRetries);
2627
2625
  }
2628
2626
  return { body: null, statusCode: -1 };
@@ -2633,16 +2631,17 @@ export class SwitchBotPlatform {
2633
2631
  try {
2634
2632
  const SwitchBot = (await import('node-switchbot')).SwitchBot;
2635
2633
  queueScheduler.schedule(() => (switchbot = new SwitchBot()));
2634
+ await this.debugLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${switchbot}`);
2636
2635
  }
2637
2636
  catch (e) {
2638
2637
  switchbot = false;
2639
- this.errorLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${switchbot}, Error: ${e}`);
2638
+ await this.errorLog(`${device.deviceType}: ${accessory.displayName} 'node-switchbot' found: ${switchbot}, Error: ${e}`);
2640
2639
  }
2641
2640
  return switchbot;
2642
2641
  }
2643
2642
  async getVersion() {
2644
2643
  const json = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
2645
- this.debugLog(`Plugin Version: ${json.version}`);
2644
+ await this.debugLog(`Plugin Version: ${json.version}`);
2646
2645
  this.version = json.version;
2647
2646
  }
2648
2647
  async getPlatformConfigSettings() {
@@ -2679,7 +2678,7 @@ export class SwitchBotPlatform {
2679
2678
  platformConfig.delayBetweenRetries = this.delayBetweenRetries / 1000;
2680
2679
  }
2681
2680
  if (Object.entries(platformConfig).length !== 0) {
2682
- this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
2681
+ await this.debugLog(`Platform Config: ${JSON.stringify(platformConfig)}`);
2683
2682
  }
2684
2683
  this.platformConfig = platformConfig;
2685
2684
  }
@@ -2688,64 +2687,64 @@ export class SwitchBotPlatform {
2688
2687
  this.debugMode = process.argv.includes('-D') || process.argv.includes('--debug');
2689
2688
  if (this.config.options?.logging === 'debug' || this.config.options?.logging === 'standard' || this.config.options?.logging === 'none') {
2690
2689
  this.platformLogging = this.config.options.logging;
2691
- this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`);
2690
+ await this.debugWarnLog(`Using Config Logging: ${this.platformLogging}`);
2692
2691
  }
2693
2692
  else if (this.debugMode) {
2694
2693
  this.platformLogging = 'debugMode';
2695
- this.debugWarnLog(`Using ${this.platformLogging} Logging`);
2694
+ await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
2696
2695
  }
2697
2696
  else {
2698
2697
  this.platformLogging = 'standard';
2699
- this.debugWarnLog(`Using ${this.platformLogging} Logging`);
2698
+ await this.debugWarnLog(`Using ${this.platformLogging} Logging`);
2700
2699
  }
2701
2700
  }
2702
2701
  /**
2703
2702
  * If device level logging is turned on, log to log.warn
2704
2703
  * Otherwise send debug logs to log.debug
2705
2704
  */
2706
- infoLog(...log) {
2707
- if (this.enablingPlatformLogging()) {
2705
+ async infoLog(...log) {
2706
+ if (await this.enablingPlatformLogging()) {
2708
2707
  this.log.info(String(...log));
2709
2708
  }
2710
2709
  }
2711
- successLog(...log) {
2712
- if (this.enablingPlatformLogging()) {
2710
+ async successLog(...log) {
2711
+ if (await this.enablingPlatformLogging()) {
2713
2712
  this.log.success(String(...log));
2714
2713
  }
2715
2714
  }
2716
- debugSuccessLog(...log) {
2717
- if (this.enablingPlatformLogging()) {
2715
+ async debugSuccessLog(...log) {
2716
+ if (await this.enablingPlatformLogging()) {
2718
2717
  if (this.platformLogging?.includes('debug')) {
2719
2718
  this.log.success('[DEBUG]', String(...log));
2720
2719
  }
2721
2720
  }
2722
2721
  }
2723
- warnLog(...log) {
2724
- if (this.enablingPlatformLogging()) {
2722
+ async warnLog(...log) {
2723
+ if (await this.enablingPlatformLogging()) {
2725
2724
  this.log.warn(String(...log));
2726
2725
  }
2727
2726
  }
2728
- debugWarnLog(...log) {
2729
- if (this.enablingPlatformLogging()) {
2727
+ async debugWarnLog(...log) {
2728
+ if (await this.enablingPlatformLogging()) {
2730
2729
  if (this.platformLogging?.includes('debug')) {
2731
2730
  this.log.warn('[DEBUG]', String(...log));
2732
2731
  }
2733
2732
  }
2734
2733
  }
2735
- errorLog(...log) {
2736
- if (this.enablingPlatformLogging()) {
2734
+ async errorLog(...log) {
2735
+ if (await this.enablingPlatformLogging()) {
2737
2736
  this.log.error(String(...log));
2738
2737
  }
2739
2738
  }
2740
- debugErrorLog(...log) {
2741
- if (this.enablingPlatformLogging()) {
2739
+ async debugErrorLog(...log) {
2740
+ if (await this.enablingPlatformLogging()) {
2742
2741
  if (this.platformLogging?.includes('debug')) {
2743
2742
  this.log.error('[DEBUG]', String(...log));
2744
2743
  }
2745
2744
  }
2746
2745
  }
2747
- debugLog(...log) {
2748
- if (this.enablingPlatformLogging()) {
2746
+ async debugLog(...log) {
2747
+ if (await this.enablingPlatformLogging()) {
2749
2748
  if (this.platformLogging === 'debugMode') {
2750
2749
  this.log.debug(String(...log));
2751
2750
  }
@@ -2754,7 +2753,7 @@ export class SwitchBotPlatform {
2754
2753
  }
2755
2754
  }
2756
2755
  }
2757
- enablingPlatformLogging() {
2756
+ async enablingPlatformLogging() {
2758
2757
  return this.platformLogging?.includes('debug') || this.platformLogging === 'standard';
2759
2758
  }
2760
2759
  }