ESPHome 2025.5.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 {
5namespace template_ {
6
7static const char *const TAG = "template.fan";
8
10 auto restore = this->restore_state_();
11 if (restore.has_value()) {
12 restore->apply(*this);
13 }
14
15 // Construct traits
16 this->traits_ =
19}
20
21void TemplateFan::dump_config() { LOG_FAN("", "Template Fan", this); }
22
24 if (call.get_state().has_value())
25 this->state = *call.get_state();
26 if (call.get_speed().has_value() && (this->speed_count_ > 0))
27 this->speed = *call.get_speed();
28 if (call.get_oscillating().has_value() && this->has_oscillating_)
29 this->oscillating = *call.get_oscillating();
30 if (call.get_direction().has_value() && this->has_direction_)
31 this->direction = *call.get_direction();
32 this->preset_mode = call.get_preset_mode();
33
34 this->publish_state();
35}
36
37} // namespace template_
38} // namespace esphome
optional< bool > get_state() const
Definition fan.h:49
optional< bool > get_oscillating() const
Definition fan.h:58
optional< int > get_speed() const
Definition fan.h:65
optional< FanDirection > get_direction() const
Definition fan.h:74
std::string get_preset_mode() const
Definition fan.h:79
void publish_state()
Definition fan.cpp:117
FanDirection direction
The current direction of the fan.
Definition fan.h:116
std::string preset_mode
Definition fan.h:118
bool oscillating
The current oscillation state of the fan.
Definition fan.h:112
bool state
The current on/off state of the fan.
Definition fan.h:110
int speed
The current fan speed level.
Definition fan.h:114
optional< FanRestoreState > restore_state_()
Definition fan.cpp:140
void set_supported_preset_modes(const std::set< std::string > &preset_modes)
Set the preset modes supported by the fan.
Definition fan_traits.h:34
std::set< std::string > preset_modes_
void control(const fan::FanCall &call) override
const char *const TAG
Definition spi.cpp:8
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7