@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.
- package/CHANGELOG.md +8 -0
- package/config.schema.json +7 -1
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +25 -6
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +25 -6
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +25 -6
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +25 -6
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +25 -6
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +25 -6
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +25 -6
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +25 -6
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +25 -6
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +25 -6
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +25 -6
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +25 -6
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +25 -6
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +25 -6
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +25 -6
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +25 -6
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +25 -6
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +25 -6
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +46 -22
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +10 -10
- package/src/device/blindtilt.ts +22 -6
- package/src/device/bot.ts +22 -6
- package/src/device/ceilinglight.ts +22 -6
- package/src/device/colorbulb.ts +22 -6
- package/src/device/contact.ts +22 -6
- package/src/device/curtain.ts +23 -6
- package/src/device/fan.ts +22 -6
- package/src/device/hub.ts +22 -6
- package/src/device/humidifier.ts +22 -6
- package/src/device/iosensor.ts +22 -6
- package/src/device/lightstrip.ts +22 -6
- package/src/device/lock.ts +22 -6
- package/src/device/meter.ts +22 -6
- package/src/device/meterplus.ts +22 -6
- package/src/device/motion.ts +22 -6
- package/src/device/plug.ts +22 -6
- package/src/device/robotvacuumcleaner.ts +22 -6
- package/src/device/waterdetector.ts +22 -6
- package/src/platform.ts +39 -19
- package/src/settings.ts +1 -0
package/src/device/lock.ts
CHANGED
|
@@ -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
|
-
|
|
169
|
-
|
|
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
|
-
|
|
173
|
-
|
|
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
|
-
|
|
177
|
-
|
|
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)
|
package/src/device/meter.ts
CHANGED
|
@@ -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
|
-
|
|
152
|
-
|
|
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
|
-
|
|
156
|
-
|
|
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
|
-
|
|
160
|
-
|
|
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)
|
package/src/device/meterplus.ts
CHANGED
|
@@ -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
|
-
|
|
157
|
-
|
|
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
|
-
|
|
161
|
-
|
|
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
|
-
|
|
165
|
-
|
|
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)
|
package/src/device/motion.ts
CHANGED
|
@@ -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
|
-
|
|
142
|
-
|
|
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
|
-
|
|
146
|
-
|
|
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
|
-
|
|
150
|
-
|
|
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)
|
package/src/device/plug.ts
CHANGED
|
@@ -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
|
-
|
|
70
|
-
|
|
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
|
-
|
|
74
|
-
|
|
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
|
-
|
|
78
|
-
|
|
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
|
-
|
|
131
|
-
|
|
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
|
-
|
|
135
|
-
|
|
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
|
-
|
|
139
|
-
|
|
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
|
-
|
|
122
|
-
|
|
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
|
-
|
|
126
|
-
|
|
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
|
-
|
|
130
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
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
|
-
|
|
2936
|
-
|
|
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
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
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
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
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
|
-
|
|
2972
|
+
return value;
|
|
2973
|
+
}
|
|
2954
2974
|
}
|
|
2955
2975
|
|
|
2956
2976
|
/**
|
package/src/settings.ts
CHANGED