From 22c91dfadc5ba2bcf0c0c291eaf8b21c4d285274 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 14 Sep 2025 13:51:10 -0500 Subject: [PATCH] cleanup --- esphome/components/md5/md5.cpp | 6 ++---- esphome/core/helpers.cpp | 1 - esphome/core/helpers.h | 3 +++ 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/esphome/components/md5/md5.cpp b/esphome/components/md5/md5.cpp index fb0d9f401f..21bd2e1cab 100644 --- a/esphome/components/md5/md5.cpp +++ b/esphome/components/md5/md5.cpp @@ -44,10 +44,8 @@ void MD5Digest::get_bytes(uint8_t *output) { memcpy(output, this->digest_, 16); void MD5Digest::get_hex(char *output) { for (size_t i = 0; i < 16; i++) { uint8_t byte = this->digest_[i]; - uint8_t high = byte >> 4; - uint8_t low = byte & 0x0F; - output[i * 2] = high < 10 ? '0' + high : 'a' + (high - 10); - output[i * 2 + 1] = low < 10 ? '0' + low : 'a' + (low - 10); + output[i * 2] = format_hex_char(byte >> 4); + output[i * 2 + 1] = format_hex_char(byte & 0x0F); } } diff --git a/esphome/core/helpers.cpp b/esphome/core/helpers.cpp index 43d6f1153c..7f977c5d40 100644 --- a/esphome/core/helpers.cpp +++ b/esphome/core/helpers.cpp @@ -258,7 +258,6 @@ std::string format_mac_address_pretty(const uint8_t *mac) { return str_snprintf("%02X:%02X:%02X:%02X:%02X:%02X", 17, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); } -static char format_hex_char(uint8_t v) { return v >= 10 ? 'a' + (v - 10) : '0' + v; } std::string format_hex(const uint8_t *data, size_t length) { std::string ret; ret.resize(length * 2); diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index a6741925d0..a2bac19b25 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -380,6 +380,9 @@ template::value, int> = 0> optional< return parse_hex(str.c_str(), str.length()); } +/// Convert a nibble (0-15) to lowercase hex char +inline char format_hex_char(uint8_t v) { return v >= 10 ? 'a' + (v - 10) : '0' + v; } + /// Format the six-byte array \p mac into a MAC address. std::string format_mac_address_pretty(const uint8_t mac[6]); /// Format the byte array \p data of length \p len in lowercased hex.