Debian Codegraph @

blebox_uniapi/error.py

raw symbols SCIP
1 class Error(RuntimeError):
2 """Generic blebox_uniapi error."""
3
4 pass
5
6
7 # Likely fixable/retriable network/busy errors
8 class ConnectionError(Error):
9 pass
10
11
12 class TimeoutError(ConnectionError):
13 pass
14
15
16 # Likely unfixable device errors (do not setup)
17 class ClientError(Error):
18 pass
19
20
21 class HttpError(ClientError):
22 pass
23
24
25 class UnauthorizedRequest(ClientError):
26 pass
27
28
29 # API errors
30 class BoxError(Error):
31 pass
32
33
34 class UnsupportedBoxResponse(BoxError):
35 pass
36
37
38 class UnsupportedBoxVersion(BoxError):
39 pass
40
41
42 class BadFieldExceedsMax(BoxError):
43 def __init__(self, dev_name: str, field: str, value: int, max_value: int):
44 self._dev_name = dev_name
45 self._field = field
46 self._value = value
47 self._max_value = max_value
48
49 def __str__(self) -> str:
50 return f"{self._dev_name}.{self._field} is {self._value} which exceeds max ({self._max_value})"
51
52
53 class BadFieldLessThanMin(BoxError):
54 def __init__(self, dev_name: str, field: str, value: int, min_value: int):
55 self._dev_name = dev_name
56 self._field = field
57 self._value = value
58 self._min_value = min_value
59
60 def __str__(self) -> str:
61 return f"{self._dev_name}.{self._field} is {self._value} which is less than minimum ({self._min_value})"
62
63
64 class BadFieldMissing(BoxError):
65 def __init__(self, dev_name: str, field: str):
66 self._dev_name = dev_name
67 self._field = field
68
69 def __str__(self) -> str:
70 return f"{self._dev_name}.{self._field} is missing"
71
72
73 class BadFieldNotANumber(BoxError):
74 def __init__(self, dev_name: str, field: str, value: int):
75 self._dev_name = dev_name
76 self._field = field
77 self._value = value
78
79 def __str__(self) -> str:
80 return (
81 f"{self._dev_name}.{self._field} is '{self._value}' which is not a number"
82 )
83
84
85 class BadFieldNotAString(BoxError):
86 def __init__(self, dev_name: str, field: str, value: int):
87 self._dev_name = dev_name
88 self._field = field
89 self._value = value
90
91 def __str__(self) -> str:
92 return f"{self._dev_name}.{self._field} is {self._value} which is not a string"
93
94
95 class BadFieldNotRGBW(BoxError):
96 def __init__(self, dev_name: str, field: str, value: int):
97 self._dev_name = dev_name
98 self._field = field
99 self._value = value
100
101 def __str__(self) -> str:
102 return f"{self._dev_name}.{self._field} is {self._value} which is not a rgbw string"
103
104
105 # misc errors
106
107
108 class MisconfiguredDevice(BoxError):
109 pass
110
111
112 # development bugs that shouldn't normally be possible
113
114
115 class DeviceStateNotAvailable(BoxError):
116 def __str__(self) -> str:
117 return "device state not available yet" # pragma: no cover