Skip to content

Commit 7979b3b

Browse files
authored
Add some more logging for disconnections (#205)
1 parent f7cc161 commit 7979b3b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

switchbot/devices/device.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,21 @@ async def _ensure_connected(self):
253253
self.rssi,
254254
)
255255
if self._client and self._client.is_connected:
256+
_LOGGER.debug(
257+
"%s: Already connected before obtaining lock, resetting timer; RSSI: %s",
258+
self.name,
259+
self.rssi,
260+
)
256261
self._reset_disconnect_timer()
257262
return
258263
async with self._connect_lock:
259264
# Check again while holding the lock
260265
if self._client and self._client.is_connected:
266+
_LOGGER.debug(
267+
"%s: Already connected after obtaining lock, resetting timer; RSSI: %s",
268+
self.name,
269+
self.rssi,
270+
)
261271
self._reset_disconnect_timer()
262272
return
263273
_LOGGER.debug("%s: Connecting; RSSI: %s", self.name, self.rssi)
@@ -287,6 +297,11 @@ async def _ensure_connected(self):
287297
await self._execute_disconnect_with_lock()
288298
raise
289299

300+
_LOGGER.debug(
301+
"%s: Starting notify and disconnect timer; RSSI: %s",
302+
self.name,
303+
self.rssi,
304+
)
290305
self._reset_disconnect_timer()
291306
await self._start_notify()
292307

@@ -319,6 +334,7 @@ def _disconnected(self, client: BleakClientWithServiceCache) -> None:
319334
self.name,
320335
self.rssi,
321336
)
337+
self._cancel_disconnect_timer()
322338

323339
def _disconnect_from_timer(self):
324340
"""Disconnect from device."""
@@ -390,7 +406,8 @@ async def _execute_disconnect_with_lock(self) -> None:
390406
ex,
391407
self.rssi,
392408
)
393-
_LOGGER.debug("%s: Disconnect completed", self.name)
409+
else:
410+
_LOGGER.debug("%s: Disconnect completed successfully", self.name)
394411

395412
async def _send_command_locked(self, key: str, command: bytes) -> bytes:
396413
"""Send command to device and read response."""

0 commit comments

Comments
 (0)