File: exceptions.py

package info (click to toggle)
python-aiohomekit 3.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,620 kB
  • sloc: python: 16,560; sh: 14; makefile: 8
file content (300 lines) | stat: -rw-r--r-- 7,745 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#
# Copyright 2019 aiohomekit team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


class HomeKitException(Exception):
    """Generic HomeKit exception.
    Attributes:
        stage: the stage that the exception occurred at
    """

    def __init__(self, stage: str) -> None:
        self.stage = stage

    pass


class BluetoothAdapterError(HomeKitException):
    pass


class MalformedPinError(HomeKitException):
    """
    Class to represent a malformed pin (not following the form DDD-DD-DDD)
    """

    pass


class ProtocolError(HomeKitException):
    """
    Class to represent an abstraction layer for all errors that are defined in the Error Codes table 4-5 page 60 of the
    specification.
    """

    pass


class UnknownError(ProtocolError):
    """
    Raised upon receipt of an unknown error (transmission of kTLVError_Unknown). The spec says that this can happen
    during "Add Pairing" (chapter 4.11 page 51) and "Remove Pairing" (chapter 4.12 page 53).
    """

    pass


class AuthenticationError(ProtocolError):
    """
    Raised upon receipt of an authentication error. This can happen on:
     * multiple occasions through out setup pairing (M4 / page 42, M5 page 45): if the pairing could not be established
     * during pair verify (M4 / page 50): if the session key could not be generated
     * during add pair (M2 / page 52): if the controller is not admin
     * during remove pairing (M2 / page 54): if the controller is not admin
     * during list pairing (M2 / page 56): if the controller is not admin
    """

    pass


class BackoffError(ProtocolError):
    """
    Raised upon receipt of a back off error. It seems unclear when this is raised, must be related to
    kTLVType_RetryDelay which is defined on page 61 of the spec.
    """

    pass


class MaxPeersError(ProtocolError):
    """
    Raised upon receipt of a max peers error. This can happen:
     * during executing a "pair setup" command
     * during an "add pairing" command
    """

    pass


class MaxTriesError(ProtocolError):
    """
    Raised upon receipt of a max tries error during a pair setup procedure. This happens if more than 100 unsuccessful
    authentication attempts were performed.
    """

    pass


class UnavailableError(ProtocolError):
    """Raised upon receipt of an unavailable error"""

    pass


class BusyError(ProtocolError):
    """
    Raised upon receipt of a busy error during a pair setup procedure. This happens only if a parallel pairing process
    is ongoing.
    """

    pass


class InvalidError(ProtocolError):
    """
    Raised upon receipt of an error not defined in the HomeKit spec. This should basically never be raised since it is
    the default error in the protocol's error handler.
    """

    pass


class IllegalData(ProtocolError):
    pass


class HttpException(Exception):
    """
    Used within the HTTP Parser.
    """

    def __init__(self, message):
        Exception.__init__(self, message)


class InvalidAuthTagError(ProtocolError):
    """
    Raised upon receipt of an invalid auth tag in Pair Verify Step 3.3 (Page 49).
    """

    pass


class IncorrectPairingIdError(ProtocolError):
    """
    Raised in Pair Verify Step 3.5 (Page 49) if the accessory responds with an unexpected pairing id.
    """

    pass


class InvalidSignatureError(ProtocolError):
    """
    Raised upon receipt of an invalid signature either from an accessory or from the controller.
    """

    pass


class ConfigurationError(HomeKitException):
    """
    Used if any configuration in the HomeKit AccessoryServer's context was wrong.
    """

    def __init__(self, message):
        Exception.__init__(self, message)


class FormatError(HomeKitException):
    """
    Used if any format conversion fails or is impossible.
    """

    def __init__(self, message):
        Exception.__init__(self, message)


class CharacteristicPermissionError(HomeKitException):
    """
    Used if the characteristic's permissions do not allow the action. This includes reads on write only characteristics
    and writes on read only characteristics.
    """

    def __init__(self, message):
        Exception.__init__(self, message)


class AccessoryNotFoundError(HomeKitException):
    """
    Used if a HomeKit Accessory's IP and port could not be received via Bonjour / Zeroconf. This might be a temporary
    issue due to the way Bonjour / Zeroconf works.
    """

    def __init__(self, message):
        Exception.__init__(self, message)


class EncryptionError(HomeKitException):
    """
    Used if during a transmission some errors occurred.
    """

    def __init__(self, message):
        Exception.__init__(self, message)


class AccessoryDisconnectedError(HomeKitException):
    """
    There was a connectivity issue whilst communicating with a device.
    """

    def __init__(self, message: str) -> None:
        Exception.__init__(self, message)


class ConnectionError(AccessoryDisconnectedError):
    """
    Used if a HomeKit disconnects part way through an operation or series of operations.

    It may be possible to reconnect and retry the request.
    """


class HttpErrorResponse(AccessoryDisconnectedError):
    def __init__(self, message: str, response):
        super().__init__(message)
        self.response = response


class TimeoutError(ConnectionError):
    """Connection timeout."""


class ConfigLoadingError(HomeKitException):
    """
    Used on problems loading some config. This includes but may not be limited to:
     * problems with file permissions (file not readable)
     * the file could not be found
     * the file does not contain parseable JSON
    """

    def __init__(self, message):
        Exception.__init__(self, message)


class ConfigSavingError(HomeKitException):
    """
    Used on problems saving some config. This includes but may not be limited to:
     * problems with file permissions (file not writable)
     * the file could not be found (occurs if the path does not exist)
    """

    def __init__(self, message):
        Exception.__init__(self, message)


class UnpairedError(HomeKitException):
    """
    This should be raised if a paired accessory is expected but the accessory is still unpaired.
    """

    def __init__(self, message):
        Exception.__init__(self, message)


class AlreadyPairedError(HomeKitException):
    """
    This should be raised if an unpaired accessory is expected but the accessory is already paired.
    """

    def __init__(self, message):
        Exception.__init__(self, message)


class RequestRejected(HomeKitException):
    """
    Raised when a request fails with a HAP error code
    """

    def __init__(self, message, error_code):
        self.error_code = error_code
        self.message = message
        Exception.__init__(message)


class TransportNotSupportedError(HomeKitException):
    def __init__(self, transport):
        Exception.__init__(
            self,
            "Transport {t} not supported. See setup.py for required dependencies.".format(
                t=transport
            ),
        )


class DisconnectedControllerError(HomeKitException):
    def __init__(self):
        Exception.__init__(self, "Controller has passed away")