mirror of
https://github.com/esphome/esphome.git
synced 2024-08-31 00:00:56 +02:00
Fix home assistant binary sensor initial state (#632)
* Fix home assistant binary sensor initial state * Fix send state log message * fix new_state local name * lint * Trigger Co-authored-by: Guillermo Ruffino <guillermo.ruffino@pampatech.net>
This commit is contained in:
parent
dc9f304d94
commit
7abe8875bd
|
@ -30,7 +30,11 @@ void BinarySensor::publish_initial_state(bool state) {
|
|||
}
|
||||
}
|
||||
void BinarySensor::send_state_internal(bool state, bool is_initial) {
|
||||
ESP_LOGD(TAG, "'%s': Sending state %s", this->get_name().c_str(), state ? "ON" : "OFF");
|
||||
if (is_initial) {
|
||||
ESP_LOGD(TAG, "'%s': Sending initial state %s", this->get_name().c_str(), ONOFF(state));
|
||||
} else {
|
||||
ESP_LOGD(TAG, "'%s': Sending state %s", this->get_name().c_str(), ONOFF(state));
|
||||
}
|
||||
this->has_state_ = true;
|
||||
this->state = state;
|
||||
if (!is_initial) {
|
||||
|
|
|
@ -16,14 +16,16 @@ void HomeassistantBinarySensor::setup() {
|
|||
ESP_LOGW(TAG, "Can't convert '%s' to binary state!", state.c_str());
|
||||
break;
|
||||
case PARSE_ON:
|
||||
ESP_LOGD(TAG, "'%s': Got state ON", this->entity_id_.c_str());
|
||||
this->publish_state(true);
|
||||
break;
|
||||
case PARSE_OFF:
|
||||
ESP_LOGD(TAG, "'%s': Got state OFF", this->entity_id_.c_str());
|
||||
this->publish_state(false);
|
||||
bool new_state = val == PARSE_ON;
|
||||
ESP_LOGD(TAG, "'%s': Got state %s", this->entity_id_.c_str(), ONOFF(new_state));
|
||||
if (this->initial_)
|
||||
this->publish_initial_state(new_state);
|
||||
else
|
||||
this->publish_state(new_state);
|
||||
break;
|
||||
}
|
||||
this->initial_ = false;
|
||||
});
|
||||
}
|
||||
void HomeassistantBinarySensor::dump_config() {
|
||||
|
|
|
@ -15,6 +15,7 @@ class HomeassistantBinarySensor : public binary_sensor::BinarySensor, public Com
|
|||
|
||||
protected:
|
||||
std::string entity_id_;
|
||||
bool initial_{true};
|
||||
};
|
||||
|
||||
} // namespace homeassistant
|
||||
|
|
Loading…
Reference in New Issue
Block a user