@switchbot/homebridge-switchbot 3.7.1-beta.3 → 3.7.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.
Files changed (83) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/config.schema.json +7 -1
  3. package/dist/device/blindtilt.d.ts.map +1 -1
  4. package/dist/device/blindtilt.js +25 -6
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.d.ts.map +1 -1
  7. package/dist/device/bot.js +25 -6
  8. package/dist/device/bot.js.map +1 -1
  9. package/dist/device/ceilinglight.d.ts.map +1 -1
  10. package/dist/device/ceilinglight.js +25 -6
  11. package/dist/device/ceilinglight.js.map +1 -1
  12. package/dist/device/colorbulb.d.ts.map +1 -1
  13. package/dist/device/colorbulb.js +25 -6
  14. package/dist/device/colorbulb.js.map +1 -1
  15. package/dist/device/contact.d.ts.map +1 -1
  16. package/dist/device/contact.js +25 -6
  17. package/dist/device/contact.js.map +1 -1
  18. package/dist/device/curtain.d.ts.map +1 -1
  19. package/dist/device/curtain.js +25 -6
  20. package/dist/device/curtain.js.map +1 -1
  21. package/dist/device/fan.d.ts.map +1 -1
  22. package/dist/device/fan.js +25 -6
  23. package/dist/device/fan.js.map +1 -1
  24. package/dist/device/hub.d.ts.map +1 -1
  25. package/dist/device/hub.js +25 -6
  26. package/dist/device/hub.js.map +1 -1
  27. package/dist/device/humidifier.d.ts.map +1 -1
  28. package/dist/device/humidifier.js +25 -6
  29. package/dist/device/humidifier.js.map +1 -1
  30. package/dist/device/iosensor.d.ts.map +1 -1
  31. package/dist/device/iosensor.js +25 -6
  32. package/dist/device/iosensor.js.map +1 -1
  33. package/dist/device/lightstrip.d.ts.map +1 -1
  34. package/dist/device/lightstrip.js +25 -6
  35. package/dist/device/lightstrip.js.map +1 -1
  36. package/dist/device/lock.d.ts.map +1 -1
  37. package/dist/device/lock.js +25 -6
  38. package/dist/device/lock.js.map +1 -1
  39. package/dist/device/meter.d.ts.map +1 -1
  40. package/dist/device/meter.js +25 -6
  41. package/dist/device/meter.js.map +1 -1
  42. package/dist/device/meterplus.d.ts.map +1 -1
  43. package/dist/device/meterplus.js +25 -6
  44. package/dist/device/meterplus.js.map +1 -1
  45. package/dist/device/motion.d.ts.map +1 -1
  46. package/dist/device/motion.js +25 -6
  47. package/dist/device/motion.js.map +1 -1
  48. package/dist/device/plug.d.ts.map +1 -1
  49. package/dist/device/plug.js +25 -6
  50. package/dist/device/plug.js.map +1 -1
  51. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  52. package/dist/device/robotvacuumcleaner.js +25 -6
  53. package/dist/device/robotvacuumcleaner.js.map +1 -1
  54. package/dist/device/waterdetector.d.ts.map +1 -1
  55. package/dist/device/waterdetector.js +25 -6
  56. package/dist/device/waterdetector.js.map +1 -1
  57. package/dist/platform.d.ts.map +1 -1
  58. package/dist/platform.js +46 -22
  59. package/dist/platform.js.map +1 -1
  60. package/dist/settings.d.ts +1 -0
  61. package/dist/settings.d.ts.map +1 -1
  62. package/dist/settings.js.map +1 -1
  63. package/package.json +10 -10
  64. package/src/device/blindtilt.ts +22 -6
  65. package/src/device/bot.ts +22 -6
  66. package/src/device/ceilinglight.ts +22 -6
  67. package/src/device/colorbulb.ts +22 -6
  68. package/src/device/contact.ts +22 -6
  69. package/src/device/curtain.ts +23 -6
  70. package/src/device/fan.ts +22 -6
  71. package/src/device/hub.ts +22 -6
  72. package/src/device/humidifier.ts +22 -6
  73. package/src/device/iosensor.ts +22 -6
  74. package/src/device/lightstrip.ts +22 -6
  75. package/src/device/lock.ts +22 -6
  76. package/src/device/meter.ts +22 -6
  77. package/src/device/meterplus.ts +22 -6
  78. package/src/device/motion.ts +22 -6
  79. package/src/device/plug.ts +22 -6
  80. package/src/device/robotvacuumcleaner.ts +22 -6
  81. package/src/device/waterdetector.ts +22 -6
  82. package/src/platform.ts +39 -19
  83. package/src/settings.ts +1 -0
