ESPHome  2022.12.8
binary_fan.cpp
Go to the documentation of this file.
1 #include "binary_fan.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace binary {
6 
7 static const char *const TAG = "binary.fan";
8 
10  auto restore = this->restore_state_();
11  if (restore.has_value()) {
12  restore->apply(*this);
13  this->write_state_();
14  }
15 }
16 void BinaryFan::dump_config() { LOG_FAN("", "Binary Fan", this); }
18  return fan::FanTraits(this->oscillating_ != nullptr, false, this->direction_ != nullptr, 0);
19 }
21  if (call.get_state().has_value())
22  this->state = *call.get_state();
23  if (call.get_oscillating().has_value())
24  this->oscillating = *call.get_oscillating();
25  if (call.get_direction().has_value())
26  this->direction = *call.get_direction();
27 
28  this->write_state_();
29  this->publish_state();
30 }
32  this->output_->set_state(this->state);
33  if (this->oscillating_ != nullptr)
34  this->oscillating_->set_state(this->oscillating);
35  if (this->direction_ != nullptr)
37 }
38 
39 } // namespace binary
40 } // namespace esphome
bool state
The current on/off state of the fan.
Definition: fan.h:107
bool oscillating
The current oscillation state of the fan.
Definition: fan.h:109
output::BinaryOutput * output_
Definition: binary_fan.h:25
FanDirection direction
The current direction of the fan.
Definition: fan.h:113
optional< FanDirection > get_direction() const
Definition: fan.h:74
void publish_state()
Definition: fan.cpp:92
void control(const fan::FanCall &call) override
Definition: binary_fan.cpp:20
virtual void set_state(bool state)
Enable or disable this binary output.
Definition: binary_output.h:34
optional< FanRestoreState > restore_state_()
Definition: fan.cpp:113
bool has_value() const
Definition: optional.h:87
output::BinaryOutput * oscillating_
Definition: binary_fan.h:26
output::BinaryOutput * direction_
Definition: binary_fan.h:27
fan::FanTraits get_traits() override
Definition: binary_fan.cpp:17
void dump_config() override
Definition: binary_fan.cpp:16
optional< bool > get_state() const
Definition: fan.h:49
optional< bool > get_oscillating() const
Definition: fan.h:58
void setup() override
Definition: binary_fan.cpp:9
Definition: a4988.cpp:4