Revert "Template sensors always publish on update interval (#2224)" (#4774)

This commit is contained in:
Chris Nussbaum 2023-05-03 17:16:00 -05:00 committed by GitHub
parent 2b3052e9d7
commit c4539e10fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 14 deletions

View File

@ -8,13 +8,12 @@ namespace template_ {
static const char *const TAG = "template.sensor";
void TemplateSensor::update() {
if (this->f_.has_value()) {
auto val = (*this->f_)();
if (val.has_value()) {
this->publish_state(*val);
}
} else if (!std::isnan(this->get_raw_state())) {
this->publish_state(this->get_raw_state());
if (!this->f_.has_value())
return;
auto val = (*this->f_)();
if (val.has_value()) {
this->publish_state(*val);
}
}
float TemplateSensor::get_setup_priority() const { return setup_priority::HARDWARE; }

View File

@ -7,13 +7,12 @@ namespace template_ {
static const char *const TAG = "template.text_sensor";
void TemplateTextSensor::update() {
if (this->f_.has_value()) {
auto val = (*this->f_)();
if (val.has_value()) {
this->publish_state(*val);
}
} else if (this->has_state()) {
this->publish_state(this->state);
if (!this->f_.has_value())
return;
auto val = (*this->f_)();
if (val.has_value()) {
this->publish_state(*val);
}
}
float TemplateTextSensor::get_setup_priority() const { return setup_priority::HARDWARE; }