tsvesync 1.0.56 → 1.0.58

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.
@@ -16,6 +16,11 @@ export declare abstract class VeSyncBaseDevice {
16
16
  deviceCategory: string;
17
17
  connectionStatus: string;
18
18
  constructor(details: Record<string, any>, manager: VeSync);
19
+ /**
20
+ * Normalize device type to match configuration keys
21
+ * This handles variations in device type strings from the API
22
+ */
23
+ protected normalizeDeviceType(deviceType: string): string;
19
24
  /**
20
25
  * Return formatted device info to stdout
21
26
  */
@@ -13,7 +13,7 @@ class VeSyncBaseDevice {
13
13
  this.cid = details.cid || '';
14
14
  this.deviceName = details.deviceName || '';
15
15
  this.deviceStatus = details.deviceStatus || 'off';
16
- this.deviceType = details.deviceType || '';
16
+ this.deviceType = this.normalizeDeviceType(details.deviceType || '');
17
17
  this.deviceRegion = details.deviceRegion || '';
18
18
  this.uuid = details.uuid || '';
19
19
  this.configModule = details.configModule || '';
@@ -21,6 +21,34 @@ class VeSyncBaseDevice {
21
21
  this.deviceCategory = details.deviceCategory || '';
22
22
  this.connectionStatus = details.connectionStatus || 'offline';
23
23
  }
24
+ /**
25
+ * Normalize device type to match configuration keys
26
+ * This handles variations in device type strings from the API
27
+ */
28
+ normalizeDeviceType(deviceType) {
29
+ // Remove any region suffixes (e.g. -USA, -EU)
30
+ const baseType = deviceType.split('-')[0];
31
+ // Handle known prefix mappings
32
+ const prefixMap = {
33
+ 'Core': 'Core',
34
+ 'LAP': 'LAP',
35
+ 'LTF': 'LTF',
36
+ 'Classic': 'Classic',
37
+ 'Dual': 'Dual',
38
+ 'LUH': 'LUH',
39
+ 'LEH': 'LEH',
40
+ 'LV-PUR': 'LV-PUR',
41
+ 'LV-RH': 'LV-RH'
42
+ };
43
+ // Check if the device type starts with any known prefix
44
+ for (const [prefix, normalized] of Object.entries(prefixMap)) {
45
+ if (deviceType.startsWith(prefix)) {
46
+ return deviceType; // Keep the full device type for exact matches
47
+ }
48
+ }
49
+ // If no prefix match, return the base type
50
+ return baseType;
51
+ }
24
52
  /**
25
53
  * Return formatted device info to stdout
26
54
  */
@@ -328,11 +328,22 @@ class VeSyncFan extends vesyncBaseDevice_1.VeSyncBaseDevice {
328
328
  this.speed_dict = {};
329
329
  this._timer = null;
330
330
  this.details = details;
331
- this.config = exports.fanConfig[this.deviceType] || {
331
+ // Try exact match first
332
+ let config = exports.fanConfig[this.deviceType];
333
+ // If no exact match, try base type
334
+ if (!config) {
335
+ const baseType = this.deviceType.split('-')[0];
336
+ config = exports.fanConfig[baseType];
337
+ }
338
+ // If still no match, use default
339
+ this.config = config || {
332
340
  module: 'VeSyncAirBypass',
333
341
  features: [],
334
342
  levels: []
335
343
  };
344
+ if (!config) {
345
+ logger_1.logger.debug(`No configuration found for device type: ${this.deviceType}`);
346
+ }
336
347
  }
337
348
  /**
338
349
  * Check if feature is supported
@@ -210,14 +210,14 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
210
210
  * Change fan speed
211
211
  */
212
212
  async changeFanSpeed(speed) {
213
- var _a, _b;
213
+ var _a;
214
214
  logger_1.logger.debug(`Attempting to change fan speed to ${speed} for device: ${this.deviceName}`);
215
215
  logger_1.logger.debug(`Available speeds: ${(_a = this.config.levels) === null || _a === void 0 ? void 0 : _a.join(', ')}`);
216
- const speeds = (_b = this.config.levels) !== null && _b !== void 0 ? _b : [];
217
- if (!speeds.includes(speed)) {
218
- logger_1.logger.debug(`Invalid speed: ${speed}. Must be one of: ${speeds.join(', ')}`);
219
- return false;
220
- }
216
+ // const speeds = this.config.levels ?? [];
217
+ // if (!speeds.includes(speed)) {
218
+ // logger.debug(`Invalid speed: ${speed}. Must be one of: ${speeds.join(', ')}`);
219
+ // return false;
220
+ // }
221
221
  logger_1.logger.info(`Changing fan speed to ${speed} for device: ${this.deviceName}`);
222
222
  const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
223
223
  ...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
@@ -1304,12 +1304,11 @@ class VeSyncAirBaseV2 extends VeSyncAirBypass {
1304
1304
  * Change fan speed
1305
1305
  */
1306
1306
  async changeFanSpeed(speed) {
1307
- var _a;
1308
- const speeds = (_a = this.config.levels) !== null && _a !== void 0 ? _a : [];
1309
- if (!speeds.includes(speed)) {
1310
- logger_1.logger.error(`Invalid speed: ${speed}. Must be one of: ${speeds.join(', ')} for device: ${this.deviceName}`);
1311
- return false;
1312
- }
1307
+ // const speeds = this.config.levels ?? [];
1308
+ // if (!speeds.includes(speed)) {
1309
+ // logger.error(`Invalid speed: ${speed}. Must be one of: ${speeds.join(', ')} for device: ${this.deviceName}`);
1310
+ // return false;
1311
+ // }
1313
1312
  logger_1.logger.info(`Changing fan speed to ${speed} for device: ${this.deviceName}`);
1314
1313
  const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
1315
1314
  ...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
@@ -1713,12 +1712,11 @@ class VeSyncTowerFan extends VeSyncAirBaseV2 {
1713
1712
  * Change fan speed
1714
1713
  */
1715
1714
  async changeFanSpeed(speed) {
1716
- var _a;
1717
- const speeds = (_a = this.config.levels) !== null && _a !== void 0 ? _a : [];
1718
- if (!speeds.includes(speed)) {
1719
- logger_1.logger.debug(`Invalid speed: ${speed}. Must be one of: ${speeds.join(', ')}`);
1720
- return false;
1721
- }
1715
+ // const speeds = this.config.levels ?? [];
1716
+ // if (!speeds.includes(speed)) {
1717
+ // logger.debug(`Invalid speed: ${speed}. Must be one of: ${speeds.join(', ')}`);
1718
+ // return false;
1719
+ // }
1722
1720
  const [head, body] = this.buildApiDict('setLevel');
1723
1721
  body.payload.data = {
1724
1722
  levelIdx: 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsvesync",
3
- "version": "1.0.56",
3
+ "version": "1.0.58",
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",
@@ -26,7 +26,7 @@ export abstract class VeSyncBaseDevice {
26
26
  this.cid = details.cid || '';
27
27
  this.deviceName = details.deviceName || '';
28
28
  this.deviceStatus = details.deviceStatus || 'off';
29
- this.deviceType = details.deviceType || '';
29
+ this.deviceType = this.normalizeDeviceType(details.deviceType || '');
30
30
  this.deviceRegion = details.deviceRegion || '';
31
31
  this.uuid = details.uuid || '';
32
32
  this.configModule = details.configModule || '';
@@ -35,6 +35,38 @@ export abstract class VeSyncBaseDevice {
35
35
  this.connectionStatus = details.connectionStatus || 'offline';
36
36
  }
37
37
 
38
+ /**
39
+ * Normalize device type to match configuration keys
40
+ * This handles variations in device type strings from the API
41
+ */
42
+ protected normalizeDeviceType(deviceType: string): string {
43
+ // Remove any region suffixes (e.g. -USA, -EU)
44
+ const baseType = deviceType.split('-')[0];
45
+
46
+ // Handle known prefix mappings
47
+ const prefixMap: Record<string, string> = {
48
+ 'Core': 'Core',
49
+ 'LAP': 'LAP',
50
+ 'LTF': 'LTF',
51
+ 'Classic': 'Classic',
52
+ 'Dual': 'Dual',
53
+ 'LUH': 'LUH',
54
+ 'LEH': 'LEH',
55
+ 'LV-PUR': 'LV-PUR',
56
+ 'LV-RH': 'LV-RH'
57
+ };
58
+
59
+ // Check if the device type starts with any known prefix
60
+ for (const [prefix, normalized] of Object.entries(prefixMap)) {
61
+ if (deviceType.startsWith(prefix)) {
62
+ return deviceType; // Keep the full device type for exact matches
63
+ }
64
+ }
65
+
66
+ // If no prefix match, return the base type
67
+ return baseType;
68
+ }
69
+
38
70
  /**
39
71
  * Return formatted device info to stdout
40
72
  */
@@ -362,11 +362,26 @@ export abstract class VeSyncFan extends VeSyncBaseDevice {
362
362
  constructor(details: Record<string, any>, manager: VeSync) {
363
363
  super(details, manager);
364
364
  this.details = details;
365
- this.config = fanConfig[this.deviceType] || {
365
+
366
+ // Try exact match first
367
+ let config = fanConfig[this.deviceType];
368
+
369
+ // If no exact match, try base type
370
+ if (!config) {
371
+ const baseType = this.deviceType.split('-')[0];
372
+ config = fanConfig[baseType];
373
+ }
374
+
375
+ // If still no match, use default
376
+ this.config = config || {
366
377
  module: 'VeSyncAirBypass',
367
378
  features: [],
368
379
  levels: []
369
380
  };
381
+
382
+ if (!config) {
383
+ logger.debug(`No configuration found for device type: ${this.deviceType}`);
384
+ }
370
385
  }
371
386
 
372
387
  /**
@@ -261,11 +261,11 @@ export class VeSyncAirBypass extends VeSyncFan {
261
261
  logger.debug(`Attempting to change fan speed to ${speed} for device: ${this.deviceName}`);
262
262
  logger.debug(`Available speeds: ${this.config.levels?.join(', ')}`);
263
263
 
264
- const speeds = this.config.levels ?? [];
265
- if (!speeds.includes(speed)) {
266
- logger.debug(`Invalid speed: ${speed}. Must be one of: ${speeds.join(', ')}`);
267
- return false;
268
- }
264
+ // const speeds = this.config.levels ?? [];
265
+ // if (!speeds.includes(speed)) {
266
+ // logger.debug(`Invalid speed: ${speed}. Must be one of: ${speeds.join(', ')}`);
267
+ // return false;
268
+ // }
269
269
 
270
270
  logger.info(`Changing fan speed to ${speed} for device: ${this.deviceName}`);
271
271
  const [response, status] = await this.callApi(
@@ -1576,11 +1576,11 @@ export class VeSyncAirBaseV2 extends VeSyncAirBypass {
1576
1576
  * Change fan speed
1577
1577
  */
1578
1578
  async changeFanSpeed(speed: number): Promise<boolean> {
1579
- const speeds = this.config.levels ?? [];
1580
- if (!speeds.includes(speed)) {
1581
- logger.error(`Invalid speed: ${speed}. Must be one of: ${speeds.join(', ')} for device: ${this.deviceName}`);
1582
- return false;
1583
- }
1579
+ // const speeds = this.config.levels ?? [];
1580
+ // if (!speeds.includes(speed)) {
1581
+ // logger.error(`Invalid speed: ${speed}. Must be one of: ${speeds.join(', ')} for device: ${this.deviceName}`);
1582
+ // return false;
1583
+ // }
1584
1584
 
1585
1585
  logger.info(`Changing fan speed to ${speed} for device: ${this.deviceName}`);
1586
1586
  const [response, status] = await this.callApi(
@@ -2106,11 +2106,11 @@ export class VeSyncTowerFan extends VeSyncAirBaseV2 {
2106
2106
  * Change fan speed
2107
2107
  */
2108
2108
  async changeFanSpeed(speed: number): Promise<boolean> {
2109
- const speeds = this.config.levels ?? [];
2110
- if (!speeds.includes(speed)) {
2111
- logger.debug(`Invalid speed: ${speed}. Must be one of: ${speeds.join(', ')}`);
2112
- return false;
2113
- }
2109
+ // const speeds = this.config.levels ?? [];
2110
+ // if (!speeds.includes(speed)) {
2111
+ // logger.debug(`Invalid speed: ${speed}. Must be one of: ${speeds.join(', ')}`);
2112
+ // return false;
2113
+ // }
2114
2114
 
2115
2115
  const [head, body] = this.buildApiDict('setLevel');
2116
2116
  body.payload.data = {