From e22ded38036074dac72a2ce3a156bfd573179765 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 7 Apr 2026 19:47:43 -1000 Subject: [PATCH] more fixes --- .../esp32_ble_server/ble_server_automations.h | 8 ++++++-- esphome/core/automation.h | 10 +++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/esphome/components/esp32_ble_server/ble_server_automations.h b/esphome/components/esp32_ble_server/ble_server_automations.h index 0bbfdffd5b..0c39a40dbb 100644 --- a/esphome/components/esp32_ble_server/ble_server_automations.h +++ b/esphome/components/esp32_ble_server/ble_server_automations.h @@ -69,7 +69,8 @@ class BLECharacteristicSetValueActionManager { template class BLECharacteristicSetValueAction : public Action { public: BLECharacteristicSetValueAction(BLECharacteristic *characteristic) : parent_(characteristic) {} - TEMPLATABLE_VALUE(std::vector, buffer) + // TemplatableValue (not TemplatableFn) — also set from C++ with raw values (initializer_list, ByteBuffer) + template void set_buffer(V buffer) { this->buffer_ = buffer; } void set_buffer(std::initializer_list buffer) { this->buffer_ = std::vector(buffer); } void set_buffer(ByteBuffer buffer) { this->set_buffer(buffer.get_data()); } void play(const Ts &...x) override { @@ -90,6 +91,7 @@ template class BLECharacteristicSetValueAction : public Action, Ts...> buffer_{}; }; #endif // USE_ESP32_BLE_SERVER_SET_VALUE_ACTION @@ -115,13 +117,15 @@ template class BLECharacteristicNotifyAction : public Action class BLEDescriptorSetValueAction : public Action { public: BLEDescriptorSetValueAction(BLEDescriptor *descriptor) : parent_(descriptor) {} - TEMPLATABLE_VALUE(std::vector, buffer) + // TemplatableValue (not TemplatableFn) — also set from C++ with raw values (initializer_list, ByteBuffer) + template void set_buffer(V buffer) { this->buffer_ = buffer; } void set_buffer(std::initializer_list buffer) { this->buffer_ = std::vector(buffer); } void set_buffer(ByteBuffer buffer) { this->set_buffer(buffer.get_data()); } void play(const Ts &...x) override { this->parent_->set_value(this->buffer_.value(x...)); } protected: BLEDescriptor *parent_; + TemplatableValue, Ts...> buffer_{}; }; #endif // USE_ESP32_BLE_SERVER_DESCRIPTOR_SET_VALUE_ACTION diff --git a/esphome/core/automation.h b/esphome/core/automation.h index 7d5981c3b8..9f62f8fc4e 100644 --- a/esphome/core/automation.h +++ b/esphome/core/automation.h @@ -80,11 +80,11 @@ template class TemplatableFn { // Forward declaration for TemplatableValue (string specialization needs it) template class TemplatableValue; -/// Selects TemplatableFn (4 bytes) for non-string types, TemplatableValue (8 bytes) for std::string. -/// std::string needs TemplatableValue for const char*, __FlashStringHelper*, and PROGMEM support. -template -using TemplatableStorage = - std::conditional_t, TemplatableValue, TemplatableFn>; +/// TemplatableStorage uses TemplatableValue (8 bytes) for the TEMPLATABLE_VALUE macro. +/// Many components pass raw constants to macro-generated setters from codegen, so the +/// macro must accept both raw values and function pointers. Components that want the +/// 4-byte savings can use TemplatableFn directly instead of the macro. +template using TemplatableStorage = TemplatableValue; #define TEMPLATABLE_VALUE_(type, name) \ protected: \