mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 08:28:12 +01:00
Template sensors always publish on update interval (#2224)
Co-authored-by: Chris Nussbaum <chris.nussbaum@protolabs.com>
This commit is contained in:
parent
1be106c0b5
commit
6180ee8065
2 changed files with 14 additions and 12 deletions
|
@ -7,12 +7,13 @@ namespace template_ {
|
|||
static const char *const TAG = "template.sensor";
|
||||
|
||||
void TemplateSensor::update() {
|
||||
if (!this->f_.has_value())
|
||||
return;
|
||||
|
||||
auto val = (*this->f_)();
|
||||
if (val.has_value()) {
|
||||
this->publish_state(*val);
|
||||
if (this->f_.has_value()) {
|
||||
auto val = (*this->f_)();
|
||||
if (val.has_value()) {
|
||||
this->publish_state(*val);
|
||||
}
|
||||
} else if (!isnan(this->get_raw_state())) {
|
||||
this->publish_state(this->get_raw_state());
|
||||
}
|
||||
}
|
||||
float TemplateSensor::get_setup_priority() const { return setup_priority::HARDWARE; }
|
||||
|
|
|
@ -7,12 +7,13 @@ namespace template_ {
|
|||
static const char *const TAG = "template.text_sensor";
|
||||
|
||||
void TemplateTextSensor::update() {
|
||||
if (!this->f_.has_value())
|
||||
return;
|
||||
|
||||
auto val = (*this->f_)();
|
||||
if (val.has_value()) {
|
||||
this->publish_state(*val);
|
||||
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);
|
||||
}
|
||||
}
|
||||
float TemplateTextSensor::get_setup_priority() const { return setup_priority::HARDWARE; }
|
||||
|
|
Loading…
Reference in a new issue