mirror of
https://github.com/esphome/esphome.git
synced 2025-10-26 20:53:50 +00:00
Reduce memory required for sensor entities (#9201)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -80,9 +80,9 @@ class Sensor : public EntityBase, public EntityBase_DeviceClass, public EntityBa
|
||||
* state changes to the database when they are published, even if the state is the
|
||||
* same as before.
|
||||
*/
|
||||
bool get_force_update() const { return force_update_; }
|
||||
bool get_force_update() const { return sensor_flags_.force_update; }
|
||||
/// Set force update mode.
|
||||
void set_force_update(bool force_update) { force_update_ = force_update; }
|
||||
void set_force_update(bool force_update) { sensor_flags_.force_update = force_update; }
|
||||
|
||||
/// Add a filter to the filter chain. Will be appended to the back.
|
||||
void add_filter(Filter *filter);
|
||||
@@ -155,9 +155,17 @@ class Sensor : public EntityBase, public EntityBase_DeviceClass, public EntityBa
|
||||
|
||||
Filter *filter_list_{nullptr}; ///< Store all active filters.
|
||||
|
||||
optional<int8_t> accuracy_decimals_; ///< Accuracy in decimals override
|
||||
optional<StateClass> state_class_{STATE_CLASS_NONE}; ///< State class override
|
||||
bool force_update_{false}; ///< Force update mode
|
||||
// Group small members together to avoid padding
|
||||
int8_t accuracy_decimals_{-1}; ///< Accuracy in decimals (-1 = not set)
|
||||
StateClass state_class_{STATE_CLASS_NONE}; ///< State class (STATE_CLASS_NONE = not set)
|
||||
|
||||
// Bit-packed flags for sensor-specific settings
|
||||
struct SensorFlags {
|
||||
uint8_t has_accuracy_override : 1;
|
||||
uint8_t has_state_class_override : 1;
|
||||
uint8_t force_update : 1;
|
||||
uint8_t reserved : 5; // Reserved for future use
|
||||
} sensor_flags_{};
|
||||
};
|
||||
|
||||
} // namespace sensor
|
||||
|
||||
Reference in New Issue
Block a user