tsvesync 1.0.12 → 1.0.14

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 (70) hide show
  1. package/dist/lib/helpers.js +3 -2
  2. package/dist/lib/logger.d.ts +23 -0
  3. package/dist/lib/logger.js +54 -0
  4. package/dist/lib/vesync.js +42 -41
  5. package/dist/lib/vesyncBaseDevice.js +8 -7
  6. package/dist/lib/vesyncBulb.d.ts +9 -0
  7. package/dist/lib/vesyncBulb.js +125 -28
  8. package/dist/lib/vesyncBulbImpl.d.ts +1 -1
  9. package/dist/lib/vesyncBulbImpl.js +105 -36
  10. package/dist/lib/vesyncFan.js +2 -1
  11. package/dist/lib/vesyncFanImpl.d.ts +36 -0
  12. package/dist/lib/vesyncFanImpl.js +307 -42
  13. package/dist/lib/vesyncOutlet.d.ts +17 -0
  14. package/dist/lib/vesyncOutlet.js +124 -8
  15. package/dist/lib/vesyncOutletImpl.js +39 -0
  16. package/dist/lib/vesyncSwitch.d.ts +0 -124
  17. package/dist/lib/vesyncSwitch.js +3 -343
  18. package/dist/lib/vesyncSwitchImpl.d.ts +6 -6
  19. package/dist/lib/vesyncSwitchImpl.js +69 -15
  20. package/package.json +1 -1
  21. package/src/lib/helpers.ts +3 -2
  22. package/src/lib/logger.ts +60 -0
  23. package/src/lib/vesync.ts +42 -43
  24. package/src/lib/vesyncBaseDevice.ts +8 -7
  25. package/src/lib/vesyncBulb.ts +138 -30
  26. package/src/lib/vesyncBulbImpl.ts +113 -44
  27. package/src/lib/vesyncFan.ts +2 -4
  28. package/src/lib/vesyncFanImpl.ts +314 -42
  29. package/src/lib/vesyncOutlet.ts +140 -13
  30. package/src/lib/vesyncOutletImpl.ts +41 -0
  31. package/src/lib/vesyncSwitch.ts +3 -454
  32. package/src/lib/vesyncSwitchImpl.ts +66 -16
  33. package/dist/lib/helpers.js.map +0 -1
  34. package/dist/lib/vesync.js.map +0 -1
  35. package/dist/lib/vesyncBaseDevice.js.map +0 -1
  36. package/dist/lib/vesyncBulb.js.map +0 -1
  37. package/dist/lib/vesyncFan.js.map +0 -1
  38. package/dist/lib/vesyncKitchen.d.ts +0 -0
  39. package/dist/lib/vesyncKitchen.js +0 -2
  40. package/dist/lib/vesyncKitchen.js.map +0 -1
  41. package/dist/lib/vesyncOutlet.js.map +0 -1
  42. package/dist/lib/vesyncSwitch.js.map +0 -1
  43. package/dist/src/lib/helpers.d.ts +0 -88
  44. package/dist/src/lib/helpers.js +0 -244
  45. package/dist/src/lib/vesync.d.ts +0 -89
  46. package/dist/src/lib/vesync.js +0 -430
  47. package/dist/src/lib/vesyncBaseDevice.d.ts +0 -43
  48. package/dist/src/lib/vesyncBaseDevice.js +0 -87
  49. package/dist/src/lib/vesyncBulb.d.ts +0 -79
  50. package/dist/src/lib/vesyncBulb.js +0 -198
  51. package/dist/src/lib/vesyncBulbImpl.d.ts +0 -38
  52. package/dist/src/lib/vesyncBulbImpl.js +0 -161
  53. package/dist/src/lib/vesyncFan.d.ts +0 -80
  54. package/dist/src/lib/vesyncFan.js +0 -406
  55. package/dist/src/lib/vesyncFanImpl.d.ts +0 -137
  56. package/dist/src/lib/vesyncFanImpl.js +0 -643
  57. package/dist/src/lib/vesyncOutlet.d.ts +0 -53
  58. package/dist/src/lib/vesyncOutlet.js +0 -98
  59. package/dist/src/lib/vesyncOutletImpl.d.ts +0 -70
  60. package/dist/src/lib/vesyncOutletImpl.js +0 -206
  61. package/dist/src/lib/vesyncSwitch.d.ts +0 -169
  62. package/dist/src/lib/vesyncSwitch.js +0 -414
  63. package/dist/src/lib/vesyncSwitchImpl.d.ts +0 -82
  64. package/dist/src/lib/vesyncSwitchImpl.js +0 -290
  65. package/dist/test/testFeatures.d.ts +0 -4
  66. package/dist/test/testFeatures.js +0 -394
  67. package/dist/test/testService.d.ts +0 -62
  68. package/dist/test/testService.js +0 -540
  69. package/dist/test/testSpecial.d.ts +0 -5
  70. package/dist/test/testSpecial.js +0 -227
