mirror of
https://github.com/esphome/esphome.git
synced 2024-12-01 11:14:13 +01:00
This commit is contained in:
parent
2b3052e9d7
commit
c4539e10fb
2 changed files with 12 additions and 14 deletions
|
@ -8,13 +8,12 @@ namespace template_ {
|
||||||
static const char *const TAG = "template.sensor";
|
static const char *const TAG = "template.sensor";
|
||||||
|
|
||||||
void TemplateSensor::update() {
|
void TemplateSensor::update() {
|
||||||
if (this->f_.has_value()) {
|
if (!this->f_.has_value())
|
||||||
auto val = (*this->f_)();
|
return;
|
||||||
if (val.has_value()) {
|
|
||||||
this->publish_state(*val);
|
auto val = (*this->f_)();
|
||||||
}
|
if (val.has_value()) {
|
||||||
} else if (!std::isnan(this->get_raw_state())) {
|
this->publish_state(*val);
|
||||||
this->publish_state(this->get_raw_state());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float TemplateSensor::get_setup_priority() const { return setup_priority::HARDWARE; }
|
float TemplateSensor::get_setup_priority() const { return setup_priority::HARDWARE; }
|
||||||
|
|
|
@ -7,13 +7,12 @@ namespace template_ {
|
||||||
static const char *const TAG = "template.text_sensor";
|
static const char *const TAG = "template.text_sensor";
|
||||||
|
|
||||||
void TemplateTextSensor::update() {
|
void TemplateTextSensor::update() {
|
||||||
if (this->f_.has_value()) {
|
if (!this->f_.has_value())
|
||||||
auto val = (*this->f_)();
|
return;
|
||||||
if (val.has_value()) {
|
|
||||||
this->publish_state(*val);
|
auto val = (*this->f_)();
|
||||||
}
|
if (val.has_value()) {
|
||||||
} else if (this->has_state()) {
|
this->publish_state(*val);
|
||||||
this->publish_state(this->state);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float TemplateTextSensor::get_setup_priority() const { return setup_priority::HARDWARE; }
|
float TemplateTextSensor::get_setup_priority() const { return setup_priority::HARDWARE; }
|
||||||
|
|
Loading…
Reference in a new issue