[tuya][rc522][remote_base] Migrate format_hex_pretty() to stack-based alternatives

This commit is contained in:
J. Nick Koston
2026-01-11 17:44:43 -10:00
parent 45c0796e40
commit 6e6d545963
3 changed files with 11 additions and 4 deletions

View File

@@ -492,7 +492,10 @@ bool RC522BinarySensor::process(std::vector<uint8_t> &data) {
this->found_ = result;
return result;
}
void RC522Trigger::process(std::vector<uint8_t> &data) { this->trigger(format_hex_pretty(data, '-', false)); }
void RC522Trigger::process(std::vector<uint8_t> &data) {
char uid_buf[format_hex_pretty_size(RC522_MAX_UID_SIZE)];
this->trigger(format_hex_pretty_to(uid_buf, data.data(), data.size(), '-'));
}
} // namespace rc522
} // namespace esphome

View File

@@ -29,6 +29,8 @@ class MideaData {
bool is_valid() const { return this->data_[OFFSET_CS] == this->calc_cs_(); }
void finalize() { this->data_[OFFSET_CS] = this->calc_cs_(); }
bool is_compliment(const MideaData &rhs) const;
/// @deprecated Allocates heap memory. Use to_str() instead. Removed in 2026.7.0.
ESPDEPRECATED("Allocates heap memory. Use to_str() instead. Removed in 2026.7.0.", "2026.1.0")
std::string to_string() const { return format_hex_pretty(this->data_.data(), this->data_.size()); }
/// Buffer size for to_str(): 6 bytes = "AA.BB.CC.DD.EE.FF\0"
static constexpr size_t TO_STR_BUFFER_SIZE = format_hex_pretty_size(6);

View File

@@ -14,9 +14,11 @@ void TuyaTextSensor::setup() {
this->publish_state(datapoint.value_string);
break;
case TuyaDatapointType::RAW: {
std::string data = format_hex_pretty(datapoint.value_raw);
ESP_LOGD(TAG, "MCU reported text sensor %u is: %s", datapoint.id, data.c_str());
this->publish_state(data);
// Text sensor state is limited to 255 bytes, use 256 byte buffer
char hex_buf[256];
const char *formatted = format_hex_pretty_to(hex_buf, sizeof(hex_buf), datapoint.value_raw);
ESP_LOGD(TAG, "MCU reported text sensor %u is: %s", datapoint.id, formatted);
this->publish_state(formatted);
break;
}
case TuyaDatapointType::ENUM: {