tsvesync 1.0.25 → 1.0.27

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.
@@ -373,6 +373,7 @@ class VeSync {
373
373
  }
374
374
  else {
375
375
  logger_1.logger.error('No devices found in response');
376
+ logger_1.logger.error(response.code, response.msg);
376
377
  }
377
378
  }
378
379
  catch (error) {
@@ -35,11 +35,11 @@ export declare abstract class VeSyncBaseDevice {
35
35
  /**
36
36
  * Get device details
37
37
  */
38
- abstract getDetails(): Promise<void>;
38
+ abstract getDetails(): Promise<Boolean>;
39
39
  /**
40
40
  * Update device details
41
41
  */
42
- update(): Promise<void>;
42
+ update(): Promise<Boolean>;
43
43
  /**
44
44
  * Call API with proper headers
45
45
  */
@@ -84,7 +84,7 @@ class VeSyncBaseDevice {
84
84
  * Update device details
85
85
  */
86
86
  async update() {
87
- await this.getDetails();
87
+ return await this.getDetails();
88
88
  }
89
89
  /**
90
90
  * Call API with proper headers
@@ -31,11 +31,11 @@ export declare abstract class VeSyncBulb extends VeSyncBaseDevice {
31
31
  /**
32
32
  * Get bulb details
33
33
  */
34
- getDetails(): Promise<void>;
34
+ getDetails(): Promise<Boolean>;
35
35
  /**
36
- * Update bulb status
36
+ * Update bulb details
37
37
  */
38
- update(): Promise<void>;
38
+ update(): Promise<Boolean>;
39
39
  /**
40
40
  * Turn bulb on
41
41
  */
@@ -74,8 +74,9 @@ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
74
74
  getLightStatus: 'get'
75
75
  }
76
76
  };
77
- const [response] = await this.callApi(endpoint, 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
78
- if ((response === null || response === void 0 ? void 0 : response.code) === 0 && (response === null || response === void 0 ? void 0 : response.result)) {
77
+ const [response, statusCode] = await this.callApi(endpoint, 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
78
+ const success = this.checkResponse([response, statusCode], 'getDetails');
79
+ if (success && (response === null || response === void 0 ? void 0 : response.result)) {
79
80
  this.deviceStatus = response.result.enabled ? 'on' : 'off';
80
81
  this.brightness = response.result.brightness || this.brightness;
81
82
  if (this.features.includes('color_temp')) {
@@ -97,17 +98,16 @@ class VeSyncBulb extends vesyncBaseDevice_1.VeSyncBaseDevice {
97
98
  }
98
99
  logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved bulb details`);
99
100
  }
100
- else {
101
- logger_1.logger.error(`[${this.deviceName}] Failed to get bulb details: ${JSON.stringify(response)}`);
102
- }
101
+ return success;
103
102
  }
104
103
  /**
105
- * Update bulb status
104
+ * Update bulb details
106
105
  */
107
106
  async update() {
108
107
  logger_1.logger.debug(`[${this.deviceName}] Updating bulb information`);
109
- await this.getDetails();
108
+ const success = await this.getDetails();
110
109
  logger_1.logger.info(`[${this.deviceName}] Successfully updated bulb information`);
110
+ return success;
111
111
  }
112
112
  /**
113
113
  * Turn bulb on
@@ -71,7 +71,7 @@ export declare abstract class VeSyncFan extends VeSyncBaseDevice {
71
71
  * Return JSON details for fan
72
72
  */
73
73
  displayJSON(): string;
74
- abstract getDetails(): Promise<void>;
74
+ abstract getDetails(): Promise<Boolean>;
75
75
  abstract turnOn(): Promise<boolean>;
76
76
  abstract turnOff(): Promise<boolean>;
77
77
  abstract changeFanSpeed(speed: number): Promise<boolean>;
@@ -15,7 +15,7 @@ export declare class VeSyncAirBypass extends VeSyncFan {
15
15
  /**
16
16
  * Get device details
17
17
  */
18
- getDetails(): Promise<void>;
18
+ getDetails(): Promise<Boolean>;
19
19
  /**
20
20
  * Turn device on
21
21
  */
@@ -93,7 +93,7 @@ export declare class VeSyncHumidifier extends VeSyncFan {
93
93
  /**
94
94
  * Get device details
95
95
  */
96
- getDetails(): Promise<void>;
96
+ getDetails(): Promise<Boolean>;
97
97
  /**
98
98
  * Turn device on
99
99
  */
@@ -35,7 +35,8 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
35
35
  source: 'APP'
36
36
  }
37
37
  }, helpers_1.Helpers.reqHeaderBypass());
38
- if (this.checkResponse([response, status], 'getDetails')) {
38
+ const success = this.checkResponse([response, status], 'getDetails');
39
+ if (success) {
39
40
  const result = (_a = response === null || response === void 0 ? void 0 : response.result) === null || _a === void 0 ? void 0 : _a.result;
40
41
  if (result) {
41
42
  // Update device status
@@ -56,9 +57,7 @@ class VeSyncAirBypass extends vesyncFan_1.VeSyncFan {
56
57
  logger_1.logger.debug(`Successfully got details for device: ${this.deviceName}`);
57
58
  }
58
59
  }
59
- else {
60
- logger_1.logger.error(`Failed to get details for device: ${this.deviceName}`);
61
- }
60
+ return success;
62
61
  }
63
62
  /**
64
63
  * Turn device on
@@ -398,6 +397,7 @@ class VeSyncHumidifier extends vesyncFan_1.VeSyncFan {
398
397
  * Get device details
399
398
  */
400
399
  async getDetails() {
400
+ var _a;
401
401
  logger_1.logger.debug(`Getting details for device: ${this.deviceName}`);
402
402
  const [response, status] = await this.callApi('/cloud/v2/deviceManaged/bypassV2', 'post', {
403
403
  ...helpers_1.Helpers.reqBody(this.manager, 'bypassV2'),
@@ -410,13 +410,11 @@ class VeSyncHumidifier extends vesyncFan_1.VeSyncFan {
410
410
  }
411
411
  }, helpers_1.Helpers.reqHeaderBypass());
412
412
  const success = this.checkResponse([response, status], 'getDetails');
413
- if (success) {
413
+ if (success && ((_a = response === null || response === void 0 ? void 0 : response.result) === null || _a === void 0 ? void 0 : _a.result)) {
414
414
  this.details = response.result.result;
415
415
  logger_1.logger.debug(`Successfully got details for device: ${this.deviceName}`);
416
416
  }
417
- else {
418
- logger_1.logger.error(`Failed to get details for device: ${this.deviceName}`);
419
- }
417
+ return success;
420
418
  }
421
419
  /**
422
420
  * Turn device on
@@ -21,7 +21,7 @@ export declare abstract class VeSyncOutlet extends VeSyncBaseDevice {
21
21
  /**
22
22
  * Get outlet details
23
23
  */
24
- getDetails(): Promise<void>;
24
+ getDetails(): Promise<Boolean>;
25
25
  /**
26
26
  * Update outlet energy data
27
27
  */
@@ -53,7 +53,7 @@ export declare abstract class VeSyncOutlet extends VeSyncBaseDevice {
53
53
  /**
54
54
  * Update outlet details and energy info
55
55
  */
56
- update(): Promise<void>;
56
+ update(): Promise<Boolean>;
57
57
  /**
58
58
  * Check if outlet has nightlight feature
59
59
  */
@@ -66,15 +66,15 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
66
66
  else {
67
67
  url = '/v1/device/devicedetail';
68
68
  }
69
- const [response] = await this.callApi(url, this.deviceType === 'wifi-switch-1.3' ? 'get' : 'post', this.deviceType === 'wifi-switch-1.3' ? null : body, helpers_1.Helpers.reqHeaders(this.manager));
69
+ const [response, statusCode] = await this.callApi(url, this.deviceType === 'wifi-switch-1.3' ? 'get' : 'post', this.deviceType === 'wifi-switch-1.3' ? null : body, helpers_1.Helpers.reqHeaders(this.manager));
70
70
  if (!response) {
71
71
  logger_1.logger.debug(`[${this.deviceName}] No response received from API`);
72
- return;
72
+ return false;
73
73
  }
74
74
  // Handle error responses
75
75
  if (response.error) {
76
76
  logger_1.logger.debug(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
77
- return;
77
+ return false;
78
78
  }
79
79
  // Handle successful responses
80
80
  if (response.code === 0) {
@@ -102,7 +102,7 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
102
102
  if (subDevice) {
103
103
  this.deviceStatus = subDevice.subDeviceStatus;
104
104
  logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved sub-device status: ${this.deviceStatus}`);
105
- return;
105
+ return true;
106
106
  }
107
107
  }
108
108
  // Handle regular devices
@@ -117,12 +117,14 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
117
117
  }
118
118
  else {
119
119
  logger_1.logger.debug(`[${this.deviceName}] Device status not found in response: ${JSON.stringify(response)}`);
120
- return;
120
+ return false;
121
121
  }
122
122
  logger_1.logger.debug(`[${this.deviceName}] Successfully retrieved outlet details`);
123
+ return true;
123
124
  }
124
125
  else {
125
126
  logger_1.logger.debug(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
127
+ return false;
126
128
  }
127
129
  }
128
130
  /**
@@ -313,11 +315,12 @@ class VeSyncOutlet extends vesyncBaseDevice_1.VeSyncBaseDevice {
313
315
  */
314
316
  async update() {
315
317
  logger_1.logger.debug(`[${this.deviceName}] Updating outlet information`);
316
- await this.getDetails();
317
- if (this.features.includes('energy')) {
318
+ const success = await this.getDetails();
319
+ if (success && this.features.includes('energy')) {
318
320
  await this.updateEnergy();
319
321
  }
320
322
  logger_1.logger.info(`[${this.deviceName}] Successfully updated outlet information`);
323
+ return success;
321
324
  }
322
325
  /**
323
326
  * Check if outlet has nightlight feature
@@ -33,13 +33,16 @@ export declare abstract class VeSyncSwitch extends VeSyncBaseDevice {
33
33
  * Return JSON details for switch
34
34
  */
35
35
  displayJSON(): string;
36
- abstract getDetails(): Promise<void>;
36
+ /**
37
+ * Get switch details
38
+ */
39
+ abstract getDetails(): Promise<Boolean>;
40
+ /**
41
+ * Update switch details
42
+ */
43
+ update(): Promise<Boolean>;
37
44
  abstract getConfig(): Promise<void>;
38
45
  abstract turnOn(): Promise<boolean>;
39
46
  abstract turnOff(): Promise<boolean>;
40
- /**
41
- * Update device details
42
- */
43
- update(): Promise<void>;
44
47
  }
45
48
  export {};
@@ -69,10 +69,13 @@ class VeSyncSwitch extends vesyncBaseDevice_1.VeSyncBaseDevice {
69
69
  }, null, 4);
