ESPHome 2026.1.0-dev
Loading...
Searching...
No Matches
template_water_heater.cpp
Go to the documentation of this file.
2#include "esphome/core/log.h"
3
4namespace esphome::template_ {
5
6static const char *const TAG = "template.water_heater";
7
9
13 auto restore = this->restore_state();
14
15 if (restore.has_value()) {
16 restore->perform();
17 }
18 }
19 if (!this->current_temperature_f_.has_value() && !this->mode_f_.has_value())
20 this->disable_loop();
21}
22
33
35 bool changed = false;
36
37 auto curr_temp = this->current_temperature_f_.call();
38 if (curr_temp.has_value()) {
39 if (*curr_temp != this->current_temperature_) {
40 this->current_temperature_ = *curr_temp;
41 changed = true;
42 }
43 }
44
45 auto new_mode = this->mode_f_.call();
46 if (new_mode.has_value()) {
47 if (*new_mode != this->mode_) {
48 this->mode_ = *new_mode;
49 changed = true;
50 }
51 }
52
53 if (changed) {
54 this->publish_state();
55 }
56}
57
59 LOG_WATER_HEATER("", "Template Water Heater", this);
60 ESP_LOGCONFIG(TAG, " Optimistic: %s", YESNO(this->optimistic_));
61}
62
64
68
70 if (call.get_mode().has_value()) {
71 if (this->optimistic_) {
72 this->mode_ = *call.get_mode();
73 }
74 }
75 if (!std::isnan(call.get_target_temperature())) {
76 if (this->optimistic_) {
78 }
79 }
80
81 this->set_trigger_->trigger();
82
83 if (this->optimistic_) {
84 this->publish_state();
85 }
86}
87
88} // namespace esphome::template_
void disable_loop()
Disable this component's loop.
constexpr bool empty() const
Check if the set is empty.
optional< T > call(Args &&...args)
Alias for operator() for compatibility.
bool has_value() const
Check if a lambda is set.
void trigger(const Ts &...x)
Inform the parent automation that the event has triggered.
Definition automation.h:204
TemplateWaterHeaterRestoreMode restore_mode_
void control(const water_heater::WaterHeaterCall &call) override
water_heater::WaterHeaterCallInternal make_call() override
water_heater::WaterHeaterTraits traits() override
TemplateLambda< water_heater::WaterHeaterMode > mode_f_
water_heater::WaterHeaterModeMask supported_modes_
const optional< WaterHeaterMode > & get_mode() const
optional< WaterHeaterCall > restore_state()
void set_supported_modes(WaterHeaterModeMask modes)
void set_supports_current_temperature(bool supports)
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.cpp:80
const char *const TAG
Definition spi.cpp:7