Skip to content

Commit dd18d67

Browse files
authored
Improve logging to show hex values for easier debugging (#123)
1 parent f5e5f77 commit dd18d67

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

switchbot/devices/bot.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ async def turn_on(self) -> bool:
4040
ret = self._check_command_result(result, 0, {1, 5})
4141
self._override_adv_data = {"isOn": True}
4242
_LOGGER.debug(
43-
"%s: Turn on result: %s -> %s", self.name, result, self._override_adv_data
43+
"%s: Turn on result: %s -> %s",
44+
self.name,
45+
result.hex() if result else None,
46+
self._override_adv_data,
4447
)
4548
self._fire_callbacks()
4649
return ret
@@ -51,7 +54,10 @@ async def turn_off(self) -> bool:
5154
ret = self._check_command_result(result, 0, {1, 5})
5255
self._override_adv_data = {"isOn": False}
5356
_LOGGER.debug(
54-
"%s: Turn off result: %s -> %s", self.name, result, self._override_adv_data
57+
"%s: Turn off result: %s -> %s",
58+
self.name,
59+
result.hex() if result else None,
60+
self._override_adv_data,
5561
)
5662
self._fire_callbacks()
5763
return ret

switchbot/devices/device.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,7 @@ async def _send_command(self, key: str, retry: int | None = None) -> bytes | Non
131131
if retry is None:
132132
retry = self._retry_count
133133
command = bytearray.fromhex(self._commandkey(key))
134-
_LOGGER.debug("%s: Sending command %s", self.name, command)
135-
if self._operation_lock.locked():
136-
_LOGGER.debug(
137-
"%s: Operation already in progress, waiting for it to complete; RSSI: %s",
138-
self.name,
139-
self.rssi,
140-
)
141-
134+
_LOGGER.debug("%s: Scheduling command %s", self.name, command.hex())
142135
max_attempts = retry + 1
143136
if self._operation_lock.locked():
144137
_LOGGER.debug(
@@ -359,7 +352,7 @@ async def _execute_command_locked(self, key: str, command: bytes) -> bytes:
359352

360353
async with async_timeout.timeout(5):
361354
notify_msg = await self._notify_future
362-
_LOGGER.debug("%s: Notification received: %s", self.name, notify_msg)
355+
_LOGGER.debug("%s: Notification received: %s", self.name, notify_msg.hex())
363356
self._notify_future = None
364357

365358
if notify_msg == b"\x07":

0 commit comments

Comments
 (0)