70
70
  }
71
71
  /**
72
- * Update device details
72
+ * Update switch details
73
73
  */
74
74
  async update() {
75
- await this.getDetails();
75
+ logger_1.logger.debug(`[${this.deviceName}] Updating switch information`);
76
+ const success = await this.getDetails();
77
+ logger_1.logger.debug(`[${this.deviceName}] Successfully updated switch information`);
78
+ return success;
76
79
  }
77
80
  }
78
81
  exports.VeSyncSwitch = VeSyncSwitch;
@@ -11,7 +11,7 @@ export declare class VeSyncWallSwitch extends VeSyncSwitch {
11
11
  /**
12
12
  * Get wall switch details
13
13
  */
14
- getDetails(): Promise<void>;
14
+ getDetails(): Promise<Boolean>;
15
15
  /**
16
16
  * Get switch device configuration info
17
17
  */
@@ -37,7 +37,7 @@ export declare class VeSyncDimmerSwitch extends VeSyncSwitch {
37
37
  /**
38
38
  * Get dimmer switch details
39
39
  */
40
- getDetails(): Promise<void>;
40
+ getDetails(): Promise<Boolean>;
41
41
  /**
42
42
  * Get dimmer switch configuration info
43
43
  */
@@ -25,17 +25,16 @@ class VeSyncWallSwitch extends vesyncSwitch_1.VeSyncSwitch {
25
25
  uuid: this.cid,
26
26
  method: 'devicedetail'
27
27
  };
28
- const [response] = await this.callApi('/inwallswitch/v1/device/devicedetail', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
29
- if ((response === null || response === void 0 ? void 0 : response.code) === 0 && (response === null || response === void 0 ? void 0 : response.result)) {
28
+ const [response, statusCode] = await this.callApi('/inwallswitch/v1/device/devicedetail', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
29
+ const success = this.checkResponse([response, statusCode], 'getDetails');
30
+ if (success && (response === null || response === void 0 ? void 0 : response.result)) {
30
31
  const result = response.result;
31
32
  this.deviceStatus = result.deviceStatus || this.deviceStatus;
32
33
  this.details.active_time = result.activeTime || 0;
33
34
  this.connectionStatus = result.connectionStatus || this.connectionStatus;
34
35
  logger_1.logger.debug(`Successfully got details for device: ${this.deviceName}`);
35
36
  }
36
- else {
37
- logger_1.logger.error(`Failed to get details for device: ${this.deviceName}`);
38
- }
37
+ return success;
39
38
  }
40
39
  /**
41
40
  * Get switch device configuration info
@@ -118,8 +117,9 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
118
117
  uuid: this.cid,
119
118
  method: 'devicedetail'
120
119
  };
121
- const [response] = await this.callApi('/dimmer/v1/device/devicedetail', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
122
- if ((response === null || response === void 0 ? void 0 : response.code) === 0 && (response === null || response === void 0 ? void 0 : response.result)) {
120
+ const [response, statusCode] = await this.callApi('/dimmer/v1/device/devicedetail', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
121
+ const success = this.checkResponse([response, statusCode], 'getDetails');
122
+ if (success && (response === null || response === void 0 ? void 0 : response.result)) {
123
123
  const result = response.result;
124
124
  this.deviceStatus = result.deviceStatus || this.deviceStatus;
125
125
  this.details.active_time = result.activeTime || 0;
@@ -136,9 +136,7 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
136
136
  }
137
137
  logger_1.logger.debug(`Successfully got details for device: ${this.deviceName}`);
138
138
  }
139
- else {
140
- logger_1.logger.error(`Failed to get details for device: ${this.deviceName}`);
141
- }
139
+ return success;
142
140
  }
143
141
  /**
144
142
  * Get dimmer switch configuration info
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsvesync",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
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
@@ -456,6 +456,7 @@ export class VeSync {
456
456
  logger.debug('\n=== End of Device Discovery ===\n');
457
457
  } else {
458
458
  logger.error('No devices found in response');
459
+ logger.error(response.code, response.msg);
459
460
  }
460
461
  } catch (error) {
461
462
  logger.error('Unable to get device list:', error);
@@ -105,13 +105,13 @@ export abstract class VeSyncBaseDevice {
105
105
  /**
106
106
  * Get device details
107
107
  */
108
- abstract getDetails(): Promise<void>;
108
+ abstract getDetails(): Promise<Boolean>;
109
109
 
110
110
  /**
111
111
  * Update device details
112
112
  */
113
- async update(): Promise<void> {
114
- await this.getDetails();
113
+ async update(): Promise<Boolean> {
114
+ return await this.getDetails();
115
115
  }
116
116
 
117
117
  /**
@@ -71,7 +71,7 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
71
71
  /**
72
72
  * Get bulb details
73
73
  */
74
- async getDetails(): Promise<void> {
74
+ async getDetails(): Promise<Boolean> {
75
75
  logger.debug(`[${this.deviceName}] Getting bulb details`);
76
76
 
77
77
  const isV2Device = this.deviceType === 'XYD0001';
@@ -94,14 +94,15 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
94
94
  }
95
95
  };
96
96
 
97
- const [response] = await this.callApi(
97
+ const [response, statusCode] = await this.callApi(
98
98
  endpoint,
99
99
  'post',
100
100
  body,
101
101
  Helpers.reqHeaders(this.manager)
102
102
  );
103
103
 
104
- if (response?.code === 0 && response?.result) {
104
+ const success = this.checkResponse([response, statusCode], 'getDetails');
105
+ if (success && response?.result) {
105
106
  this.deviceStatus = response.result.enabled ? 'on' : 'off';
106
107
  this.brightness = response.result.brightness || this.brightness;
107
108
  if (this.features.includes('color_temp')) {
@@ -121,18 +122,18 @@ export abstract class VeSyncBulb extends VeSyncBaseDevice {
121
122
  }
122
123
  }
123
124
  logger.debug(`[${this.deviceName}] Successfully retrieved bulb details`);
124
- } else {
125
- logger.error(`[${this.deviceName}] Failed to get bulb details: ${JSON.stringify(response)}`);
126
125
  }
126
+ return success;
127
127
  }
128
128
 
129
129
  /**
130
- * Update bulb status
130
+ * Update bulb details
131
131
  */
132
- async update(): Promise<void> {
132
+ async update(): Promise<Boolean> {
133
133
  logger.debug(`[${this.deviceName}] Updating bulb information`);
134
- await this.getDetails();
134
+ const success = await this.getDetails();
135
135
  logger.info(`[${this.deviceName}] Successfully updated bulb information`);
136
+ return success;
136
137
  }
137
138
 
138
139
  /**
@@ -437,7 +437,7 @@ export abstract class VeSyncFan extends VeSyncBaseDevice {
437
437
  }, null, 4);
438
438
  }
439
439
 
440
- abstract getDetails(): Promise<void>;
440
+ abstract getDetails(): Promise<Boolean>;
441
441
  abstract turnOn(): Promise<boolean>;
442
442
  abstract turnOff(): Promise<boolean>;
443
443
  abstract changeFanSpeed(speed: number): Promise<boolean>;
@@ -24,7 +24,7 @@ export class VeSyncAirBypass extends VeSyncFan {
24
24
  /**
25
25
  * Get device details
26
26
  */
27
- async getDetails(): Promise<void> {
27
+ async getDetails(): Promise<Boolean> {
28
28
  logger.debug(`Getting details for device: ${this.deviceName}`);
29
29
  const [response, status] = await this.callApi(
30
30
  '/cloud/v2/deviceManaged/bypassV2',
@@ -42,7 +42,8 @@ export class VeSyncAirBypass extends VeSyncFan {
42
42
  Helpers.reqHeaderBypass()
43
43
  );
44
44
 
45
- if (this.checkResponse([response, status], 'getDetails')) {
45
+ const success = this.checkResponse([response, status], 'getDetails');
46
+ if (success) {
46
47
  const result = response?.result?.result;
47
48
  if (result) {
48
49
  // Update device status
@@ -64,9 +65,8 @@ export class VeSyncAirBypass extends VeSyncFan {
64
65
  }
65
66
  logger.debug(`Successfully got details for device: ${this.deviceName}`);
66
67
  }
67
- } else {
68
- logger.error(`Failed to get details for device: ${this.deviceName}`);
69
68
  }
69
+ return success;
70
70
  }
71
71
 
72
72
  /**
@@ -488,7 +488,7 @@ export class VeSyncHumidifier extends VeSyncFan {
488
488
  /**
489
489
  * Get device details
490
490
  */
491
- async getDetails(): Promise<void> {
491
+ async getDetails(): Promise<Boolean> {
492
492
  logger.debug(`Getting details for device: ${this.deviceName}`);
493
493
  const [response, status] = await this.callApi(
494
494
  '/cloud/v2/deviceManaged/bypassV2',
@@ -507,12 +507,11 @@ export class VeSyncHumidifier extends VeSyncFan {
507
507
  );
508
508
 
509
509
  const success = this.checkResponse([response, status], 'getDetails');
510
- if (success) {
510
+ if (success && response?.result?.result) {
511
511
  this.details = response.result.result;
512
512
  logger.debug(`Successfully got details for device: ${this.deviceName}`);
513
- } else {
514
- logger.error(`Failed to get details for device: ${this.deviceName}`);
515
513
  }
514
+ return success;
516
515
  }
517
516
 
518
517
  /**
@@ -56,7 +56,7 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
56
56
  /**
57
57
  * Get outlet details
58
58
  */
59
- async getDetails(): Promise<void> {
59
+ async getDetails(): Promise<Boolean> {
60
60
  logger.debug(`[${this.deviceName}] Getting outlet details`);
61
61
 
62
62
  const body = {
@@ -77,7 +77,7 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
77
77
  url = '/v1/device/devicedetail';
78
78
  }
79
79
 
80
- const [response] = await this.callApi(
80
+ const [response, statusCode] = await this.callApi(
81
81
  url,
82
82
  this.deviceType === 'wifi-switch-1.3' ? 'get' : 'post',
83
83
  this.deviceType === 'wifi-switch-1.3' ? null : body,
@@ -86,13 +86,13 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
86
86
 
87
87
  if (!response) {
88
88
  logger.debug(`[${this.deviceName}] No response received from API`);
89
- return;
89
+ return false;
90
90
  }
91
91
 
92
92
  // Handle error responses
93
93
  if (response.error) {
94
94
  logger.debug(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
95
- return;
95
+ return false;
96
96
  }
97
97
 
98
98
  // Handle successful responses
@@ -126,7 +126,7 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
126
126
  if (subDevice) {
127
127
  this.deviceStatus = subDevice.subDeviceStatus;
128
128
  logger.debug(`[${this.deviceName}] Successfully retrieved sub-device status: ${this.deviceStatus}`);
129
- return;
129
+ return true;
130
130
  }
131
131
  }
132
132
 
@@ -139,11 +139,13 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
139
139
  this.deviceStatus = response.power === 'on' ? 'on' : 'off';
140
140
  } else {
141
141
  logger.debug(`[${this.deviceName}] Device status not found in response: ${JSON.stringify(response)}`);
142
- return;
142
+ return false;
143
143
  }
144
144
  logger.debug(`[${this.deviceName}] Successfully retrieved outlet details`);
145
+ return true;
145
146
  } else {
146
147
  logger.debug(`[${this.deviceName}] Failed to get outlet details: ${JSON.stringify(response)}`);
148
+ return false;
147
149
  }
148
150
  }
149
151
 
@@ -364,13 +366,14 @@ export abstract class VeSyncOutlet extends VeSyncBaseDevice {
364
366
  /**
365
367
  * Update outlet details and energy info
366
368
  */
367
- async update(): Promise<void> {
369
+ async update(): Promise<Boolean> {
368
370
  logger.debug(`[${this.deviceName}] Updating outlet information`);
369
- await this.getDetails();
370
- if (this.features.includes('energy')) {
371
+ const success = await this.getDetails();
372
+ if (success && this.features.includes('energy')) {
371
373
  await this.updateEnergy();
372
374
  }
373
375
  logger.info(`[${this.deviceName}] Successfully updated outlet information`);
376
+ return success;
374
377
  }
375
378
 
376
379
  /**
@@ -81,15 +81,22 @@ export abstract class VeSyncSwitch extends VeSyncBaseDevice {
81
81
  }, null, 4);
82
82
  }
83
83
 
84
- abstract getDetails(): Promise<void>;
85
- abstract getConfig(): Promise<void>;
86
- abstract turnOn(): Promise<boolean>;
87
- abstract turnOff(): Promise<boolean>;
84
+ /**
85
+ * Get switch details
86
+ */
87
+ abstract getDetails(): Promise<Boolean>;
88
88
 
89
89
  /**
90
- * Update device details
90
+ * Update switch details
91
91
  */
92
- async update(): Promise<void> {
93
- await this.getDetails();
92
+ async update(): Promise<Boolean> {
93
+ logger.debug(`[${this.deviceName}] Updating switch information`);
94
+ const success = await this.getDetails();
95
+ logger.debug(`[${this.deviceName}] Successfully updated switch information`);
96
+ return success;
94
97
  }
98
+
99
+ abstract getConfig(): Promise<void>;
100
+ abstract turnOn(): Promise<boolean>;
101
+ abstract turnOff(): Promise<boolean>;
95
102
  }
@@ -19,7 +19,7 @@ export class VeSyncWallSwitch extends VeSyncSwitch {
19
19
  /**
20
20
  * Get wall switch details
21
21
  */
22
- async getDetails(): Promise<void> {
22
+ async getDetails(): Promise<Boolean> {
23
23
  logger.debug(`Getting details for device: ${this.deviceName}`);
24
24
  const body = {
25
25
  ...Helpers.reqBody(this.manager, 'devicedetail'),
@@ -27,22 +27,22 @@ export class VeSyncWallSwitch extends VeSyncSwitch {
27
27
  method: 'devicedetail'
28
28
  };
29
29
 
30
- const [response] = await this.callApi(
30
+ const [response, statusCode] = await this.callApi(
31
31
  '/inwallswitch/v1/device/devicedetail',
32
32
  'post',
33
33
  body,
34
34
  Helpers.reqHeaders(this.manager)
35
35
  );
36
36
 
37
- if (response?.code === 0 && response?.result) {
37
+ const success = this.checkResponse([response, statusCode], 'getDetails');
38
+ if (success && response?.result) {
38
39
  const result = response.result;
39
40
  this.deviceStatus = result.deviceStatus || this.deviceStatus;
40
41
  this.details.active_time = result.activeTime || 0;
41
42
  this.connectionStatus = result.connectionStatus || this.connectionStatus;
42
43
  logger.debug(`Successfully got details for device: ${this.deviceName}`);
43
- } else {
44
- logger.error(`Failed to get details for device: ${this.deviceName}`);
45
44
  }
45
+ return success;
46
46
  }
47
47
 
48
48
  /**
@@ -143,7 +143,7 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
143
143
  /**
144
144
  * Get dimmer switch details
145
145
  */
146
- async getDetails(): Promise<void> {
146
+ async getDetails(): Promise<Boolean> {
147
147
  logger.debug(`Getting details for device: ${this.deviceName}`);
148
148
  const body = {
149
149
  ...Helpers.reqBody(this.manager, 'devicedetail'),
@@ -151,14 +151,15 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
151
151
  method: 'devicedetail'
152
152
  };
153
153
 
154
- const [response] = await this.callApi(
154
+ const [response, statusCode] = await this.callApi(
155
155
  '/dimmer/v1/device/devicedetail',
156
156
  'post',
157
157
  body,
158
158
  Helpers.reqHeaders(this.manager)
159
159
  );
160
160
 
161
- if (response?.code === 0 && response?.result) {
161
+ const success = this.checkResponse([response, statusCode], 'getDetails');
162
+ if (success && response?.result) {
162
163
  const result = response.result;
163
164
  this.deviceStatus = result.deviceStatus || this.deviceStatus;
164
165
  this.details.active_time = result.activeTime || 0;
@@ -174,9 +175,8 @@ export class VeSyncDimmerSwitch extends VeSyncSwitch {
174
175
  };
175
176
  }
176
177
  logger.debug(`Successfully got details for device: ${this.deviceName}`);
177
- } else {
178
- logger.error(`Failed to get details for device: ${this.deviceName}`);
179
178
  }
179
+ return success;
180
180
  }
181
181
 
182
182
  /**