Skip to content

Commit a14aa97

Browse files
committed
log sent time
1 parent 6f6519c commit a14aa97

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

  • custom_components/ipixel_color/bluetooth

custom_components/ipixel_color/bluetooth/client.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,14 @@ async def send_command(self, command: bytes) -> bool:
120120
Raises:
121121
iPIXELConnectionError: If not connected
122122
"""
123+
import time
124+
123125
if not self._connected or not self._client:
124126
raise iPIXELConnectionError("Device not connected")
125127

128+
command_size = len(command)
129+
start_time = time.perf_counter()
130+
126131
try:
127132
# Set up temporary response capture
128133
response_data = []
@@ -170,9 +175,16 @@ def response_handler(sender: Any, data: bytearray) -> None:
170175
except BleakError as e:
171176
_LOGGER.warning("Could not restart original notification handler: %s", e)
172177

178+
elapsed_time = time.perf_counter() - start_time
179+
throughput = command_size / elapsed_time if elapsed_time > 0 else 0
180+
_LOGGER.debug(
181+
"BLE send: %d bytes in %.1f ms (%.1f KB/s)",
182+
command_size, elapsed_time * 1000, throughput / 1024
183+
)
173184
return True
174185
except BleakError as err:
175-
_LOGGER.error("Failed to send command: %s", err)
186+
elapsed_time = time.perf_counter() - start_time
187+
_LOGGER.error("Failed to send command (%d bytes) after %.1f ms: %s", command_size, elapsed_time * 1000, err)
176188
return False
177189

178190
@property

0 commit comments

Comments
 (0)