tsvesync 1.0.46 → 1.0.48

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.
@@ -3,6 +3,16 @@
3
3
  */
4
4
  import { VeSyncBaseDevice } from './vesyncBaseDevice';
5
5
  import { Logger } from './logger';
6
+ /**
7
+ * Device exclusion configuration
8
+ */
9
+ export interface ExcludeConfig {
10
+ type?: string[];
11
+ model?: string[];
12
+ name?: string[];
13
+ namePattern?: string[];
14
+ id?: string[];
15
+ }
6
16
  /**
7
17
  * VeSync Manager Class
8
18
  */
@@ -14,6 +24,7 @@ export declare class VeSync {
14
24
  private _devList;
15
25
  private _lastUpdateTs;
16
26
  private _inProcess;
27
+ private _excludeConfig;
17
28
  username: string;
18
29
  password: string;
19
30
  token: string | null;
@@ -37,8 +48,9 @@ export declare class VeSync {
37
48
  * @param redact - Optional redact mode flag
38
49
  * @param apiUrl - Optional API base URL override
39
50
  * @param customLogger - Optional custom logger implementation
51
+ * @param excludeConfig - Optional device exclusion configuration
40
52
  */
41
- constructor(username: string, password: string, timeZone?: string, debug?: boolean, redact?: boolean, apiUrl?: string, customLogger?: Logger);
53
+ constructor(username: string, password: string, timeZone?: string, debug?: boolean, redact?: boolean, apiUrl?: string, customLogger?: Logger, excludeConfig?: ExcludeConfig);
42
54
  /**
43
55
  * Get/Set debug mode
44
56
  */
@@ -86,11 +98,14 @@ export declare class VeSync {
86
98
  * Test if update interval has been exceeded
87
99
  */
88
100
  deviceTimeCheck(): boolean;
101
+ /**
102
+ * Check if a device should be excluded based on configuration
103
+ */
104
+ private shouldExcludeDevice;
89
105
  /**
90
106
  * Update device list and details
91
- * @param excludeDevices - Optional array of device IDs to exclude from detail updates
92
107
  */
93
- update(excludeDevices?: string[]): Promise<void>;
108
+ update(): Promise<void>;
94
109
  /**
95
110
  * Create device instance from details
96
111
  */
@@ -129,14 +129,16 @@ class VeSync {
129
129
  * @param redact - Optional redact mode flag
130
130
  * @param apiUrl - Optional API base URL override
131
131
  * @param customLogger - Optional custom logger implementation
132
+ * @param excludeConfig - Optional device exclusion configuration
132
133
  */
133
- constructor(username, password, timeZone = helpers_1.DEFAULT_TZ, debug = false, redact = true, apiUrl, customLogger) {
134
+ constructor(username, password, timeZone = helpers_1.DEFAULT_TZ, debug = false, redact = true, apiUrl, customLogger, excludeConfig) {
134
135
  this._debug = debug;
135
136
  this._redact = redact;
136
137
  this._energyUpdateInterval = DEFAULT_ENERGY_UPDATE_INTERVAL;
137
138
  this._energyCheck = true;
138
139
  this._lastUpdateTs = null;
139
140
  this._inProcess = false;
141
+ this._excludeConfig = excludeConfig || null;
140
142
  this.username = username;
141
143
  this.password = password;
142
144
  this.token = null;
@@ -446,11 +448,56 @@ class VeSync {
446
448
  return (this._lastUpdateTs === null ||
447
449
  (Date.now() - this._lastUpdateTs) / 1000 > this.updateInterval);
448
450
  }
451
+ /**
452
+ * Check if a device should be excluded based on configuration
453
+ */
454
+ shouldExcludeDevice(device) {
455
+ var _a, _b, _c, _d, _e;
456
+ if (!this._excludeConfig) {
457
+ return false;
458
+ }
459
+ const exclude = this._excludeConfig;
460
+ // Check device type
461
+ if ((_a = exclude.type) === null || _a === void 0 ? void 0 : _a.includes(device.deviceType.toLowerCase())) {
462
+ logger_1.logger.debug(`Excluding device ${device.deviceName} by type: ${device.deviceType}`);
463
+ return true;
464
+ }
465
+ // Check device model
466
+ if ((_b = exclude.model) === null || _b === void 0 ? void 0 : _b.some(model => device.deviceType.toUpperCase().includes(model.toUpperCase()))) {
467
+ logger_1.logger.debug(`Excluding device ${device.deviceName} by model: ${device.deviceType}`);
468
+ return true;
469
+ }
470
+ // Check exact name match
471
+ if ((_c = exclude.name) === null || _c === void 0 ? void 0 : _c.includes(device.deviceName.trim())) {
472
+ logger_1.logger.debug(`Excluding device ${device.deviceName} by exact name match`);
473
+ return true;
474
+ }
475
+ // Check name patterns
476
+ if (exclude.namePattern) {
477
+ for (const pattern of exclude.namePattern) {
478
+ try {
479
+ const regex = new RegExp(pattern);
480
+ if (regex.test(device.deviceName.trim())) {
481
+ logger_1.logger.debug(`Excluding device ${device.deviceName} by name pattern: ${pattern}`);
482
+ return true;
483
+ }
484
+ }
485
+ catch (error) {
486
+ logger_1.logger.warn(`Invalid regex pattern in exclude config: ${pattern}`);
487
+ }
488
+ }
489
+ }
490
+ // Check device ID (cid or uuid)
491
+ if (((_d = exclude.id) === null || _d === void 0 ? void 0 : _d.includes(device.cid)) || ((_e = exclude.id) === null || _e === void 0 ? void 0 : _e.includes(device.uuid))) {
492
+ logger_1.logger.debug(`Excluding device ${device.deviceName} by ID: ${device.cid}/${device.uuid}`);
493
+ return true;
494
+ }
495
+ return false;
496
+ }
449
497
  /**
450
498
  * Update device list and details
451
- * @param excludeDevices - Optional array of device IDs to exclude from detail updates
452
499
  */
453
- async update(excludeDevices = []) {
500
+ async update() {
454
501
  if (this.deviceTimeCheck()) {
455
502
  if (!this.enabled) {
456
503
  logger_1.logger.error('Not logged in to VeSync');
@@ -460,13 +507,13 @@ class VeSync {
460
507
  logger_1.logger.debug('Start updating the device details one by one');
461
508
  for (const deviceList of Object.values(this._devList)) {
462
509
  for (const device of deviceList) {
463
- // Skip excluded devices
464
- if (excludeDevices.includes(device.cid)) {
465
- logger_1.logger.debug(`Skipping update for excluded device ${device.deviceName} (${device.cid})`);
466
- continue;
467
- }
468
510
  try {
469
- await device.getDetails();
511
+ if (!this.shouldExcludeDevice(device)) {
512
+ await device.getDetails();
513
+ }
514
+ else {
515
+ logger_1.logger.debug(`Skipping details update for excluded device: ${device.deviceName}`);
516
+ }
470
517
  }
471
518
  catch (error) {
472
519
  logger_1.logger.error(`Error updating ${device.deviceName}:`, error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsvesync",
3
- "version": "1.0.46",
3
+ "version": "1.0.48",
4
4
  "description": "A TypeScript library for interacting with VeSync smart home devices",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/lib/vesync.ts CHANGED
@@ -12,6 +12,17 @@ import { logger, setLogger, Logger } from './logger';
12
12
 
13
13
  const DEFAULT_ENERGY_UPDATE_INTERVAL = 21600;
14
14
 
15
+ /**
16
+ * Device exclusion configuration
17
+ */
18
+ export interface ExcludeConfig {
19
+ type?: string[];
20
+ model?: string[];
21
+ name?: string[];
22
+ namePattern?: string[];
23
+ id?: string[];
24
+ }
25
+
15
26
  // Device constructor type for concrete device classes only
16
27
  type DeviceConstructor = new (config: Record<string, any>, manager: VeSync) => VeSyncBaseDevice;
17
28
 
@@ -147,6 +158,7 @@ export class VeSync {
147
158
  private _devList: Record<string, VeSyncBaseDevice[]>;
148
159
  private _lastUpdateTs: number | null;
149
160
  private _inProcess: boolean;
161
+ private _excludeConfig: ExcludeConfig | null;
150
162
 
151
163
  username: string;
152
164
  password: string;
@@ -173,6 +185,7 @@ export class VeSync {
173
185
  * @param redact - Optional redact mode flag
174
186
  * @param apiUrl - Optional API base URL override
175
187
  * @param customLogger - Optional custom logger implementation
188
+ * @param excludeConfig - Optional device exclusion configuration
176
189
  */
177
190
  constructor(
178
191
  username: string,
@@ -181,7 +194,8 @@ export class VeSync {
181
194
  debug = false,
182
195
  redact = true,
183
196
  apiUrl?: string,
184
- customLogger?: Logger
197
+ customLogger?: Logger,
198
+ excludeConfig?: ExcludeConfig
185
199
  ) {
186
200
  this._debug = debug;
187
201
  this._redact = redact;
@@ -189,6 +203,7 @@ export class VeSync {
189
203
  this._energyCheck = true;
190
204
  this._lastUpdateTs = null;
191
205
  this._inProcess = false;
206
+ this._excludeConfig = excludeConfig || null;
192
207
 
193
208
  this.username = username;
194
209
  this.password = password;
@@ -547,11 +562,62 @@ export class VeSync {
547
562
  );
548
563
  }
549
564
 
565
+ /**
566
+ * Check if a device should be excluded based on configuration
567
+ */
568
+ private shouldExcludeDevice(device: VeSyncBaseDevice): boolean {
569
+ if (!this._excludeConfig) {
570
+ return false;
571
+ }
572
+
573
+ const exclude = this._excludeConfig;
574
+
575
+ // Check device type
576
+ if (exclude.type?.includes(device.deviceType.toLowerCase())) {
577
+ logger.debug(`Excluding device ${device.deviceName} by type: ${device.deviceType}`);
578
+ return true;
579
+ }
580
+
581
+ // Check device model
582
+ if (exclude.model?.some(model => device.deviceType.toUpperCase().includes(model.toUpperCase()))) {
583
+ logger.debug(`Excluding device ${device.deviceName} by model: ${device.deviceType}`);
584
+ return true;
585
+ }
586
+
587
+ // Check exact name match
588
+ if (exclude.name?.includes(device.deviceName.trim())) {
589
+ logger.debug(`Excluding device ${device.deviceName} by exact name match`);
590
+ return true;
591
+ }
592
+
593
+ // Check name patterns
594
+ if (exclude.namePattern) {
595
+ for (const pattern of exclude.namePattern) {
596
+ try {
597
+ const regex = new RegExp(pattern);
598
+ if (regex.test(device.deviceName.trim())) {
599
+ logger.debug(`Excluding device ${device.deviceName} by name pattern: ${pattern}`);
600
+ return true;
601
+ }
602
+ } catch (error) {
603
+ logger.warn(`Invalid regex pattern in exclude config: ${pattern}`);
604
+ }
605
+ }
606
+ }
607
+
608
+ // Check device ID (cid or uuid)
609
+ if (exclude.id?.includes(device.cid) || exclude.id?.includes(device.uuid)) {
610
+ logger.debug(`Excluding device ${device.deviceName} by ID: ${device.cid}/${device.uuid}`);
611
+ return true;
612
+ }
613
+
614
+ return false;
615
+ }
616
+
550
617
  /**
551
618
  * Update device list and details
552
- * @param excludeDevices - Optional array of device IDs to exclude from detail updates
553
619
  */
554
- async update(excludeDevices: string[] = []): Promise<void> {
620
+ async update(): Promise<void> {
555
621
  if (this.deviceTimeCheck()) {
556
622
  if (!this.enabled) {
557
623
  logger.error('Not logged in to VeSync');
@@ -563,14 +629,12 @@ export class VeSync {
563
629
  logger.debug('Start updating the device details one by one');
564
630
  for (const deviceList of Object.values(this._devList)) {
565
631
  for (const device of deviceList) {
566
- // Skip excluded devices
567
- if (excludeDevices.includes(device.cid)) {
568
- logger.debug(`Skipping update for excluded device ${device.deviceName} (${device.cid})`);
569
- continue;
570
- }
571
-
572
632
  try {
573
- await device.getDetails();
633
+ if (!this.shouldExcludeDevice(device)) {
634
+ await device.getDetails();
635
+ } else {
636
+ logger.debug(`Skipping details update for excluded device: ${device.deviceName}`);
637
+ }
574
638
  } catch (error) {
575
639
  logger.error(`Error updating ${device.deviceName}:`, error);
576
640
  }