@@ -3,6 +3,10 @@
3
3
  * lock.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import { deviceBase } from './device.js';
6
+ /*
7
+ * For Testing Locally:
8
+ * import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
9
+ */
6
10
  import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
7
11
  import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
8
12
 
@@ -165,16 +169,28 @@ export class Lock extends deviceBase {
165
169
  }
166
170
 
167
171
  // Retrieve initial values and updateHomekit
168
- this.debugLog('Retrieve initial values and update Homekit');
169
- this.refreshStatus();
172
+ try {
173
+ this.debugLog('Retrieve initial values and update Homekit');
174
+ this.refreshStatus();
175
+ } catch (e: any) {
176
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
177
+ }
170
178
 
171
179
  //regisiter webhook event handler if enabled
172
- this.debugLog('Registering Webhook Event Handler');
173
- this.registerWebhook();
180
+ try {
181
+ this.debugLog('Registering Webhook Event Handler');
182
+ this.registerWebhook();
183
+ } catch (e: any) {
184
+ this.errorLog(`failed to registerWebhook, Error: ${e}`);
185
+ }
174
186
 
175
187
  //regisiter platform BLE event handler if enabled
176
- this.debugLog('Registering Platform BLE Event Handler');
177
- this.registerPlatformBLE();
188
+ try {
189
+ this.debugLog('Registering Platform BLE Event Handler');
190
+ this.registerPlatformBLE();
191
+ } catch (e: any) {
192
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e}`);
193
+ }
178
194
 
179
195
  // Start an update interval
180
196
  interval(this.deviceRefreshRate * 1000)
@@ -6,6 +6,10 @@ import { Units } from 'homebridge';
6
6
  import { deviceBase } from './device.js';
7
7
  import { Subject, interval, skipWhile } from 'rxjs';
8
8
  import { convertUnits, validHumidity } from '../utils.js';
9
+ /*
10
+ * For Testing Locally:
11
+ * import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
12
+ */
9
13
  import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
10
14
 
11
15
  import type { devicesConfig } from '../settings.js';
@@ -148,16 +152,28 @@ export class Meter extends deviceBase {
148
152
  }
149
153
 
150
154
  // Retrieve initial values and updateHomekit
151
- this.debugLog('Retrieve initial values and update Homekit');
152
- this.refreshStatus();
155
+ try {
156
+ this.debugLog('Retrieve initial values and update Homekit');
157
+ this.refreshStatus();
158
+ } catch (e: any) {
159
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
160
+ }
153
161
 
154
162
  //regisiter webhook event handler if enabled
155
- this.debugLog('Registering Webhook Event Handler');
156
- this.registerWebhook();
163
+ try {
164
+ this.debugLog('Registering Webhook Event Handler');
165
+ this.registerWebhook();
166
+ } catch (e: any) {
167
+ this.errorLog(`failed to registerWebhook, Error: ${e}`);
168
+ }
157
169
 
158
170
  //regisiter platform BLE event handler if enabled
159
- this.debugLog('Registering Platform BLE Event Handler');
160
- this.registerPlatformBLE();
171
+ try {
172
+ this.debugLog('Registering Platform BLE Event Handler');
173
+ this.registerPlatformBLE();
174
+ } catch (e: any) {
175
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e}`);
176
+ }
161
177
 
162
178
  // Start an update interval
163
179
  interval(this.deviceRefreshRate * 1000)
@@ -6,6 +6,10 @@ import { Units } from 'homebridge';
6
6
  import { deviceBase } from './device.js';
7
7
  import { Subject, interval, skipWhile } from 'rxjs';
8
8
  import { convertUnits, validHumidity } from '../utils.js';
9
+ /*
10
+ * For Testing Locally:
11
+ * import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
12
+ */
9
13
  import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
10
14
 
11
15
  import type { devicesConfig } from '../settings.js';
@@ -153,16 +157,28 @@ export class MeterPlus extends deviceBase {
153
157
  }
154
158
 
