mirror of
https://github.com/esphome/esphome.git
synced 2025-10-17 17:23:45 +01:00
Reduce entity memory usage by eliminating field shadowing and bit-packing (#9076)
This commit is contained in:
@@ -11,25 +11,25 @@ static const char *const TAG = "datetime.date_entity";
|
||||
|
||||
void DateEntity::publish_state() {
|
||||
if (this->year_ == 0 || this->month_ == 0 || this->day_ == 0) {
|
||||
this->has_state_ = false;
|
||||
this->set_has_state(false);
|
||||
return;
|
||||
}
|
||||
if (this->year_ < 1970 || this->year_ > 3000) {
|
||||
this->has_state_ = false;
|
||||
this->set_has_state(false);
|
||||
ESP_LOGE(TAG, "Year must be between 1970 and 3000");
|
||||
return;
|
||||
}
|
||||
if (this->month_ < 1 || this->month_ > 12) {
|
||||
this->has_state_ = false;
|
||||
this->set_has_state(false);
|
||||
ESP_LOGE(TAG, "Month must be between 1 and 12");
|
||||
return;
|
||||
}
|
||||
if (this->day_ > days_in_month(this->month_, this->year_)) {
|
||||
this->has_state_ = false;
|
||||
this->set_has_state(false);
|
||||
ESP_LOGE(TAG, "Day must be between 1 and %d for month %d", days_in_month(this->month_, this->year_), this->month_);
|
||||
return;
|
||||
}
|
||||
this->has_state_ = true;
|
||||
this->set_has_state(true);
|
||||
ESP_LOGD(TAG, "'%s': Sending date %d-%d-%d", this->get_name().c_str(), this->year_, this->month_, this->day_);
|
||||
this->state_callback_.call();
|
||||
}
|
||||
|
@@ -13,9 +13,6 @@ namespace datetime {
|
||||
|
||||
class DateTimeBase : public EntityBase {
|
||||
public:
|
||||
/// Return whether this Datetime has gotten a full state yet.
|
||||
bool has_state() const { return this->has_state_; }
|
||||
|
||||
virtual ESPTime state_as_esptime() const = 0;
|
||||
|
||||
void add_on_state_callback(std::function<void()> &&callback) { this->state_callback_.add(std::move(callback)); }
|
||||
@@ -31,8 +28,6 @@ class DateTimeBase : public EntityBase {
|
||||
#ifdef USE_TIME
|
||||
time::RealTimeClock *rtc_;
|
||||
#endif
|
||||
|
||||
bool has_state_{false};
|
||||
};
|
||||
|
||||
#ifdef USE_TIME
|
||||
|
@@ -11,40 +11,40 @@ static const char *const TAG = "datetime.datetime_entity";
|
||||
|
||||
void DateTimeEntity::publish_state() {
|
||||
if (this->year_ == 0 || this->month_ == 0 || this->day_ == 0) {
|
||||
this->has_state_ = false;
|
||||
this->set_has_state(false);
|
||||
return;
|
||||
}
|
||||
if (this->year_ < 1970 || this->year_ > 3000) {
|
||||
this->has_state_ = false;
|
||||
this->set_has_state(false);
|
||||
ESP_LOGE(TAG, "Year must be between 1970 and 3000");
|
||||
return;
|
||||
}
|
||||
if (this->month_ < 1 || this->month_ > 12) {
|
||||
this->has_state_ = false;
|
||||
this->set_has_state(false);
|
||||
ESP_LOGE(TAG, "Month must be between 1 and 12");
|
||||
return;
|
||||
}
|
||||
if (this->day_ > days_in_month(this->month_, this->year_)) {
|
||||
this->has_state_ = false;
|
||||
this->set_has_state(false);
|
||||
ESP_LOGE(TAG, "Day must be between 1 and %d for month %d", days_in_month(this->month_, this->year_), this->month_);
|
||||
return;
|
||||
}
|
||||
if (this->hour_ > 23) {
|
||||
this->has_state_ = false;
|
||||
this->set_has_state(false);
|
||||
ESP_LOGE(TAG, "Hour must be between 0 and 23");
|
||||
return;
|
||||
}
|
||||
if (this->minute_ > 59) {
|
||||
this->has_state_ = false;
|
||||
this->set_has_state(false);
|
||||
ESP_LOGE(TAG, "Minute must be between 0 and 59");
|
||||
return;
|
||||
}
|
||||
if (this->second_ > 59) {
|
||||
this->has_state_ = false;
|
||||
this->set_has_state(false);
|
||||
ESP_LOGE(TAG, "Second must be between 0 and 59");
|
||||
return;
|
||||
}
|
||||
this->has_state_ = true;
|
||||
this->set_has_state(true);
|
||||
ESP_LOGD(TAG, "'%s': Sending datetime %04u-%02u-%02u %02d:%02d:%02d", this->get_name().c_str(), this->year_,
|
||||
this->month_, this->day_, this->hour_, this->minute_, this->second_);
|
||||
this->state_callback_.call();
|
||||
|
@@ -11,21 +11,21 @@ static const char *const TAG = "datetime.time_entity";
|
||||
|
||||
void TimeEntity::publish_state() {
|
||||
if (this->hour_ > 23) {
|
||||
this->has_state_ = false;
|
||||
this->set_has_state(false);
|
||||
ESP_LOGE(TAG, "Hour must be between 0 and 23");
|
||||
return;
|
||||
}
|
||||
if (this->minute_ > 59) {
|
||||
this->has_state_ = false;
|
||||
this->set_has_state(false);
|
||||
ESP_LOGE(TAG, "Minute must be between 0 and 59");
|
||||
return;
|
||||
}
|
||||
if (this->second_ > 59) {
|
||||
this->has_state_ = false;
|
||||
this->set_has_state(false);
|
||||
ESP_LOGE(TAG, "Second must be between 0 and 59");
|
||||
return;
|
||||
}
|
||||
this->has_state_ = true;
|
||||
this->set_has_state(true);
|
||||
ESP_LOGD(TAG, "'%s': Sending time %02d:%02d:%02d", this->get_name().c_str(), this->hour_, this->minute_,
|
||||
this->second_);
|
||||
this->state_callback_.call();
|
||||
|
Reference in New Issue
Block a user