1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-05 04:42:21 +01:00

Revert "[binary_sensor] initial state refactor" (#8828)

This commit is contained in:
Clyde Stubbs
2025-05-18 13:30:08 +10:00
committed by GitHub
parent 18ac1b7c54
commit 44470f31f6
4 changed files with 42 additions and 38 deletions

View File

@@ -15,17 +15,21 @@ void BinarySensor::publish_state(bool state) {
if (!this->publish_dedup_.next(state))
return;
if (this->filter_list_ == nullptr) {
this->send_state_internal(state);
this->send_state_internal(state, false);
} else {
this->filter_list_->input(state);
this->filter_list_->input(state, false);
}
}
void BinarySensor::publish_initial_state(bool state) {
this->has_state_ = false;
this->publish_state(state);
if (!this->publish_dedup_.next(state))
return;
if (this->filter_list_ == nullptr) {
this->send_state_internal(state, true);
} else {
this->filter_list_->input(state, true);
}
}
void BinarySensor::send_state_internal(bool state) {
bool is_initial = !this->has_state_;
void BinarySensor::send_state_internal(bool state, bool is_initial) {
if (is_initial) {
ESP_LOGD(TAG, "'%s': Sending initial state %s", this->get_name().c_str(), ONOFF(state));
} else {