155
159
  // Retrieve initial values and updateHomekit
156
- this.debugLog('Retrieve initial values and update Homekit');
157
- this.refreshStatus();
160
+ try {
161
+ this.debugLog('Retrieve initial values and update Homekit');
162
+ this.refreshStatus();
163
+ } catch (e: any) {
164
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
165
+ }
158
166
 
159
167
  //regisiter webhook event handler if enabled
160
- this.debugLog('Registering Webhook Event Handler');
161
- this.registerWebhook();
168
+ try {
169
+ this.debugLog('Registering Webhook Event Handler');
170
+ this.registerWebhook();
171
+ } catch (e: any) {
172
+ this.errorLog(`failed to registerWebhook, Error: ${e}`);
173
+ }
162
174
 
163
175
  //regisiter platform BLE event handler if enabled
164
- this.debugLog('Registering Platform BLE Event Handler');
165
- this.registerPlatformBLE();
176
+ try {
177
+ this.debugLog('Registering Platform BLE Event Handler');
178
+ this.registerPlatformBLE();
179
+ } catch (e: any) {
180
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e}`);
181
+ }
166
182
 
167
183
  // Start an update interval
168
184
  interval(this.deviceRefreshRate * 1000)
@@ -5,6 +5,10 @@
5
5
  */
6
6
  import { deviceBase } from './device.js';
7
7
  import { Subject, interval, skipWhile } from 'rxjs';
8
+ /*
9
+ * For Testing Locally:
10
+ * import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
11
+ */
8
12
  import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
9
13
 
10
14
  import type { devicesConfig } from '../settings.js';
@@ -138,16 +142,28 @@ export class Motion extends deviceBase {
138
142
  };
139
143
 
140
144
  // Retrieve initial values and updateHomekit
141
- this.debugLog('Retrieve initial values and update Homekit');
142
- this.refreshStatus();
145
+ try {
146
+ this.debugLog('Retrieve initial values and update Homekit');
147
+ this.refreshStatus();
148
+ } catch (e: any) {
149
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
150
+ }
143
151
 
144
152
  //regisiter webhook event handler if enabled
145
- this.debugLog('Registering Webhook Event Handler');
146
- this.registerWebhook();
153
+ try {
154
+ this.debugLog('Registering Webhook Event Handler');
155
+ this.registerWebhook();
156
+ } catch (e: any) {
157
+ this.errorLog(`failed to registerWebhook, Error: ${e}`);
158
+ }
147
159
 
148
160
  //regisiter platform BLE event handler if enabled
149
- this.debugLog('Registering Platform BLE Event Handler');
150
- this.registerPlatformBLE();
161
+ try {
162
+ this.debugLog('Registering Platform BLE Event Handler');
163
+ this.registerPlatformBLE();
164
+ } catch (e: any) {
165
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e}`);
166
+ }
151
167
 
152
168
  // Start an update interval
153
169
  interval(this.deviceRefreshRate * 1000)
@@ -3,6 +3,10 @@
3
3
  * plug.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import { deviceBase } from './device.js';
6
+ /*
7
+ * For Testing Locally:
8
+ * import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
9
+ */
6
10
  import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
7
11
  import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
8
12
 
