ESPHome 2026.3.0
Loading...
Searching...
No Matches
template_fan.cpp
Go to the documentation of this file.
1#include "template_fan.h"
2#include "esphome/core/log.h"
3
4namespace esphome::template_ {
5
6static const char *const TAG = "template.fan";
7
9 // Construct traits before restore so preset modes can be looked up by index
10 this->traits_ =
13
14 auto restore = this->restore_state_();
15 if (restore.has_value()) {
16 restore->apply(*this);
17 }
18}
19
20void TemplateFan::dump_config() { LOG_FAN("", "Template Fan", this); }
21
23 auto call_state = call.get_state();
24 if (call_state.has_value())
25 this->state = *call_state;
26 auto call_speed = call.get_speed();
27 if (call_speed.has_value() && (this->speed_count_ > 0))
28 this->speed = *call_speed;
29 auto call_oscillating = call.get_oscillating();
30 if (call_oscillating.has_value() && this->has_oscillating_)
31 this->oscillating = *call_oscillating;
32 auto call_direction = call.get_direction();
33 if (call_direction.has_value() && this->has_direction_)
34 this->direction = *call_direction;
35 this->apply_preset_mode_(call);
36
37 this->publish_state();
38}
39
40} // namespace esphome::template_
void publish_state()
Definition fan.cpp:197
void apply_preset_mode_(const FanCall &call)
Apply preset mode from a FanCall (handles speed-clears-preset convention)
Definition fan.cpp:187
FanDirection direction
The current direction of the fan.
Definition fan.h:117
bool oscillating
The current oscillation state of the fan.
Definition fan.h:113
bool state
The current on/off state of the fan.
Definition fan.h:111
int speed
The current fan speed level.
Definition fan.h:115
optional< FanRestoreState > restore_state_()
Definition fan.cpp:225
void set_supported_preset_modes(std::initializer_list< const char * > preset_modes)
Set the preset modes supported by the fan (from initializer list).
Definition fan_traits.h:36
std::vector< const char * > preset_modes_
void control(const fan::FanCall &call) override
const char *const TAG
Definition spi.cpp:7