7 static const char *
const TAG =
"fan";
12 return LOG_STR(
"FORWARD");
14 return LOG_STR(
"REVERSE");
16 return LOG_STR(
"UNKNOWN");
27 ESP_LOGD(TAG,
" Oscillating: %s", YESNO(*this->
oscillating_));
30 ESP_LOGD(TAG,
" Speed: %d", *this->
speed_);
47 this->
speed_ = traits.supported_speed_count();
52 ESP_LOGW(TAG,
"'%s' - This fan does not support oscillation!", this->
parent_.
get_name().
c_str());
90 auto traits = this->get_traits();
92 ESP_LOGD(TAG,
"'%s' - Sending state:", this->name_.c_str());
93 ESP_LOGD(TAG,
" State: %s", ONOFF(this->
state));
94 if (traits.supports_speed()) {
95 ESP_LOGD(TAG,
" Speed: %d", this->
speed);
97 if (traits.supports_oscillation()) {
98 ESP_LOGD(TAG,
" Oscillating: %s", YESNO(this->
oscillating));
100 if (traits.supports_direction()) {
104 this->state_callback_.call();
113 bool restored = this->rtc_.load(&recovered);
115 switch (this->restore_mode_) {
119 recovered.state =
false;
122 recovered.state =
true;
125 recovered.state = restored ? recovered.state :
false;
128 recovered.state = restored ? recovered.state :
true;
131 recovered.state = restored ? !recovered.state :
false;
134 recovered.state = restored ? !recovered.state :
true;
146 this->rtc_.save(&
state);
150 if (this->get_traits().supports_speed()) {
151 ESP_LOGCONFIG(tag,
"%s Speed: YES", prefix);
152 ESP_LOGCONFIG(tag,
"%s Speed count: %d", prefix, this->get_traits().supported_speed_count());
154 if (this->get_traits().supports_oscillation()) {
155 ESP_LOGCONFIG(tag,
"%s Oscillation: YES", prefix);
157 if (this->get_traits().supports_direction()) {
158 ESP_LOGCONFIG(tag,
"%s Direction: YES", prefix);
bool state
The current on/off state of the fan.
bool oscillating
The current oscillation state of the fan.
optional< bool > oscillating_
void apply(Fan &fan)
Apply these settings to the fan.
FanDirection direction
The current direction of the fan.
virtual FanTraits get_traits()=0
optional< FanRestoreState > restore_state_()
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)
constexpr uint32_t RESTORE_STATE_VERSION
void add_on_state_callback(std::function< void()> &&callback)
Register a callback that will be called each time the state changes.
FanCall & set_speed(int speed)
virtual void control(const FanCall &call)=0
optional< bool > binary_state_
FanDirection
Simple enum to represent the direction of a fan.
ESPPreferences * global_preferences
int speed
The current fan speed level.
FanCall & set_oscillating(bool oscillating)
FanCall to_call(Fan &fan)
Convert this struct to a fan call that can be performed.
constexpr const char * c_str() const
FanCall & set_state(bool binary_state)
optional< FanDirection > direction_
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
Implementation of SPI Controller mode.
const LogString * fan_direction_to_string(FanDirection direction)
const StringRef & get_name() const
FanCall & set_direction(FanDirection direction)
void dump_traits_(const char *tag, const char *prefix)