-
Notifications
You must be signed in to change notification settings - Fork 199
Print bytes as hex in logs #1669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves the readability of binary data in debug logs by formatting bytes as hexadecimal strings with spaces instead of Python's default bytes representation.
- Replaces raw bytes representation with space-separated hex format in debug logs
- Updates four debug log statements in the ZCL frame deserializer
- Maintains the same logging level and information while improving readability
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
zigpy/zcl/__init__.py
Outdated
| self.debug("Unknown cluster command %s %r", hdr.command_id, data.hex(" ")) | ||
| return hdr, data | ||
|
|
||
| command = commands[hdr.command_id] | ||
| else: | ||
| # General command | ||
| if hdr.command_id not in foundation.GENERAL_COMMANDS: | ||
| self.debug("Unknown foundation command %s %s", hdr.command_id, data) | ||
| self.debug("Unknown foundation command %s %r", hdr.command_id, data.hex(" ")) |
Copilot
AI
Sep 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The format string uses %r for hex data but %s for command_id. Consider using %s for both since data.hex(" ") returns a string, making the %r unnecessary and potentially confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deliberately used %r to get the repr of the string, the difference between %s and %r is that r encloses the string in ' ('str'),
%r: Received ZCL frame: '18 35 0a 0b 05 29 b8 02'
%s: Received ZCL frame: 18 35 0a 0b 05 29 b8 02
zigpy/zcl/__init__.py
Outdated
| # General command | ||
| if hdr.command_id not in foundation.GENERAL_COMMANDS: | ||
| self.debug("Unknown foundation command %s %s", hdr.command_id, data) | ||
| self.debug("Unknown foundation command %s %r", hdr.command_id, data.hex(" ")) |
Copilot
AI
Sep 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The format string uses %r for hex data but %s for command_id. Consider using %s for both since data.hex(" ") returns a string, making the %r unnecessary and potentially confusing.
| self.debug("Unknown foundation command %s %r", hdr.command_id, data.hex(" ")) | |
| self.debug("Unknown foundation command %s %s", hdr.command_id, data.hex(" ")) |
|
|
||
| if data: | ||
| self.debug("Data remains after deserializing ZCL frame: %r", data) | ||
| self.debug("Data remains after deserializing ZCL frame: %r", data.hex(" ")) |
Copilot
AI
Sep 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The format string uses %r for hex data. Consider using %s instead since data.hex(" ") returns a string, making the %r unnecessary and potentially confusing.
| self.debug("Data remains after deserializing ZCL frame: %r", data.hex(" ")) | |
| self.debug("Data remains after deserializing ZCL frame: %s", data.hex(" ")) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #1669 +/- ##
=======================================
Coverage 99.31% 99.31%
=======================================
Files 63 63
Lines 12184 12184
=======================================
Hits 12100 12100
Misses 84 84 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
5fb2692 to
5678591
Compare
5678591 to
6ceb71b
Compare
Just a simple change to the format when logging bytes, example log output: