ESPHome 2025.12.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 auto restore = this->restore_state_();
10 if (restore.has_value()) {
11 restore->apply(*this);
12 }
13
14 // Construct traits
15 this->traits_ =
18}
19
20void TemplateFan::dump_config() { LOG_FAN("", "Template Fan", this); }
21
23 if (call.get_state().has_value())
24 this->state = *call.get_state();
25 if (call.get_speed().has_value() && (this->speed_count_ > 0))
26 this->speed = *call.get_speed();
27 if (call.get_oscillating().has_value() && this->has_oscillating_)
28 this->oscillating = *call.get_oscillating();
29 if (call.get_direction().has_value() && this->has_direction_)
30 this->direction = *call.get_direction();
32
33 this->publish_state();
34}
35
36} // namespace esphome::template_
optional< bool > get_state() const
Definition fan.h:49
const char * get_preset_mode() const
Definition fan.h:75
optional< bool > get_oscillating() const
Definition fan.h:58
optional< int > get_speed() const
Definition fan.h:63
optional< FanDirection > get_direction() const
Definition fan.h:72
void publish_state()
Definition fan.cpp:167
bool set_preset_mode_(const char *preset_mode)
Set the preset mode (finds and stores pointer from traits). Returns true if changed.
Definition fan.cpp:145
FanDirection direction
The current direction of the fan.
Definition fan.h:113
bool oscillating
The current oscillation state of the fan.
Definition fan.h:109
bool state
The current on/off state of the fan.
Definition fan.h:107
int speed
The current fan speed level.
Definition fan.h:111
optional< FanRestoreState > restore_state_()
Definition fan.cpp:194
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:8