1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-06 13:22:19 +01:00

Optimize memory usage by lazy-allocating raw callbacks in sensors (#9077)

This commit is contained in:
J. Nick Koston
2025-06-14 22:28:15 -05:00
committed by GitHub
parent 4305c44440
commit cb019fff9a
4 changed files with 23 additions and 8 deletions

View File

@@ -6,6 +6,7 @@
#include "esphome/components/text_sensor/filter.h"
#include <vector>
#include <memory>
namespace esphome {
namespace text_sensor {
@@ -33,6 +34,8 @@ namespace text_sensor {
class TextSensor : public EntityBase, public EntityBase_DeviceClass {
public:
TextSensor() = default;
/// Getter-syntax for .state.
std::string get_state() const;
/// Getter-syntax for .raw_state
@@ -70,8 +73,9 @@ class TextSensor : public EntityBase, public EntityBase_DeviceClass {
void internal_send_state_to_frontend(const std::string &state);
protected:
CallbackManager<void(std::string)> raw_callback_; ///< Storage for raw state callbacks.
CallbackManager<void(std::string)> callback_; ///< Storage for filtered state callbacks.
std::unique_ptr<CallbackManager<void(std::string)>>
raw_callback_; ///< Storage for raw state callbacks (lazy allocated).
CallbackManager<void(std::string)> callback_; ///< Storage for filtered state callbacks.
Filter *filter_list_{nullptr}; ///< Store all active filters.
};