diff --git a/pyacaia_async/acaiascale.py b/pyacaia_async/acaiascale.py index c5f5843..8dc95a2 100644 --- a/pyacaia_async/acaiascale.py +++ b/pyacaia_async/acaiascale.py @@ -146,7 +146,7 @@ def timer(self) -> int: def _device_disconnected_callback(self, client: BleakClient) -> None: """Callback for device disconnected.""" - _LOGGER.debug("Device disconnected") + _LOGGER.warning("Scale with MAC %s disconnected", self.mac) self._connected = False self._last_disconnect_time = time.time() if self._notify_callback: @@ -165,7 +165,7 @@ async def _write_msg(self, char_id: str, payload: bytearray) -> None: if not self._connected: return assert self._client - _LOGGER.debug("Writing to device...") + _LOGGER.debug("Writing to scale %s", self.mac) await self._client.write_gatt_char(char_id, payload) self._timestamp_last_command = time.time() except (BleakDeviceNotFoundError, BleakError, TimeoutError) as ex: @@ -216,6 +216,15 @@ async def connect( raise AcaiaError("Client not initialized") if self.connected: return + if self._last_disconnect_time and self._last_disconnect_time > ( + time.time() - 15 + ): + _LOGGER.debug( + "Scale has recently been disconnected, waiting 15 seconds before reconnecting", + self.mac, + ) + return + try: try: await self._client.connect() diff --git a/setup.py b/setup.py index c5383cd..34d918e 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="pyacaia_async", - version="0.0.11b10", + version="0.0.11b11", description="An async implementation of PyAcaia", long_description=readme, long_description_content_type="text/markdown",