pyvesync 3.0.0b0__py3-none-any.whl

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 (49) hide show
  1. pyvesync/__init__.py +11 -0
  2. pyvesync/base_devices/__init__.py +35 -0
  3. pyvesync/base_devices/bulb_base.py +348 -0
  4. pyvesync/base_devices/fan_base.py +398 -0
  5. pyvesync/base_devices/fryer_base.py +69 -0
  6. pyvesync/base_devices/humidifier_base.py +460 -0
  7. pyvesync/base_devices/outlet_base.py +315 -0
  8. pyvesync/base_devices/purifier_base.py +518 -0
  9. pyvesync/base_devices/switch_base.py +270 -0
  10. pyvesync/base_devices/thermostat_base.py +277 -0
  11. pyvesync/base_devices/vesyncbasedevice.py +580 -0
  12. pyvesync/const.py +749 -0
  13. pyvesync/device_container.py +360 -0
  14. pyvesync/device_map.py +1090 -0
  15. pyvesync/devices/__init__.py +1 -0
  16. pyvesync/devices/vesyncbulb.py +1254 -0
  17. pyvesync/devices/vesyncfan.py +238 -0
  18. pyvesync/devices/vesynchumidifier.py +785 -0
  19. pyvesync/devices/vesynckitchen.py +664 -0
  20. pyvesync/devices/vesyncoutlet.py +962 -0
  21. pyvesync/devices/vesyncpurifier.py +951 -0
  22. pyvesync/devices/vesyncswitch.py +449 -0
  23. pyvesync/devices/vesyncthermostat.py +175 -0
  24. pyvesync/models/__init__.py +11 -0
  25. pyvesync/models/base_models.py +117 -0
  26. pyvesync/models/bulb_models.py +173 -0
  27. pyvesync/models/bypass_models.py +264 -0
  28. pyvesync/models/fan_models.py +46 -0
  29. pyvesync/models/fryer_models.py +28 -0
  30. pyvesync/models/home_models.py +158 -0
  31. pyvesync/models/humidifier_models.py +187 -0
  32. pyvesync/models/outlet_models.py +194 -0
  33. pyvesync/models/purifier_models.py +204 -0
  34. pyvesync/models/switch_models.py +89 -0
  35. pyvesync/models/thermostat_models.py +122 -0
  36. pyvesync/models/vesync_models.py +252 -0
  37. pyvesync/utils/__init__.py +1 -0
  38. pyvesync/utils/colors.py +248 -0
  39. pyvesync/utils/device_mixins.py +366 -0
  40. pyvesync/utils/enum_utils.py +25 -0
  41. pyvesync/utils/errors.py +859 -0
  42. pyvesync/utils/helpers.py +696 -0
  43. pyvesync/utils/logs.py +500 -0
  44. pyvesync/vesync.py +445 -0
  45. pyvesync-3.0.0b0.dist-info/METADATA +527 -0
  46. pyvesync-3.0.0b0.dist-info/RECORD +49 -0
  47. pyvesync-3.0.0b0.dist-info/WHEEL +5 -0
  48. pyvesync-3.0.0b0.dist-info/licenses/LICENSE +21 -0
  49. pyvesync-3.0.0b0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,859 @@