@@ -6,17 +6,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.switchModules = exports.VeSyncDimmerSwitch = exports.VeSyncWallSwitch = void 0;
7
7
  const vesyncSwitch_1 = require("./vesyncSwitch");
8
8
  const helpers_1 = require("./helpers");
9
+ const logger_1 = require("./logger");
9
10
  /**
10
11
  * Basic Wall Switch Implementation (ESWL01, ESWL03)
11
12
  */
12
13
  class VeSyncWallSwitch extends vesyncSwitch_1.VeSyncSwitch {
13
14
  constructor(details, manager) {
14
15
  super(details, manager);
16
+ logger_1.logger.debug(`Initialized VeSyncWallSwitch device: ${this.deviceName}`);
15
17
  }
16
18
  /**
17
19
  * Get wall switch details
18
20
  */
19
21
  async getDetails() {
22
+ logger_1.logger.debug(`Getting details for device: ${this.deviceName}`);
20
23
  const body = {
21
24
  ...helpers_1.Helpers.reqBody(this.manager, 'devicedetail'),
22
25
  uuid: this.cid,
@@ -28,12 +31,17 @@ class VeSyncWallSwitch extends vesyncSwitch_1.VeSyncSwitch {
28
31
  this.deviceStatus = result.deviceStatus || this.deviceStatus;
29
32
  this.details.active_time = result.activeTime || 0;
30
33
  this.connectionStatus = result.connectionStatus || this.connectionStatus;
34
+ logger_1.logger.debug(`Successfully got details for device: ${this.deviceName}`);
35
+ }
36
+ else {
37
+ logger_1.logger.error(`Failed to get details for device: ${this.deviceName}`);
31
38
  }
32
39
  }
33
40
  /**
34
41
  * Get switch device configuration info
35
42
  */
36
43
  async getConfig() {
44
+ logger_1.logger.debug(`Getting configuration for device: ${this.deviceName}`);
37
45
  const body = {
38
46
  ...helpers_1.Helpers.reqBody(this.manager, 'devicedetail'),
39
47
  method: 'configurations',
@@ -42,12 +50,17 @@ class VeSyncWallSwitch extends vesyncSwitch_1.VeSyncSwitch {
42
50
  const [response] = await helpers_1.Helpers.callApi('/inwallswitch/v1/device/configurations', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
43
51
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
44
52
  this.config = helpers_1.Helpers.buildConfigDict(response);
53
+ logger_1.logger.debug(`Successfully got configuration for device: ${this.deviceName}`);
54
+ }
55
+ else {
56
+ logger_1.logger.error(`Failed to get configuration for device: ${this.deviceName}`);
45
57
  }
46
58
  }
47
59
  /**
48
60
  * Turn off wall switch
49
61
  */
50
62
  async turnOff() {
63
+ logger_1.logger.debug(`Turning off device: ${this.deviceName}`);
51
64
  const body = {
52
65
  ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
53
66
  status: 'off',
@@ -56,14 +69,17 @@ class VeSyncWallSwitch extends vesyncSwitch_1.VeSyncSwitch {
56
69
  const [response] = await helpers_1.Helpers.callApi('/inwallswitch/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
57
70
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
58
71
  this.deviceStatus = 'off';
72
+ logger_1.logger.debug(`Successfully turned off device: ${this.deviceName}`);
59
73
  return true;
60
74
  }
75
+ logger_1.logger.error(`Failed to turn off device: ${this.deviceName}`);
61
76
  return false;
62
77
  }
63
78
  /**
64
79
  * Turn on wall switch
65
80
  */
66
81
  async turnOn() {
82
+ logger_1.logger.debug(`Turning on device: ${this.deviceName}`);
67
83
  const body = {
68
84
  ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
69
85
  status: 'on',
@@ -72,8 +88,10 @@ class VeSyncWallSwitch extends vesyncSwitch_1.VeSyncSwitch {
72
88
  const [response] = await helpers_1.Helpers.callApi('/inwallswitch/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
73
89
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
74
90
  this.deviceStatus = 'on';
91
+ logger_1.logger.debug(`Successfully turned on device: ${this.deviceName}`);
75
92
  return true;
76
93
  }
94
+ logger_1.logger.error(`Failed to turn on device: ${this.deviceName}`);
77
95
  return false;
78
96
  }
79
97
  }
@@ -88,11 +106,13 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
88
106
  this._rgbValue = { red: 0, blue: 0, green: 0 };
89
107
  this._rgbStatus = 'unknown';
90
108
  this._indicatorLight = 'unknown';
109
+ logger_1.logger.debug(`Initialized VeSyncDimmerSwitch device: ${this.deviceName}`);
91
110
  }
92
111
  /**
93
112
  * Get dimmer switch details
94
113
  */
95
114
  async getDetails() {
115
+ logger_1.logger.debug(`Getting details for device: ${this.deviceName}`);
96
116
  const body = {
97
117
  ...helpers_1.Helpers.reqBody(this.manager, 'devicedetail'),
98
118
  uuid: this.cid,
@@ -114,12 +134,17 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
114
134
  blue: result.rgbValue.blue || 0
115
135
  };
116
136
  }
137
+ logger_1.logger.debug(`Successfully got details for device: ${this.deviceName}`);
138
+ }
139
+ else {
140
+ logger_1.logger.error(`Failed to get details for device: ${this.deviceName}`);
117
141
  }
118
142
  }
119
143
  /**
120
144
  * Get dimmer switch configuration info
121
145
  */
122
146
  async getConfig() {
147
+ logger_1.logger.debug(`Getting configuration for device: ${this.deviceName}`);
123
148
  const body = {
124
149
  ...helpers_1.Helpers.reqBody(this.manager, 'devicedetail'),
125
150
  method: 'configurations',
@@ -128,12 +153,17 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
128
153
  const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/configurations', 'post', body, helpers_1.Helpers.reqHeaders(this.manager));
129
154
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
130
155
  this.config = helpers_1.Helpers.buildConfigDict(response);
156
+ logger_1.logger.debug(`Successfully got configuration for device: ${this.deviceName}`);
157
+ }
158
+ else {
159
+ logger_1.logger.error(`Failed to get configuration for device: ${this.deviceName}`);
131
160
  }
132
161
  }
133
162
  /**
134
163
  * Turn off dimmer switch
135
164
  */
136
165
  async turnOff() {
166
+ logger_1.logger.debug(`Turning off device: ${this.deviceName}`);
137
167
  const body = {
138
168
  ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
139
169
  status: 'off',
@@ -142,14 +172,17 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
142
172
  const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
143
173
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
144
174
  this.deviceStatus = 'off';
175
+ logger_1.logger.debug(`Successfully turned off device: ${this.deviceName}`);
145
176
  return true;
146
177
  }
178
+ logger_1.logger.error(`Failed to turn off device: ${this.deviceName}`);
147
179
  return false;
148
180
  }
149
181
  /**
150
182
  * Turn on dimmer switch
151
183
  */
152
184
  async turnOn() {
185
+ logger_1.logger.debug(`Turning on device: ${this.deviceName}`);
153
186
  const body = {
154
187
  ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
155
188
  status: 'on',
@@ -158,8 +191,10 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
158
191
  const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicestatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
159
192
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
160
193
  this.deviceStatus = 'on';
194
+ logger_1.logger.debug(`Successfully turned on device: ${this.deviceName}`);
161
195
  return true;
162
196
  }
197
+ logger_1.logger.error(`Failed to turn on device: ${this.deviceName}`);
163
198
  return false;
164
199
  }
165
200
  /**
@@ -167,8 +202,10 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
167
202
  */
168
203
  async setBrightness(brightness) {
169
204
  if (!this.isDimmable()) {
205
+ logger_1.logger.error(`Device ${this.deviceName} does not support dimming`);
170
206
  return false;
171
207
  }
208
+ logger_1.logger.debug(`Setting brightness to ${brightness} for device: ${this.deviceName}`);
172
209
  const body = {
173
210
  ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
174
211
  brightness: brightness.toString(),
@@ -177,14 +214,17 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
177
214
  const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/updatebrightness', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
178
215
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
179
216
  this._brightness = brightness;
217
+ logger_1.logger.debug(`Successfully set brightness to ${brightness} for device: ${this.deviceName}`);
180
218
  return true;
181
219
  }
220
+ logger_1.logger.error(`Failed to set brightness to ${brightness} for device: ${this.deviceName}`);
182
221
  return false;
183
222
  }
184
223
  /**
185
224
  * Set RGB indicator color
186
225
  */
187
226
  async rgbColorSet(red, green, blue) {
227
+ logger_1.logger.debug(`Setting RGB color to (${red}, ${green}, ${blue}) for device: ${this.deviceName}`);
188
228
  const body = {
189
229
  ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
190
230
  rgbValue: {
@@ -199,72 +239,86 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
199
239
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
200
240
  this._rgbValue = { red, green, blue };
201
241
  this._rgbStatus = 'on';
242
+ logger_1.logger.debug(`Successfully set RGB color for device: ${this.deviceName}`);
202
243
  return true;
203
244
  }
245
+ logger_1.logger.error(`Failed to set RGB color for device: ${this.deviceName}`);
204
246
  return false;
205
247
  }
206
248
  /**
207
249
  * Turn on RGB indicator
208
250
  */
209
- async rgbColorOn() {
251
+ async rgbColorOff() {
252
+ logger_1.logger.debug(`Turning off RGB color for device: ${this.deviceName}`);
210
253
  const body = {
211
254
  ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
212
- status: 'on',
255
+ status: 'off',
213
256
  uuid: this.cid
214
257
  };
215
258
  const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicergbstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
216
259
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
217
- this._rgbStatus = 'on';
260
+ this._rgbStatus = 'off';
261
+ logger_1.logger.debug(`Successfully turned off RGB color for device: ${this.deviceName}`);
218
262
  return true;
219
263
  }
264
+ logger_1.logger.error(`Failed to turn off RGB color for device: ${this.deviceName}`);
220
265
  return false;
221
266
  }
222
267
  /**
223
- * Turn off RGB indicator
268
+ * Turn RGB Color On
224
269
  */
225
- async rgbColorOff() {
270
+ async rgbColorOn() {
271
+ logger_1.logger.debug(`Turning on RGB color for device: ${this.deviceName}`);
226
272
  const body = {
227
273
  ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
228
- status: 'off',
229
- uuid: this.cid
274
+ uuid: this.cid,
275
+ status: 'on'
230
276
  };
231
277
  const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/devicergbstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
232
278
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
233
- this._rgbStatus = 'off';
279
+ this._rgbStatus = 'on';
280
+ logger_1.logger.debug(`Successfully turned on RGB color for device: ${this.deviceName}`);
234
281
  return true;
235
282
  }
283
+ logger_1.logger.error(`Failed to turn on RGB color for device: ${this.deviceName}`);
236
284
  return false;
237
285
  }
238
286
  /**
239
- * Turn on indicator light
287
+ * Turn indicator light on
240
288
  */
241
289
  async indicatorLightOn() {
290
+ logger_1.logger.debug(`Turning on indicator light for device: ${this.deviceName}`);
242
291
  const body = {
243
292
  ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
244
- status: 'on',
245
- uuid: this.cid
293
+ uuid: this.cid,
294
+ status: 'on'
246
295
  };
247
296
  const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/indicatorlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
248
297
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
249
298
  this._indicatorLight = 'on';
299
+ logger_1.logger.debug(`Successfully turned on indicator light for device: ${this.deviceName}`);
250
300
  return true;
251
301
  }
302
+ logger_1.logger.error(`Failed to turn on indicator light for device: ${this.deviceName}`);
252
303
  return false;
253
304
  }
254
305
  /**
255
- * Turn off indicator light
306
+ * Turn indicator light off
256
307
  */
257
308
  async indicatorLightOff() {
309
+ logger_1.logger.debug(`Turning off indicator light for device: ${this.deviceName}`);
258
310
  const body = {
259
311
  ...helpers_1.Helpers.reqBody(this.manager, 'devicestatus'),
260
- status: 'off',
261
- uuid: this.cid
312
+ uuid: this.cid,
313
+ status: 'off'
262
314
  };
263
315
  const [response] = await helpers_1.Helpers.callApi('/dimmer/v1/device/indicatorlightstatus', 'put', body, helpers_1.Helpers.reqHeaders(this.manager));
264
316
  if ((response === null || response === void 0 ? void 0 : response.code) === 0) {
265
317
  this._indicatorLight = 'off';
318
+ logger_1.logger.debug(`Successfully turned off indicator light for device: ${this.deviceName}`);
266
319
  return true;
267
320
  }
321
+ logger_1.logger.error(`Failed to turn off indicator light for device: ${this.deviceName}`);
268
322
  return false;
269
323
  }
270
324
  // Getters
@@ -282,7 +336,7 @@ class VeSyncDimmerSwitch extends vesyncSwitch_1.VeSyncSwitch {
282
336
  }
283
337
  }
284
338
  exports.VeSyncDimmerSwitch = VeSyncDimmerSwitch;
285
- // Export the switch modules dictionary
339
+ // Export switch modules dictionary
286
340
  exports.switchModules = {
287
341
  'ESWL01': VeSyncWallSwitch,
288
342
  'ESWL03': VeSyncWallSwitch,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsvesync",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
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",
@@ -5,6 +5,7 @@
5
5
  import axios from 'axios';
6
6
  import crypto from 'crypto';
7
7
  import { VeSync } from './vesync';
8
+ import { logger } from './logger';
8
9
 
9
10
  // API configuration
10
11
  let _apiBaseUrl = 'https://smartapi.vesync.com';
@@ -216,7 +217,7 @@ export class Helpers {
216
217
  if (error.response) {
217
218
  return [error.response.data, error.response.status];
218
219
  }
219
- console.error('API call failed:', error.message);
220
+ logger.error('API call failed:', error.message);
220
221
  return [null, 0];
221
222
  }
222
223
  }
@@ -238,7 +239,7 @@ export class Helpers {
238
239
  const decoded = Buffer.from(value, 'hex');
239
240
  return decoded.readFloatBE(0).toString();
240
241
  } catch (error) {
241
- console.debug('Error decoding hex value:', error);
242
+ logger.debug('Error decoding hex value:', error);
242
243
  return '0';
243
244
  }
244
245
  }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Logger utility for TSVeSync
3
+ */
4
+
5
+ export enum LogLevel {
6
+ DEBUG = 0,
7
+ INFO = 1,
8
+ WARN = 2,
9
+ ERROR = 3,
10
+ NONE = 4
11
+ }
12
+
13
+ export class Logger {
14
+ private static instance: Logger;
15
+ private currentLevel: LogLevel = LogLevel.INFO;
16
+
17
+ private constructor() {}
18
+
19
+ static getInstance(): Logger {
20
+ if (!Logger.instance) {
21
+ Logger.instance = new Logger();
22
+ }
23
+ return Logger.instance;
24
+ }
25
+
26
+ setLevel(level: LogLevel): void {
27
+ this.currentLevel = level;
28
+ }
29
+
30
+ getLevel(): LogLevel {
31
+ return this.currentLevel;
32
+ }
33
+
34
+ debug(message: string, ...args: any[]): void {
35
+ if (this.currentLevel <= LogLevel.DEBUG) {
36
+ console.log(`[DEBUG] ${message}`, ...args);
37
+ }
38
+ }
39
+
40
+ info(message: string, ...args: any[]): void {
41
+ if (this.currentLevel <= LogLevel.INFO) {
42
+ console.log(`[INFO] ${message}`, ...args);
43
+ }
44
+ }
45
+
46
+ warn(message: string, ...args: any[]): void {
47
+ if (this.currentLevel <= LogLevel.WARN) {
48
+ console.warn(`[WARN] ${message}`, ...args);
49
+ }
50
+ }
51
+
52
+ error(message: string, ...args: any[]): void {
53
+ if (this.currentLevel <= LogLevel.ERROR) {
54
+ console.error(`[ERROR] ${message}`, ...args);
55
+ }
56
+ }
57
+ }
58
+
59
+ // Export singleton instance
60
+ export const logger = Logger.getInstance();
package/src/lib/vesync.ts CHANGED
@@ -9,8 +9,7 @@ import { outletModules } from './vesyncOutletImpl';
9
9
  import { switchModules } from './vesyncSwitchImpl';
10
10
  import { bulbModules } from './vesyncBulbImpl';
11
11
  import { VeSyncBulb } from './vesyncBulb';
12
- import { VeSyncOutlet } from './vesyncOutlet';
13
- import { VeSyncSwitch } from './vesyncSwitch';
12
+ import { logger } from './logger';
14
13
 
15
14
  const DEFAULT_ENERGY_UPDATE_INTERVAL = 21600;
16
15
 
@@ -46,7 +45,7 @@ function objectFactory(details: Record<string, any>, manager: VeSync): [string,
46
45
  if (deviceType in modules) {
47
46
  DeviceClass = modules[deviceType];
48
47
  category = cat;
49
- console.debug(`Found exact match for ${deviceType} in ${cat} modules`);
48
+ logger.debug(`Found exact match for ${deviceType} in ${cat} modules`);
50
49
  break;
51
50
  }
52
51
  }
@@ -83,7 +82,7 @@ function objectFactory(details: Record<string, any>, manager: VeSync): [string,
83
82
  for (const [prefix, cat] of Object.entries(prefixMap)) {
84
83
  if (deviceType.startsWith(prefix)) {
85
84
  category = cat;
86
- console.debug(`Device type ${deviceType} matched prefix ${prefix} -> category ${cat}`);
85
+ logger.debug(`Device type ${deviceType} matched prefix ${prefix} -> category ${cat}`);
87
86
 
88
87
  // Try to find a base class in this category's modules
89
88
  const modules = allModules[cat];
@@ -91,7 +90,7 @@ function objectFactory(details: Record<string, any>, manager: VeSync): [string,
91
90
  const baseType = moduleType.split('-')[0]; // e.g., ESL100 from ESL100-USA
92
91
  if (deviceType.startsWith(baseType)) {
93
92
  DeviceClass = ModuleClass;
94
- console.debug(`Found base type match: ${deviceType} -> ${baseType}`);
93
+ logger.debug(`Found base type match: ${deviceType} -> ${baseType}`);
95
94
  break;
96
95
  }
97
96
  }
@@ -107,11 +106,11 @@ function objectFactory(details: Record<string, any>, manager: VeSync): [string,
107
106
  const device = new DeviceClass(details, manager);
108
107
  return [category, device];
109
108
  } catch (error) {
110
- console.error(`Error creating device instance for ${deviceType}:`, error);
109
+ logger.error(`Error creating device instance for ${deviceType}:`, error);
111
110
  return [category, null];
112
111
  }
113
112
  } else {
114
- console.warn(`No device class found for type: ${deviceType}`);
113
+ logger.warn(`No device class found for type: ${deviceType}`);
115
114
  return [category, null];
116
115
  }
117
116
  }
@@ -187,13 +186,13 @@ export class VeSync {
187
186
  const regTest = /[^a-zA-Z/_]/;
188
187
  if (regTest.test(timeZone)) {
189
188
  this.timeZone = DEFAULT_TZ;
190
- console.debug('Invalid characters in time zone - ', timeZone);
189
+ logger.debug('Invalid characters in time zone - ', timeZone);
191
190
  } else {
192
191
  this.timeZone = timeZone;
193
192
  }
194
193
  } else {
195
194
  this.timeZone = DEFAULT_TZ;
196
- console.debug('Time zone is not a string');
195
+ logger.debug('Time zone is not a string');
197
196
  }
198
197
 
199
198
  if (debug) {
@@ -251,7 +250,7 @@ export class VeSync {
251
250
  return true;
252
251
  }
253
252
  }
254
- console.debug(`Device removed - ${device.deviceName} - ${device.deviceType}`);
253
+ logger.debug(`Device removed - ${device.deviceName} - ${device.deviceType}`);
255
254
  return false;
256
255
  }
257
256
  return true;
@@ -282,7 +281,7 @@ export class VeSync {
282
281
  this._devList[key] = deviceList.filter(device => VeSync.removeDevTest(device, devices));
283
282
  const after = this._devList[key].length;
284
283
  if (before !== after) {
285
- console.debug(`${before - after} ${key} removed`);
284
+ logger.debug(`${before - after} ${key} removed`);
286
285
  }
287
286
  }
288
287
  return true;
@@ -301,7 +300,7 @@ export class VeSync {
301
300
  dev.cid = dev.uuid;
302
301
  } else {
303
302
  devRem.push(index);
304
- console.warn(`Device with no ID - ${dev.deviceName || ''}`);
303
+ logger.warn(`Device with no ID - ${dev.deviceName || ''}`);
305
304
  }
306
305
  }
307
306
  });