@@ -66,16 +70,28 @@ export class Plug extends deviceBase {
66
70
  .onSet(this.OnSet.bind(this));
67
71
 
68
72
  // Retrieve initial values and updateHomekit
69
- this.debugLog('Retrieve initial values and update Homekit');
70
- this.refreshStatus();
73
+ try {
74
+ this.debugLog('Retrieve initial values and update Homekit');
75
+ this.refreshStatus();
76
+ } catch (e: any) {
77
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
78
+ }
71
79
 
72
80
  //regisiter webhook event handler if enabled
73
- this.debugLog('Registering Webhook Event Handler');
74
- this.registerWebhook();
81
+ try {
82
+ this.debugLog('Registering Webhook Event Handler');
83
+ this.registerWebhook();
84
+ } catch (e: any) {
85
+ this.errorLog(`failed to registerWebhook, Error: ${e}`);
86
+ }
75
87
 
76
88
  //regisiter platform BLE event handler if enabled
77
- this.debugLog('Registering Platform BLE Event Handler');
78
- this.registerPlatformBLE();
89
+ try {
90
+ this.debugLog('Registering Platform BLE Event Handler');
91
+ this.registerPlatformBLE();
92
+ } catch (e: any) {
93
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e}`);
94
+ }
79
95
 
80
96
  // Start an update interval
81
97
  interval(this.deviceRefreshRate * 1000)
@@ -3,6 +3,10 @@
3
3
  * robotvacuumcleaner.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
5
  import { deviceBase } from './device.js';
6
+ /*
7
+ * For Testing Locally:
8
+ * import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
9
+ */
6
10
  import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
7
11
  import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
8
12
 
@@ -127,16 +131,28 @@ export class RobotVacuumCleaner extends deviceBase {
127
131
  });
128
132
 
129
133
  // Retrieve initial values and updateHomekit
130
- this.debugLog('Retrieve initial values and update Homekit');
131
- this.refreshStatus();
134
+ try {
135
+ this.debugLog('Retrieve initial values and update Homekit');
136
+ this.refreshStatus();
137
+ } catch (e: any) {
138
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
139
+ }
132
140
 
133
141
  //regisiter webhook event handler if enabled
134
- this.debugLog('Registering Webhook Event Handler');
135
- this.registerWebhook();
142
+ try {
143
+ this.debugLog('Registering Webhook Event Handler');
144
+ this.registerWebhook();
145
+ } catch (e: any) {
146
+ this.errorLog(`failed to registerWebhook, Error: ${e}`);
147
+ }
136
148
 
137
149
  //regisiter platform BLE event handler if enabled
138
- this.debugLog('Registering Platform BLE Event Handler');
139
- this.registerPlatformBLE();
150
+ try {
151
+ this.debugLog('Registering Platform BLE Event Handler');
152
+ this.registerPlatformBLE();
153
+ } catch (e: any) {
154
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e}`);
155
+ }
140
156
 
141
157
  // Start an update interval
142
158
  interval(this.deviceRefreshRate * 1000)
@@ -4,6 +4,10 @@
4
4
  */
5
5
  import { deviceBase } from './device.js';
6
6
  import { Subject, interval, skipWhile } from 'rxjs';
7
+ /*
8
+ * For Testing Locally:
9
+ * import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
10
+ */
7
11
  import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
8
12
 
9
13
  import type { devicesConfig } from '../settings.js';
@@ -118,16 +122,28 @@ export class WaterDetector extends deviceBase {
118
122
  }
119
123
 
120
124
  // Retrieve initial values and updateHomekit
121
- this.debugLog('Retrieve initial values and update Homekit');
122
- this.refreshStatus();
125
+ try {
126
+ this.debugLog('Retrieve initial values and update Homekit');
127
+ this.refreshStatus();
128
+ } catch (e: any) {
129
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
130
+ }
123
131
 
124
132
  //regisiter webhook event handler if enabled
125
- this.debugLog('Registering Webhook Event Handler');
126
- this.registerWebhook();
133
+ try {
134
+ this.debugLog('Registering Webhook Event Handler');
135
+ this.registerWebhook();
136
+ } catch (e: any) {
137
+ this.errorLog(`failed to registerWebhook, Error: ${e}`);
138
+ }
127
139
 
128
140
  //regisiter platform BLE event handler if enabled
