|
22 | 22 |
|
23 | 23 | from homekit.controller.tools import AbstractPairing, check_convert_value |
24 | 24 | from homekit.protocol.statuscodes import HapStatusCodes |
25 | | -from homekit.exceptions import UnknownError, UnpairedError, \ |
26 | | - AccessoryDisconnectedError, EncryptionError |
| 25 | +from homekit.exceptions import UnknownError, UnpairedError |
27 | 26 | from homekit.protocol.tlv import TLV |
28 | 27 | from homekit.model.characteristics import CharacteristicsTypes |
29 | 28 | from homekit.model.services import ServicesTypes |
@@ -79,12 +78,7 @@ async def list_accessories_and_characteristics(self): |
79 | 78 | """ |
80 | 79 | await self._ensure_connected() |
81 | 80 |
|
82 | | - try: |
83 | | - response = await self.connection.get_json('/accessories') |
84 | | - except (AccessoryDisconnectedError, EncryptionError): |
85 | | - self.session.close() |
86 | | - self.session = None |
87 | | - raise |
| 81 | + response = await self.connection.get_json('/accessories') |
88 | 82 |
|
89 | 83 | accessories = response['accessories'] |
90 | 84 |
|
@@ -123,15 +117,10 @@ async def list_pairings(self): |
123 | 117 | """ |
124 | 118 | await self._ensure_connected() |
125 | 119 |
|
126 | | - try: |
127 | | - data = await self.connection.post_tlv('/pairings', [ |
128 | | - (TLV.kTLVType_State, TLV.M1), |
129 | | - (TLV.kTLVType_Method, TLV.ListPairings) |
130 | | - ]) |
131 | | - except (AccessoryDisconnectedError, EncryptionError): |
132 | | - self.session.close() |
133 | | - self.session = None |
134 | | - raise |
| 120 | + data = await self.connection.post_tlv('/pairings', [ |
| 121 | + (TLV.kTLVType_State, TLV.M1), |
| 122 | + (TLV.kTLVType_Method, TLV.ListPairings) |
| 123 | + ]) |
135 | 124 |
|
136 | 125 | if not (data[0][0] == TLV.kTLVType_State and data[0][1] == TLV.M2): |
137 | 126 | raise UnknownError('unexpected data received: ' + str(data)) |
@@ -188,12 +177,7 @@ async def get_characteristics(self, characteristics, include_meta=False, include |
188 | 177 | if include_events: |
189 | 178 | url += '&ev=1' |
190 | 179 |
|
191 | | - try: |
192 | | - response = await self.connection.get_json(url) |
193 | | - except (AccessoryDisconnectedError, EncryptionError): |
194 | | - self.session.close() |
195 | | - self.session = None |
196 | | - raise |
| 180 | + response = await self.connection.get_json(url) |
197 | 181 |
|
198 | 182 | tmp = {} |
199 | 183 | for c in response['characteristics']: |
@@ -347,21 +331,10 @@ async def get_events(self, characteristics, callback_fun, max_events=-1, max_sec |
347 | 331 | event_count = 0 |
348 | 332 | s = time.time() |
349 | 333 | while (max_events == -1 or event_count < max_events) and (max_seconds == -1 or s + max_seconds >= time.time()): |
350 | | - try: |
351 | | - r = self.session.sec_http.handle_event_response() |
352 | | - body = r.read().decode() |
353 | | - except (AccessoryDisconnectedError, EncryptionError): |
354 | | - self.session.close() |
355 | | - self.session = None |
356 | | - raise |
| 334 | + r = self.session.sec_http.handle_event_response() |
| 335 | + body = r.read().decode() |
357 | 336 |
|
358 | 337 | if len(body) > 0: |
359 | | - try: |
360 | | - r = json.loads(body) |
361 | | - except JSONDecodeError: |
362 | | - self.session.close() |
363 | | - self.session = None |
364 | | - raise AccessoryDisconnectedError("Session closed after receiving malformed response from device") |
365 | 338 | tmp = [] |
366 | 339 | for c in r['characteristics']: |
367 | 340 | tmp.append((c['aid'], c['iid'], c['value'])) |
|
0 commit comments