@@ -326,13 +325,13 @@ export class VeSync {
326
325
  }
327
326
 
328
327
  if (!devices || devices.length === 0) {
329
- console.warn('No devices found in api return');
328
+ logger.warn('No devices found in api return');
330
329
  return false;
331
330
  }
332
331
 
333
332
  // Initialize new device list or remove old devices
334
333
  if (numDevices === 0) {
335
- console.debug('New device list initialized');
334
+ logger.debug('New device list initialized');
336
335
  } else {
337
336
  this.removeOldDevices(devices);
338
337
  }
@@ -347,7 +346,7 @@ export class VeSync {
347
346
  for (const dev of newDevices) {
348
347
  // Verify required device properties
349
348
  if (!requiredKeys.every(key => key in dev)) {
350
- console.debug(`Error adding device - missing required properties: ${dev.deviceName || 'Unknown'}`);
349
+ logger.debug(`Error adding device - missing required properties: ${dev.deviceName || 'Unknown'}`);
351
350
  continue;
352
351
  }
353
352
 
@@ -359,12 +358,12 @@ export class VeSync {
359
358
  // Add device to appropriate category if valid
360
359
  if (deviceObj && category in this._devList) {
361
360
  this._devList[category].push(deviceObj);
362
- console.debug(`Added ${devType} device to ${category} category`);
361
+ logger.debug(`Added ${devType} device to ${category} category`);
363
362
  } else if (category === 'unknown') {
364
- console.debug(`Unknown device type: ${devType}`);
363
+ logger.debug(`Unknown device type: ${devType}`);
365
364
  }
366
365
  } catch (err) {
367
- console.error(`Error creating device ${devType}:`, err);
366
+ logger.error(`Error creating device ${devType}:`, err);
368
367
  continue;
369
368
  }
370
369
  }
@@ -377,7 +376,7 @@ export class VeSync {
377
376
  */
378
377
  async getDevices(): Promise<boolean> {
379
378
  if (!this.enabled) {
380
- console.error('Not logged in to VeSync');
379
+ logger.error('Not logged in to VeSync');
381
380
  return false;
382
381
  }
383
382
 
@@ -400,42 +399,42 @@ export class VeSync {
400
399
  this.devices = Object.values(this._devList).flat();
401
400
 
402
401
  // Log device discovery results
403
- console.log('\n=== Device Discovery Summary ===');
404
- console.log(`Total devices processed: ${deviceList.length}`);
402
+ logger.debug('\n=== Device Discovery Summary ===');
403
+ logger.debug(`Total devices processed: ${deviceList.length}`);
405
404
 
406
405
  // Log device types found
407
406
  const deviceTypes = deviceList.map((d: Record<string, any>) => d.deviceType);
408
- console.log('\nDevice types found:', deviceTypes);
407
+ logger.debug('\nDevice types found:', deviceTypes);
409
408
 
410
409
  // Log devices by category with details
411
- console.log('\nDevices by Category:');
412
- console.log('---------------------');
410
+ logger.debug('\nDevices by Category:');
411
+ logger.debug('---------------------');
413
412
  for (const [category, devices] of Object.entries(this._devList)) {
414
413
  if (devices.length > 0) {
415
- console.log(`\n${category.toUpperCase()} (${devices.length} devices):`);
414
+ logger.debug(`\n${category.toUpperCase()} (${devices.length} devices):`);
416
415
  devices.forEach((d: VeSyncBaseDevice) => {
417
- console.log(` • ${d.deviceName}`);
418
- console.log(` Type: ${d.deviceType}`);
419
- console.log(` Status: ${d.deviceStatus}`);
420
- console.log(` ID: ${d.cid}`);
416
+ logger.debug(` • ${d.deviceName}`);
417
+ logger.debug(` Type: ${d.deviceType}`);
418
+ logger.debug(` Status: ${d.deviceStatus}`);
419
+ logger.debug(` ID: ${d.cid}`);
421
420
  });
422
421
  }
423
422
  }
424
423
 
425
424
  // Log summary statistics
426
- console.log('\nSummary Statistics:');
427
- console.log('-------------------');
428
- console.log(`Total Devices: ${this.devices?.length || 0}`);
425
+ logger.debug('\nSummary Statistics:');
426
+ logger.debug('-------------------');
427
+ logger.debug(`Total Devices: ${this.devices?.length || 0}`);
429
428
  for (const [category, devices] of Object.entries(this._devList)) {
430
- console.log(`${category}: ${devices.length} devices`);
429
+ logger.debug(`${category}: ${devices.length} devices`);
431
430
  }
432
431
 
433
- console.log('\n=== End of Device Discovery ===\n');
432
+ logger.debug('\n=== End of Device Discovery ===\n');
434
433
  } else {
435
- console.error('No devices found in response');
434
+ logger.error('No devices found in response');
436
435
  }
437
436
  } catch (error) {
438
- console.error('Unable to get device list:', error);
437
+ logger.error('Unable to get device list:', error);
439
438
  }
440
439
 
441
440
  this._inProcess = false;
@@ -447,7 +446,7 @@ export class VeSync {
447
446
  */
448
447
  async login(): Promise<boolean> {
449
448
  const body = Helpers.reqBody(this, 'login');
450
- console.log('Login request:', {
449
+ logger.debug('Login request:', {
451
450
  url: `${process.env.VESYNC_API_URL}/cloud/v1/user/login`,
452
451
  body
453
452
  });
@@ -459,7 +458,7 @@ export class VeSync {
459
458
  body
460
459
  );
461
460
 
462
- console.log('Login response:', { status, response });
461
+ logger.debug('Login response:', { status, response });
463
462
 
464
463
  if (response?.result?.token) {
465
464
  this.token = response.result.token;
@@ -469,10 +468,10 @@ export class VeSync {
469
468
  return true;
470
469
  }
471
470
 
472
- console.error('Unable to login with supplied credentials');
471
+ logger.error('Unable to login with supplied credentials');
473
472
  return false;
474
473
  } catch (error) {
475
- console.error('Login error:', error);
474
+ logger.error('Login error:', error);
476
475
  return false;
477
476
  }
478
477
  }
@@ -493,19 +492,19 @@ export class VeSync {
493
492
  async update(): Promise<void> {
494
493
  if (this.deviceTimeCheck()) {
495
494
  if (!this.enabled) {
496
- console.error('Not logged in to VeSync');
495
+ logger.error('Not logged in to VeSync');
497
496
  return;
498
497
  }
499
498
 
500
499
  await this.getDevices();
501
500
 
502
- console.debug('Start updating the device details one by one');
501
+ logger.debug('Start updating the device details one by one');
503
502
  for (const deviceList of Object.values(this._devList)) {
504
503
  for (const device of deviceList) {
505
504
  try {
506
505
  await device.getDetails();
507
506
  } catch (error) {
508
- console.error(`Error updating ${device.deviceName}:`, error);
507
+ logger.error(`Error updating ${device.deviceName}:`, error);
509
508
  }
510
509
  }
511
510
  }