129
- this.debugLog('Registering Platform BLE Event Handler');
130
- this.registerPlatformBLE();
141
+ try {
142
+ this.debugLog('Registering Platform BLE Event Handler');
143
+ this.registerPlatformBLE();
144
+ } catch (e: any) {
145
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e}`);
146
+ }
131
147
 
132
148
  // Start an update interval
133
149
  interval(this.deviceRefreshRate * 1000)
package/src/platform.ts CHANGED
@@ -51,6 +51,10 @@ import type { blindTilt, curtain, curtain3, device } from './types/devicelist.js
51
51
  import type { API, DynamicPlatformPlugin, Logging, PlatformAccessory } from 'homebridge';
52
52
  import type { SwitchBotPlatformConfig, devicesConfig, irDevicesConfig } from './settings.js';
53
53
  import type { IncomingMessage, Server, ServerResponse } from 'http';
54
+ /*
55
+ * For Testing Locally:
56
+ * import { SwitchBotModel } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
57
+ */
54
58
  import { SwitchBotModel } from 'node-switchbot';
55
59
 
56
60
  /**
@@ -147,9 +151,21 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
147
151
  }
148
152
  });
149
153
 
150
- this.setupMqtt();
151
- this.setupwebhook();
152
- this.setupBlE();
154
+ try {
155
+ this.setupMqtt();
156
+ } catch (e: any) {
157
+ this.errorLog(`Setup MQTT, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
158
+ }
159
+ try {
160
+ this.setupwebhook();
161
+ } catch (e: any) {
162
+ this.errorLog(`Setup Webhook, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
163
+ }
164
+ try {
165
+ this.setupBlE();
166
+ } catch (e: any) {
167
+ this.errorLog(`Setup Platform BLE, Error Message: ${e.message}, Submit Bugs Here: ` + 'https://tinyurl.com/SwitchBotBug');
168
+ }
153
169
  }
154
170
 
155
171
  async setupMqtt(): Promise<void> {
@@ -2928,29 +2944,33 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2928
2944
  * @returns string value
2929
2945
  */
2930
2946
  async validateAndCleanDisplayName(displayName: string, name: string, value: string): Promise<string> {
2931
- const validPattern = /^[a-zA-Z0-9][a-zA-Z0-9 ']*[a-zA-Z0-9]$/;
2932
- const invalidCharsPattern = /[^a-zA-Z0-9 ']/g;
2933
- const invalidStartEndPattern = /^[^a-zA-Z0-9]+|[^a-zA-Z0-9]+$/g;
2947
+ if (this.config.options?.allowInvalidCharacter) {
2948
+ return value;
2949
+ } else {
2950
+ const validPattern = /^[a-zA-Z0-9][a-zA-Z0-9 ']*[a-zA-Z0-9]$/;
2951
+ const invalidCharsPattern = /[^a-zA-Z0-9 ']/g;
2952
+ const invalidStartEndPattern = /^[^a-zA-Z0-9]+|[^a-zA-Z0-9]+$/g;
2934
2953
 
2935
- if (!validPattern.test(value)) {
2936
- this.warnLog(`WARNING: The accessory '${displayName}' has an invalid '${name}' characteristic ('${value}'). Please use only alphanumeric,`
2954
+ if (!validPattern.test(value)) {
2955
+ this.warnLog(`WARNING: The accessory '${displayName}' has an invalid '${name}' characteristic ('${value}'). Please use only alphanumeric,`
2937
2956
  + ' space, and apostrophe characters. Ensure it starts and ends with an alphabetic or numeric character, and avoid emojis. This may'
2938
2957
  + ' prevent the accessory from being added in the Home App or cause unresponsiveness.');
2939
2958
 
2940
- // Remove invalid characters
2941
- if (invalidCharsPattern.test(value)) {
2942
- this.warnLog(`Removing invalid characters from '${name}' characteristic`);
2943
- value = value.replace(invalidCharsPattern, '');
2944
- }
2959
+ // Remove invalid characters
2960
+ if (invalidCharsPattern.test(value)) {
2961
+ this.warnLog(`Removing invalid characters from '${name}' characteristic`);
2962
+ value = value.replace(invalidCharsPattern, '');
2963
+ }
2945
2964
 
2946
- // Ensure it starts and ends with an alphanumeric character
2947
- if (invalidStartEndPattern.test(value)) {
2948
- this.warnLog(`Removing invalid starting or ending characters from '${name}' characteristic`);
2949
- value = value.replace(invalidStartEndPattern, '');
2965
+ // Ensure it starts and ends with an alphanumeric character
2966
+ if (invalidStartEndPattern.test(value)) {
2967
+ this.warnLog(`Removing invalid starting or ending characters from '${name}' characteristic`);
2968
+ value = value.replace(invalidStartEndPattern, '');
2969
+ }
2950
2970
  }
2951
- }
2952
2971
 
2953
- return value;
2972
+ return value;
2973
+ }
2954
2974
  }
2955
2975
 
2956
2976
  /**
package/src/settings.ts CHANGED
@@ -58,6 +58,7 @@ interface credentials {
58
58
  interface options {
59
59
  devices?: devicesConfig[];
60
60
  irdevices?: irDevicesConfig[];
61
+ allowInvalidCharacter?: boolean;
61
62
  mqttURL?: string;
62
63
  mqttOptions?: IClientOptions;
63
64
  mqttPubOptions?: IClientOptions;