Skip to content

Commit

Permalink
more exception handling, only write timer when is set from msg
Browse files Browse the repository at this point in the history
  • Loading branch information
zweckj committed Nov 28, 2023
1 parent f53c4ee commit 8bb0aa4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
12 changes: 11 additions & 1 deletion pyacaia_async/acaiascale.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ async def _write_msg(self, char_id: str, payload: bytearray) -> None:
except BleakError as ex:
self._connected = False
raise AcaiaError("Error writing to device") from ex
except TimeoutError as ex:
self._connected = False
raise AcaiaError("Timeout writing to device") from ex
except Exception as ex:
self._connected = False
raise AcaiaError("Unknown error writing to device") from ex
Expand Down Expand Up @@ -203,6 +206,12 @@ async def connect(
except BleakError as ex:
_LOGGER.exception("Error during connecting to device: %s", ex)
raise AcaiaError("Error during connecting to device") from ex
except TimeoutError as ex:
_LOGGER.exception("Timeout during connecting to device: %s", ex)
raise AcaiaError("Timeout during connecting to device") from ex
except Exception as ex:
_LOGGER.exception("Unknown error during connecting to device: %s", ex)
raise AcaiaError("Unknown error during connecting to device") from ex

self._connected = True
_LOGGER.debug("Connected to Acaia Scale")
Expand Down Expand Up @@ -338,7 +347,8 @@ async def on_bluetooth_data_received(

elif isinstance(msg, Message):
self._data[WEIGHT] = msg.value
self._timer_running = msg.timer_running
if msg.timer_running is not None:
self._timer_running = msg.timer_running
_LOGGER.debug("Got weight %s", str(msg.value))

if self._notify_callback is not None:
Expand Down
8 changes: 4 additions & 4 deletions pyacaia_async/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class Message:
def __init__(self, msg_type: int, payload: bytearray | list[int]) -> None:
self.msg_type = msg_type
self.payload = payload
self.value = None
self.button = None
self.time = None
self.timer_running = False
self.value: float | None = None
self.button: str | None = None
self.time: int | None = None
self.timer_running: bool | None = None

if self.msg_type == 5:
self.value = self._decode_weight(payload)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pyacaia_async",
version="0.0.11b6",
version="0.0.11b7",
description="An async implementation of PyAcaia",
long_description=readme,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 8bb0aa4

Please sign in to comment.