1
+ """Module holding VeSync API Error Codes and Response statuses.
2
+
3
+ Error codes are pulled from the VeSync app source code. If there are unknown errors
4
+ that are not found, please open an issue on GitHub.
5
+
6
+ Errors are integers divided by 1000 and then multiplied by 1000 to
7
+ get the base error code. It also tries to check if the absolute value matches
8
+ as well.
9
+
10
+ This is used by the `pyvesync.utils.helpers.Helpers.process_dev_response` method to
11
+ retrieve response code information and store in the `last_response` device instance.
12
+
13
+
14
+ The "check_device" key of the error dictionary is used to determine if the logger
15
+ should emit a warning to the user for critical device errors, such as a short
16
+ or voltage error.
17
+
18
+ The ResponseInfo class is used to define information regarding the error code or
19
+ indicate the request was successful. The ErrorTypes class is used to categorize the
20
+ error types. This is a WIP and subject to change. Should not be used for anything
21
+ other than the ErrorCodes error configuration.
22
+
23
+ Example:
24
+ Example of the error dictionary structure:
25
+ ```python
26
+ pyvesync.errors.ErrorCodes.get_error_info("-11201022")
27
+ ResponseInfo(
28
+ name="PASSWORD_ERROR",
29
+ error_type=ErrorTypes.AUTHENTICATION,
30
+ msg="Invalid password"
31
+ critical_error=False,
32
+ operational_error=False,
33
+ device_online=None
34
+ )
35
+
36
+ device.last_response
37
+ # Returns the ResponseInfo object.
38
+ ```
39
+ """
40
+
41
+ from dataclasses import dataclass
42
+ from types import MappingProxyType
43
+ from enum import StrEnum
44
+ from mashumaro.mixins.orjson import DataClassORJSONMixin
45
+
46
+
47
+ @dataclass
48
+ class ResponseInfo(DataClassORJSONMixin):
49
+ """Class holding response information and error code definitions and lookup methods.
50
+
51
+ Attributes:
52
+ name (str): Name of the error
53
+ error_type (ErrorTypes): Type of the error see `ErrorTypes`
54
+ message (str): Message for the error
55
+ critical_error (bool): A major error, such as a short or voltage error
56
+ operational_error (bool): Device connected but API error
57
+ device_online (bool | None): Device online status
58
+ response_data (dict | None): Response data from API - populated by the
59
+ process_dev_response method in the Helpers class and bypass mixin
60
+ methods.
61
+ """
62
+
63
+ name: str
64
+ error_type: str
65
+ message: str
66
+ critical_error: bool = False
67
+ operational_error: bool = False # Device connected but API error
68
+ device_online: bool | None = None # Defaults to connected
69
+ response_data: dict | None = None # Response data from API
70
+
71
+
72
+ class ErrorTypes(StrEnum):
73
+ """Error types for API return codes.
74
+
75
+ Attributes:
76
+ SUCCESS: Successful request
77
+ AUTHENTICATION: Authentication error
78
+ RATE_LIMIT: Rate limiting error
79
+ SERVER_ERROR: Server and connection error
80
+ REQUEST_ERROR: Error in Request parameters or method
81
+ DEVICE_ERROR: Device operational error, device
82
+ connected but cannot perform requested action
83
+ CONFIG_ERROR: Configuration error in user profie
84
+ DEVICE_OFFLINE: Device is offline, not connected
85
+ UNKNOWN_ERROR: Unknown error
86
+ BAD_RESPONSE: Bad response from API
87
+ """
88
+
89
+ SUCCESS = "success"
90
+ AUTHENTICATION = "auth_error"
91
+ RATE_LIMIT = "rate_limit_error"
92
+ SERVER_ERROR = "server_error"
93
+ REQUEST_ERROR = "request_error"
94
+ DEVICE_ERROR = "device_error"
95
+ CONFIG_ERROR = "config_error"
96
+ DEVICE_OFFLINE = "device_offline"
97
+ UNKNOWN_ERROR = "unknown_error"
98
+ TOKEN_ERROR = "token_error"
99
+ BAD_RESPONSE = "bad_response"
100
+
101
+
102
+ class ErrorCodes:
103
+ """Class holding error code definitions and lookup methods.
104
+
105
+ Taken from VeSync app source code. Values are `ErrorInfo` dataclasses.
106
+
107
+ Attributes:
108
+ errors (MappingProxyType[str, ErrorInfo]): Dictionary of error codes and
109
+ their meanings.
110
+
111
+ Example:
112
+ Error codes are taken from VeSync app source code, if there are unknown errors
113
+ that are not found, please open an issue on GitHub. The "critical_error" key of
114
+ the error dictionary is used to determine if the logger should emit a warning.
115
+ Used for device issues that are critical, such as a short or voltage error.
116
+
117
+ Each error dictionary is structured as follows:
118
+ ```
119
+ ErrorInfo(
120
+ name: str,
121
+ error_type: ErrorType,
122
+ message: str,
123
+ critical_error: bool,
124
+ operational_error: bool,
125
+ device_online: bool
126
+ )
127
+ ```
128
+
129
+ The `cls.critical_error(error_code)` method is used to determine if the error
130
+ is a critical device error that should emit a warning.
131
+
132
+ `cls.get_error_info(error_code)` method is used to return the error dictionary
133
+ for a given error code.
134
+ """
135
+
136
+ errors: MappingProxyType[str, ResponseInfo] = MappingProxyType(
137
+ {
138
+ "11": ResponseInfo(
139
+ "DEVICE_OFFLINE",
140
+ ErrorTypes.DEVICE_OFFLINE,
141
+ "Device offline",
142
+ device_online=False,
143
+ ),
144
+ "4041004": ResponseInfo(
145
+ "DEVICE_OFFLINE",
146
+ ErrorTypes.DEVICE_OFFLINE,
147
+ "Device offline",
148
+ device_online=False,
149
+ ),
150
+ "-11203000": ResponseInfo(
151
+ "ACCOUNT_EXIST", ErrorTypes.AUTHENTICATION, "Account already exists"
152
+ ),
153
+ "-11200000": ResponseInfo(
154
+ "ACCOUNT_FORMAT_ERROR", ErrorTypes.CONFIG_ERROR, "Account format error"
155
+ ),
156
+ "-11202000": ResponseInfo(
157
+ "ACCOUNT_NOT_EXIST", ErrorTypes.AUTHENTICATION, "Account does not exist"
158
+ ),
159
+ "-11300027": ResponseInfo(
160
+ "AIRPURGE_OFFLINE",
161
+ ErrorTypes.DEVICE_OFFLINE,
162
+ "Device offline",
163
+ device_online=False,
164
+ ),
165
+ "-16906000": ResponseInfo(
166
+ "REQUEST_TOO_FREQUENT",
167
+ ErrorTypes.RATE_LIMIT,
168
+ "Request too frequent",
169
+ operational_error=True,
170
+ ),
171
+ "-11902000": ResponseInfo(
172
+ "AUTHKEY_NOT_EXIST", ErrorTypes.CONFIG_ERROR, "Authkey does not exist"
173
+ ),
174
+ "-11900000": ResponseInfo(
175
+ "AUTHKEY_PID_NOT_MATCH", ErrorTypes.DEVICE_ERROR, "Authkey PID mismatch"
176
+ ),
177
+ "-11504000": ResponseInfo(
178
+ "AWAY_MAX", ErrorTypes.CONFIG_ERROR, "Away maximum reached"
179
+ ),
180
+ "11014000": ResponseInfo(
181
+ "BYPASS_AIRPURIFIER_E2",
182
+ ErrorTypes.DEVICE_ERROR,
183
+ "Air Purifier E2 error",
184
+ critical_error=True,
185
+ device_online=True,
186
+ ),
187
+ "11802000": ResponseInfo(
188
+ "BYPASS_AIRPURIFIER_MOTOR_ABNORMAL",
189
+ ErrorTypes.DEVICE_ERROR,
190
+ "Air Purifier motor error",
191
+ critical_error=True,
192
+ device_online=True,
193
+ ),
194
+ "11504000": ResponseInfo(
195
+ "BYPASS_AWAY_MAX", ErrorTypes.CONFIG_ERROR, "Away maximum reached"
196
+ ),
197
+ "11509000": ResponseInfo(
198
+ "BYPASS_AWAY_NOT_EXIST",
199
+ ErrorTypes.CONFIG_ERROR,
200
+ "Away does not exist",
201
+ ),
202
+ "11908000": ResponseInfo(
203
+ "BYPASS_COOK_TIMEOUT", ErrorTypes.DEVICE_ERROR, "Cook timeout error"
204
+ ),
205
+ "11909000": ResponseInfo(
206
+ "BYPASS_SMART_STOP",
207
+ ErrorTypes.DEVICE_ERROR,
208
+ "Smart stop error",
209
+ device_online=True,
210
+ ),
211
+ "11910000": ResponseInfo(
212
+ "BYPASS_LEFT_ZONE_COOKING",
213
+ ErrorTypes.DEVICE_ERROR,
214
+ "Left zone cooking error",
215
+ device_online=True
216
+ ),
217
+ "11911000": ResponseInfo(
218
+ "BYPASS_RIGHT_ZONE_COOKING",
219
+ ErrorTypes.DEVICE_ERROR,
220
+ "Right zone cooking error",
221
+ device_online=True
222
+ ),
223
+ "11912000": ResponseInfo(
224
+ "BYPASS_ALL_ZONE_COOKING",
225
+ ErrorTypes.DEVICE_ERROR,
226
+ "All zone cooking error",
227
+ device_online=True
228
+ ),
229
+ "11916000": ResponseInfo(
230
+ "BYPASS_NTC_RIGHT_TOP_SHORT",
231
+ ErrorTypes.DEVICE_ERROR,
232
+ "Right top short error",
233
+ critical_error=True,
234
+ device_online=True,
235
+ ),
236
+ "11917000": ResponseInfo(
237
+ "BYPASS_NTC_RIGHT_TOP_OPEN",
238
+ ErrorTypes.DEVICE_ERROR,
239
+ "Right top open error",
240
+ critical_error=True,
241
+ device_online=True,
242
+ ),
243
+ "11918000": ResponseInfo(
244
+ "BYPASS_NTC_BOTTOM_SHORT",
245
+ ErrorTypes.DEVICE_ERROR,
246
+ "Bottom short error",
247
+ critical_error=True,
248
+ device_online=True,
249
+ ),
250
+ "11919000": ResponseInfo(
251
+ "BYPASS_NTC_BOTTOM_OPEN",
252
+ ErrorTypes.DEVICE_ERROR,
253
+ "Bottom open error",
254
+ critical_error=True,
255
+ device_online=True,
256
+ ),
257
+ "11924000": ResponseInfo(
258
+ "BYPASS_RIGHT_TEMP_FAULT",
259
+ ErrorTypes.DEVICE_ERROR,
260
+ "Right temperature fault",
261
+ critical_error=True,
262
+ device_online=True,
263
+ ),
264
+ "11925000": ResponseInfo(
265
+ "BYPASS_ZONE_2_MOTOR_ABNORMAL",
266
+ ErrorTypes.DEVICE_ERROR,
267
+ "Zone 2 motor error",
268
+ critical_error=True,
269
+ device_online=True,
270
+ ),
271
+ "11021000": ResponseInfo(
272
+ "BYPASS_DEVICE_END",
273
+ ErrorTypes.DEVICE_ERROR,
274
+ "Device end error",
275
+ critical_error=True,
276
+ device_online=True,
277
+ ),
278
+ "11012000": ResponseInfo(
279
+ "BYPASS_DEVICE_RUNNING",
280
+ ErrorTypes.DEVICE_ERROR,
281
+ "Device running error",
282
+ critical_error=True,
283
+ device_online=True,
284
+ ),
285
+ "11020000": ResponseInfo(
286
+ "BYPASS_DEVICE_STOP",
287
+ ErrorTypes.DEVICE_ERROR,
288
+ "Device stop error",
289
+ device_online=True,
290
+ critical_error=True,
291
+ ),
292
+ "11901000": ResponseInfo(
293
+ "BYPASS_DOOR_OPEN",
294
+ ErrorTypes.DEVICE_ERROR,
295
+ "Door open error",
296
+ critical_error=True,
297
+ device_online=True,
298
+ ),
299
+ "11006000": ResponseInfo(
300
+ "BYPASS_E1_OPEN",
301
+ ErrorTypes.DEVICE_ERROR,
302
+ "Open circuit error",
303
+ critical_error=True,
304
+ device_online=True,
305
+ ),
306
+ "11007000": ResponseInfo(
307
+ "BYPASS_E2_SHORT",
308
+ ErrorTypes.DEVICE_ERROR,
309
+ "Short circuit error",
310
+ device_online=True,
311
+ critical_error=True,
312
+ ),
313
+ "11015000": ResponseInfo(
314
+ "BYPASS_E3_WARM",
315
+ ErrorTypes.DEVICE_ERROR,
316
+ "Warm error",
317
+ critical_error=True,
318
+ device_online=True,
319
+ ),
320
+ "11018000": ResponseInfo(
321
+ "BYPASS_SET_MIST_LEVEL",
322
+ ErrorTypes.DEVICE_ERROR,
323
+ "Cannot set mist level error",
324
+ device_online=True,
325
+ ),
326
+ "11019000": ResponseInfo(
327
+ "BYPASS_E6_VOLTAGE_LOW",
328
+ ErrorTypes.DEVICE_ERROR,
329
+ "Low voltage error",
330
+ critical_error=True,
331
+ device_online=True,
332
+ ),
333
+ "11013000": ResponseInfo(
334
+ "BYPASS_E7_VOLTAGE",
335
+ ErrorTypes.DEVICE_ERROR,
336
+ "Voltage error",
337
+ critical_error=True,
338
+ device_online=True,
339
+ ),
340
+ "11607000": ResponseInfo(
341
+ "BYPASS_HUMIDIFIER_ERROR_CONNECT_MSG",
342
+ ErrorTypes.DEVICE_ERROR,
343
+ "Humidifier connect message error",
344
+ ),
345
+ "11317000": ResponseInfo(
346
+ "BYPASS_DIMMER_NCT",
347
+ ErrorTypes.DEVICE_ERROR,
348
+ "Dimmer NCT error",
349
+ critical_error=True,
350
+ device_online=True,
351
+ ),
352
+ "11608000": ResponseInfo(
353
+ "BYPASS_HUMIDIFIER_ERROR_WATER_PUMP",
354
+ ErrorTypes.DEVICE_ERROR,
355
+ "Humidifier water pump error",
356
+ critical_error=True,
357
+ device_online=True,
358
+ ),
359
+ "11609000": ResponseInfo(
360
+ "BYPASS_HUMIDIFIER_ERROR_FAN_MOTOR",
361
+ ErrorTypes.DEVICE_ERROR,
362
+ "Humidifier fan motor error",
363
+ critical_error=True,
364
+ device_online=True,
365
+ ),
366
+ "11601000": ResponseInfo(
367
+ "BYPASS_HUMIDIFIER_ERROR_DRY_BURNING",
368
+ ErrorTypes.DEVICE_ERROR,
369
+ "Dry burning error",
370
+ critical_error=True,
371
+ device_online=True,
372
+ ),
373
+ "11602000": ResponseInfo(
374
+ "BYPASS_HUMIDIFIER_ERROR_PTC",
375
+ ErrorTypes.DEVICE_ERROR,
376
+ "Humidifier PTC error",
377
+ critical_error=True,
378
+ device_online=True,
379
+ ),
380
+ "11603000": ResponseInfo(
381
+ "BYPASS_HUMIDIFIER_ERROR_WARM_HIGH",
382
+ ErrorTypes.DEVICE_ERROR,
383
+ "Humidifier warm high error",
384
+ critical_error=True,
385
+ device_online=True,
386
+ ),
387
+ "11604000": ResponseInfo(
388
+ "BYPASS_HUMIDIFIER_ERROR_WATER",
389
+ ErrorTypes.DEVICE_ERROR,
390
+ "Humidifier water error",
391
+ critical_error=True,
392
+ device_online=True,
393
+ ),
394
+ "11907000": ResponseInfo(
395
+ "BYPASS_LOW_WATER",
396
+ ErrorTypes.DEVICE_ERROR,
397
+ "Low water error",
398
+ device_online=True,
399
+ critical_error=True,
400
+ ),
401
+ "11028000": ResponseInfo(
402
+ "BYPASS_MOTOR_OPEN",
403
+ ErrorTypes.DEVICE_ERROR,
404
+ "Motor open error",
405
+ device_online=True,
406
+ critical_error=True,
407
+ ),
408
+ "11017000": ResponseInfo(
409
+ "BYPASS_NOT_SUPPORTED", ErrorTypes.REQUEST_ERROR, "Not supported error"
410
+ ),
411
+ "11905000": ResponseInfo(
412
+ "BYPASS_NO_POT",
413
+ ErrorTypes.DEVICE_ERROR,
414
+ "No pot error",
415
+ device_online=True,
416
+ critical_error=True,
417
+ ),
418
+ "12001000": ResponseInfo(
419
+ "BYPASS_LACK_FOOD",
420
+ ErrorTypes.DEVICE_ERROR,
421
+ "Lack of food error",
422
+ device_online=True,
423
+ critical_error=True,
424
+ ),
425
+ "12002000": ResponseInfo(
426
+ "BYPASS_JAM_FOOD",
427
+ ErrorTypes.DEVICE_ERROR,
428
+ "Jam food error",
429
+ device_online=True,
430
+ critical_error=True,
431
+ ),
432
+ "12003000": ResponseInfo(
433
+ "BYPASS_BLOCK_FOOD",
434
+ ErrorTypes.DEVICE_ERROR,
435
+ "Block food error",
436
+ device_online=True,
437
+ critical_error=True,
438
+ ),
439
+ "12004000": ResponseInfo(
440
+ "BYPASS_PUMP_FAIL",
441
+ ErrorTypes.DEVICE_ERROR,
442
+ "Pump failure error",
443
+ device_online=True,
444
+ critical_error=True,
445
+ ),
446
+ "12005000": ResponseInfo(
447
+ "BYPASS_CALI_FAIL",
448
+ ErrorTypes.DEVICE_ERROR,
449
+ "Calibration failure error",
450
+ device_online=True,
451
+ critical_error=True,
452
+ ),
453
+ "11611000": ResponseInfo(
454
+ "BYPASS_FILTER_TRAY_ERROR",
455
+ ErrorTypes.DEVICE_ERROR,
456
+ "Filter tray error",
457
+ critical_error=True,
458
+ device_online=True,
459
+ ),
460
+ "11610000": ResponseInfo(
461
+ "BYPASS_VALUE_ERROR",
462
+ ErrorTypes.DEVICE_ERROR,
463
+ "Value error",
464
+ critical_error=True,
465
+ device_online=True,
466
+ ),
467
+ "11022000": ResponseInfo(
468
+ "BYPASS_CANNOT_SET_LEVEL",
469
+ ErrorTypes.DEVICE_ERROR,
470
+ "Cannot set level error",
471
+ critical_error=False,
472
+ device_online=True,
473
+ ),
474
+ "11023000": ResponseInfo(
475
+ "BYPASS_NTC_BOTTOM_OPEN",
476
+ ErrorTypes.DEVICE_ERROR,
477
+ "NTC bottom open error",
478
+ critical_error=True,
479
+ device_online=True,
480
+ ),
481
+ "11024000": ResponseInfo(
482
+ "BYPASS_NTC_BOTTOM_SHORT",
483
+ ErrorTypes.DEVICE_ERROR,
484
+ "NTC bottom short error",
485
+ critical_error=True,
486
+ device_online=True,
487
+ ),
488
+ "11026000": ResponseInfo(
489
+ "BYPASS_NTC_TOP_OPEN",
490
+ ErrorTypes.DEVICE_ERROR,
491
+ "NTC top open error",
492
+ critical_error=True,
493
+ device_online=True,
494
+ ),
495
+ "11025000": ResponseInfo(
496
+ "BYPASS_NTC_TOP_SHORT",
497
+ ErrorTypes.DEVICE_ERROR,
498
+ "NTC top short error",
499
+ critical_error=True,
500
+ device_online=True,
501
+ ),
502
+ "11027000": ResponseInfo(
503
+ "BYPASS_OPEN_HEAT_PIPE_OR_OPEN_FUSE",
504
+ ErrorTypes.DEVICE_ERROR,
505
+ "Open heat pipe or fuse error",
506
+ critical_error=True,
507
+ device_online=True,
508
+ ),
509
+ "11906000": ResponseInfo(
510
+ "BYPASS_OVER_HEATED",
511
+ ErrorTypes.DEVICE_ERROR,
512
+ "Overheated error",
513
+ critical_error=True,
514
+ device_online=True,
515
+ ),
516
+ "11000000": ResponseInfo(
517
+ "BYPASS_PARAMETER_INVALID",
518
+ ErrorTypes.REQUEST_ERROR,
519
+ "Invalid bypass parameter",
520
+ ),
521
+ "11510000": ResponseInfo(
522
+ "BYPASS_SCHEDULE_CONFLICT", ErrorTypes.CONFIG_ERROR, "Schedule conflict"
523
+ ),
524
+ "11502000": ResponseInfo(
525
+ "BYPASS_SCHEDULE_MAX",
526
+ ErrorTypes.CONFIG_ERROR,
527
+ "Maximum number of schedules reached",
528
+ ),
529
+ "11507000": ResponseInfo(
530
+ "BYPASS_SCHEDULE_NOT_EXIST",
531
+ ErrorTypes.CONFIG_ERROR,
532
+ "Schedule does not exist",
533
+ ),
534
+ "11503000": ResponseInfo(
535
+ "TIMER_MAX",
536
+ ErrorTypes.CONFIG_ERROR,
537
+ "Maximum number of timers reached",
538
+ ),
539
+ "11508000": ResponseInfo(
540
+ "TIMER_NOT_EXIST",
541
+ ErrorTypes.CONFIG_ERROR,
542
+ "Timer does not exist",
543
+ ),
544
+ "11605000": ResponseInfo(
545
+ "BYPASS_WATER_LOCK",
546
+ ErrorTypes.DEVICE_ERROR,
547
+ "Water lock error",
548
+ critical_error=True,
549
+ device_online=True,
550
+ ),
551
+ "11029000": ResponseInfo(
552
+ "BYPASS_WIFI_ERROR", ErrorTypes.DEVICE_ERROR, "WiFi error"
553
+ ),
554
+ "11902000": ResponseInfo(
555
+ "BY_PASS_ERROR_COOKING_158",
556
+ ErrorTypes.DEVICE_ERROR,
557
+ "Error setting cook mode, air fryer is already cooking",
558
+ device_online=True,
559
+ ),
560
+ "11035000": ResponseInfo(
561
+ "BYPASS_MOTOR_ABNORMAL_ERROR",
562
+ ErrorTypes.DEVICE_ERROR,
563
+ "Motor abnormal error",
564
+ critical_error=True,
565
+ device_online=True,
566
+ ),
567
+ "11903000": ResponseInfo(
568
+ "BY_PASS_ERROR_NOT_COOK_158",
569
+ ErrorTypes.DEVICE_ERROR,
570
+ "Error pausing, air fryer is not cooking",
571
+ device_online=True,
572
+ ),
573
+ "-12001000": ResponseInfo(
574
+ "CONFIGKEY_EXPIRED", ErrorTypes.CONFIG_ERROR, "Configkey expired"
575
+ ),
576
+ "-12000000": ResponseInfo(
577
+ "CONFIGKEY_NOT_EXIST",
578
+ ErrorTypes.CONFIG_ERROR,
579
+ "Configkey does not exist",
580
+ ),
581
+ "-11305000": ResponseInfo(
582
+ "CONFIG_MODULE_NOT_EXIST",
583
+ ErrorTypes.REQUEST_ERROR,
584
+ "Config module does not exist",
585
+ ),
586
+ "-11100000": ResponseInfo(
587
+ "DATABASE_FAILED", ErrorTypes.SERVER_ERROR, "Database error"
588
+ ),
589
+ "-11101000": ResponseInfo(
590
+ "DATABASE_FAILED_ERROR", ErrorTypes.SERVER_ERROR, "Database error"
591
+ ),
592
+ "-11306000": ResponseInfo(
593
+ "DEVICE_BOUND",
594
+ ErrorTypes.CONFIG_ERROR,
595
+ "Device already associated with another account",
596
+ ),
597
+ "-11301000": ResponseInfo(
598
+ "DEVICE_NOT_EXIST",
599
+ ErrorTypes.CONFIG_ERROR,
600
+ "Device does not exist",
601
+ device_online=False,
602
+ ),
603
+ "-11300000": ResponseInfo(
604
+ "DEVICE_OFFLINE",
605
+ ErrorTypes.DEVICE_OFFLINE,
606
+ "Device offline",
607
+ device_online=False,
608
+ ),
609
+ "-11302000": ResponseInfo(
610
+ "DEVICE_TIMEOUT",
611
+ ErrorTypes.DEVICE_ERROR,
612
+ "Device timeout",
613
+ device_online=False,
614
+ ),
615
+ "-11304000": ResponseInfo(
616
+ "DEVICE_TIMEZONE_DIFF",
617
+ ErrorTypes.CONFIG_ERROR,
618
+ "Device timezone difference",
619
+ ),
620
+ "-11303000": ResponseInfo(
621
+ "FIRMWARE_LATEST",
622
+ ErrorTypes.CONFIG_ERROR,
623
+ "No firmware update available",
624
+ ),
625
+ "-11102000": ResponseInfo(
626
+ "INTERNAL_ERROR", ErrorTypes.SERVER_ERROR, "Internal server error"
627
+ ),
628
+ "-11004000": ResponseInfo(
629
+ "METHOD_NOT_FOUND", ErrorTypes.REQUEST_ERROR, "Method not found"
630
+ ),
631
+ "-11107000": ResponseInfo(
632
+ "MONGODB_ERROR", ErrorTypes.SERVER_ERROR, "MongoDB error"
633
+ ),
634
+ "-11105000": ResponseInfo(
635
+ "MYSQL_ERROR", ErrorTypes.SERVER_ERROR, "MySQL error"
636
+ ),
637
+ "88888888": ResponseInfo(
638
+ "NETWORK_DISABLE", ErrorTypes.SERVER_ERROR, "Network disabled"
639
+ ),
640
+ "77777777": ResponseInfo(
641
+ "NETWORK_TIMEOUT", ErrorTypes.SERVER_ERROR, "Network timeout"
642
+ ),
643
+ "4031005": ResponseInfo(
644
+ "NO_PERMISSION_7A", ErrorTypes.DEVICE_ERROR, "No 7A Permissions"
645
+ ),
646
+ "-11201000": ResponseInfo(
647
+ "PASSWORD_ERROR", ErrorTypes.AUTHENTICATION, "Invalid password"
648
+ ),
649
+ "-11901000": ResponseInfo(
650
+ "PID_NOT_EXIST", ErrorTypes.DEVICE_ERROR, "PID does not exist"
651
+ ),
652
+ "-11106000": ResponseInfo(
653
+ "REDIS_ERROR", ErrorTypes.SERVER_ERROR, "Redis error"
654
+ ),
655
+ "-11003000": ResponseInfo(
656
+ "REQUEST_HIGH", ErrorTypes.RATE_LIMIT, "Rate limiting error"
657
+ ),
658
+ "-11005000": ResponseInfo(
659
+ "RESOURCE_NOT_EXIST",
660
+ ErrorTypes.REQUEST_ERROR,
661
+ "No device with ID found",
662
+ device_online=False,
663
+ ),
664
+ "-11108000": ResponseInfo("S3_ERROR", ErrorTypes.SERVER_ERROR, "S3 error"),
665
+ "-11502000": ResponseInfo(
666
+ "SCHEDULE_MAX",
667
+ ErrorTypes.CONFIG_ERROR,
668
+ "Maximum number of schedules reached",
669
+ ),
670
+ "-11103000": ResponseInfo(
671
+ "SERVER_BUSY", ErrorTypes.SERVER_ERROR, "Server busy"
672
+ ),
673
+ "-11104000": ResponseInfo(
674
+ "SERVER_TIMEOUT", ErrorTypes.SERVER_ERROR, "Server timeout"
675
+ ),
676
+ "-11501000": ResponseInfo(
677
+ "TIMER_CONFLICT", ErrorTypes.DEVICE_ERROR, "Timer conflict"
678
+ ),
679
+ "-11503000": ResponseInfo(
680
+ "TIMER_MAX", ErrorTypes.DEVICE_ERROR, "Maximum number of timers reached"
681
+ ),
682
+ "-11500000": ResponseInfo(
683
+ "TIMER_NOT_EXIST", ErrorTypes.DEVICE_ERROR, "Timer does not exist"
684
+ ),
685
+ "-11001000": ResponseInfo(
686
+ "TOKEN_EXPIRED", ErrorTypes.TOKEN_ERROR, "Invalid token"
687
+ ),
688
+ "-999999999": ResponseInfo(
689
+ "UNKNOWN", ErrorTypes.SERVER_ERROR, "Unknown error"
690
+ ),
691
+ "-11307000": ResponseInfo(
692
+ "UUID_NOT_EXIST",
693
+ ErrorTypes.DEVICE_ERROR,
694
+ "Device UUID not found",
695
+ device_online=False,
696
+ ),
697
+ "12102000": ResponseInfo(
698
+ "TEM_SENOR_ERROR",
699
+ ErrorTypes.DEVICE_ERROR,
700
+ "Temperature sensor error",
701
+ critical_error=True,
702
+ device_online=True,
703
+ ),
704
+ "12103000": ResponseInfo(
705
+ "HUM_SENOR_ERROR",
706
+ ErrorTypes.DEVICE_ERROR,
707
+ "Humidity sensor error",
708
+ critical_error=True,
709
+ device_online=True,
710
+ ),
711
+ "12101000": ResponseInfo(
712
+ "SENSOR_ERROR",
713
+ ErrorTypes.DEVICE_ERROR,
714
+ "Sensor error",
715
+ critical_error=True,
716
+ device_online=True,
717
+ ),
718
+ "11005000": ResponseInfo(
719
+ "BYPASS_DEVICE_IS_OFF",
720
+ ErrorTypes.DEVICE_ERROR, "Device is off"
721
+ "Device is off",
722
+ critical_error=True,
723
+ device_online=True,
724
+ ),
725
+
726
+
727
+ }
728
+ )
729
+
730
+ @classmethod
731
+ def get_error_info(cls, error_code: str | int | None) -> ResponseInfo:
732
+ """Return error dictionary for the given error code.
733
+
734
+ Args:
735
+ error_code (str | int): Error code to lookup.
736
+
737
+ Returns:
738
+ dict: Error dictionary for the given error code.
739
+
740
+ Example:
741
+ ```python
742
+ ErrorCodes.get_error_info("-11201022")
743
+ ErrorInfo(
744
+ "PASSWORD_ERROR", ErrorTypes.AUTHENTICATION, "Invalid password"
745
+ )
746
+ ```
747
+ """
748
+ try:
749
+ if error_code is None:
750
+ return ResponseInfo("UNKNOWN", ErrorTypes.UNKNOWN_ERROR, "Unknown error")
751
+ error_str = str(error_code)
752
+ error_int = int(error_code)
753
+ if error_str == "0":
754
+ return ResponseInfo("SUCCESS", ErrorTypes.SUCCESS, "Success")
755
+ if error_str in cls.errors:
756
+ return cls.errors[error_str]
757
+ error_code = int(error_int / 1000) * 1000
758
+ return cls.errors[str(error_code)]
759
+ except (ValueError, TypeError, KeyError):
760
+ return ResponseInfo("UNKNOWN", ErrorTypes.UNKNOWN_ERROR, "Unknown error")
761
+
762
+ @classmethod
763
+ def is_critical(cls, error_code: str | int) -> bool:
764
+ """Check if error code is a device error.
765
+
766
+ Args:
767
+ error_code (str | int): Error code to check.
768
+
769
+ Returns:
770
+ bool: True if error code is a device error, False otherwise.
771
+ """
772
+ error_info = cls.get_error_info(error_code)
773
+ return bool(error_info.critical_error)
774
+
775
+
776
+ class VeSyncError(Exception):
777
+ """Base exception for VeSync errors.
778
+
779
+ These are raised based on API response codes and exceptions
780
+ that may be raised by the different handlers.
781
+ """
782
+
783
+
784
+ class VesyncLoginError(VeSyncError):
785
+ """Exception raised for login authentication errors."""
786
+
787
+ def __init__(self, msg: str) -> None:
788
+ """Initialize the exception with a message."""
789
+ super().__init__(msg)
790
+
791
+
792
+ class VeSyncTokenError(VeSyncError):
793
+ """Exception raised for VeSync API authentication errors."""
794
+
795
+ def __init__(self) -> None:
796
+ """Initialize the exception with a message."""
797
+ super().__init__("Token expired or invalid - please re-authenticate")
798
+
799
+
800
+ class VeSyncServerError(VeSyncError):
801
+ """Exception raised for VeSync API server errors."""
802
+
803
+ def __init__(self, msg: str) -> None:
804
+ """Initialize the exception with a message."""
805
+ super().__init__(msg)
806
+
807
+
808
+ class VeSyncRateLimitError(VeSyncError):
809
+ """Exception raised for VeSync API rate limit errors."""
810
+
811
+ def __init__(self) -> None:
812
+ """Initialize the exception with a message."""
813
+ super().__init__("VeSync API rate limit exceeded")
814
+
815
+
816
+ class VeSyncAPIResponseError(VeSyncError):
817
+ """Exception raised for malformed VeSync API responses."""
818
+
819
+ def __init__(self, msg: None | str = None) -> None:
820
+ """Initialize the exception with a message."""
821
+ if msg is None:
822
+ msg = "Unexpected VeSync API response."
823
+ super().__init__(msg)
824
+
825
+
826
+ class VeSyncAPIStatusCodeError(VeSyncError):
827
+ """Exception raised for malformed VeSync API responses."""
828
+
829
+ def __init__(self, status_code: str | None = None) -> None:
830
+ """Initialize the exception with a message."""
831
+ message = "VeSync API returned an unknown status code"
832
+ if status_code is not None:
833
+ message = f"VeSync API returned status code {status_code}"
834
+ super().__init__(message)
835
+
836
+
837
+ def raise_api_errors(error_info: ResponseInfo) -> None:
838
+ """Raise the appropriate exception for API error code.
839
+
840
+ Called by `VeSync.async_call_api` method.
841
+
842
+ Raises:
843
+ VeSyncRateLimitError: Rate limit error
844
+ VesyncLoginError: Authentication error
845
+ VeSyncTokenError: Token error
846
+ VeSyncServerError: Server error
847
+ """
848
+ match error_info.error_type:
849
+ case ErrorTypes.RATE_LIMIT:
850
+ raise VeSyncRateLimitError
851
+ case ErrorTypes.AUTHENTICATION:
852
+ raise VesyncLoginError(error_info.message)
853
+ case ErrorTypes.TOKEN_ERROR:
854
+ raise VeSyncTokenError
855
+ case ErrorTypes.SERVER_ERROR:
856
+ raise VeSyncServerError(
857
+ f"{error_info.message} - "
858
+ "Please report error to github.com/webdjoe/pyvesync/issues"
859
+ )