Skip to content

Commit b06ee29

Browse files
committed
Raise more exceptions while get
1 parent 94c7175 commit b06ee29

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

tion_btle/s3.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from typing import Callable
55

66
if __package__ == "":
7-
from tion_btle.tion import tion, TionException
7+
from tion_btle.tion import tion, TionException, TionExceptionGet
88
else:
9-
from .tion import tion, TionException
9+
from .tion import tion, TionException, TionExceptionGet
1010

1111
import time
1212

@@ -108,8 +108,6 @@ async def process_mode(mode_code: int) -> str:
108108
finally:
109109
return result
110110

111-
result: dict = {}
112-
113111
try:
114112
await self._do_action(self._connect)
115113
await self._enable_notifications()
@@ -131,12 +129,13 @@ async def process_mode(mode_code: int) -> str:
131129
result = await decode_response(byte_response)
132130

133131
except exc.BleakError as e:
134-
_LOGGER.debug("Got %s while waiting for notification", str(e))
132+
_LOGGER.error("Got %s while waiting for notification", str(e))
135133
await self._disconnect()
134+
raise TionExceptionGet('get', str(e))
136135
except TionException as e:
137136
_LOGGER.error(str(e))
138-
result = {"code": 400, "error": "Got exception " + str(e)}
139137
await self._disconnect()
138+
raise e
140139

141140
if not keep_connection:
142141
await self._disconnect()
@@ -158,7 +157,11 @@ async def encode_status(status: str) -> int:
158157
except KeyError:
159158
pass
160159

161-
current_settings = await self.get(True)
160+
try:
161+
current_settings = await self.get(True)
162+
except TionExceptionGet:
163+
raise TionException('set', 'Could not get current settings!')
164+
162165
_LOGGER.debug("set: got '%s' settings" % current_settings)
163166
settings = {**current_settings, **request}
164167
new_settings = await self.create_command(self.command_SET_PARAMS)
@@ -170,7 +173,14 @@ async def encode_status(status: str) -> int:
170173
return new_settings
171174
try:
172175
await self._do_action(self._connect)
173-
await self._do_action(self._try_write, request=await encode_request(request))
176+
try:
177+
encoded_request = await encode_request(request)
178+
except (KeyError, TionException) as e:
179+
_LOGGER.warning("Could not create encoded settings command: %s" % str(e))
180+
return
181+
182+
await self._do_action(self._try_write, request=encoded_request)
183+
174184
except TionException as e:
175185
_LOGGER.error(str(e))
176186
finally:

tion_btle/tion.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ def __init__(self, expression, message):
3636
self.message = message
3737

3838

39+
class TionExceptionGet(TionException):
40+
def __init__(self, expression, message):
41+
super.__init__(expression, message)
42+
43+
3944
class tion:
4045
statuses = ['off', 'on']
4146
uuid_notify: str = ""

0 commit comments

Comments
 (0)