mirror of
https://github.com/esphome/esphome.git
synced 2026-02-08 00:31:58 +00:00
[tuya][rc522][remote_base] Migrate format_hex_pretty() to stack-based alternatives (#13158)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "tuya_text_sensor.h"
|
||||
#include "esphome/core/entity_base.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
@@ -14,9 +15,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);
|
||||
char hex_buf[MAX_STATE_LEN + 1];
|
||||
const char *formatted =
|
||||
format_hex_pretty_to(hex_buf, sizeof(hex_buf), datapoint.value_raw.data(), datapoint.value_raw.size());
|
||||
ESP_LOGD(TAG, "MCU reported text sensor %u is: %s", datapoint.id, formatted);
|
||||
this->publish_state(formatted);
|
||||
break;
|
||||
}
|
||||
case TuyaDatapointType::ENUM: {
|
||||
|
||||
@@ -26,6 +26,9 @@ static constexpr size_t ESPHOME_DOMAIN_MAX_LEN = 20;
|
||||
// Maximum size for object_id buffer (friendly_name + null + margin)
|
||||
static constexpr size_t OBJECT_ID_MAX_LEN = 128;
|
||||
|
||||
// Maximum state length that Home Assistant will accept without raising ValueError
|
||||
static constexpr size_t MAX_STATE_LEN = 255;
|
||||
|
||||
enum EntityCategory : uint8_t {
|
||||
ENTITY_CATEGORY_NONE = 0,
|
||||
ENTITY_CATEGORY_CONFIG = 1,
|
||||
|
||||
Reference in New Issue
Block a user