mirror of
https://github.com/esphome/esphome.git
synced 2025-03-28 21:48:16 +00:00
Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl> Co-authored-by: rob-deutsch <robzyb+altgithub@gmail.com> Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
#include "binary_fan.h"
|
|
#include "esphome/core/log.h"
|
|
|
|
namespace esphome {
|
|
namespace binary {
|
|
|
|
static const char *const TAG = "binary.fan";
|
|
|
|
void BinaryFan::setup() {
|
|
auto restore = this->restore_state_();
|
|
if (restore.has_value()) {
|
|
restore->apply(*this);
|
|
this->write_state_();
|
|
}
|
|
}
|
|
void BinaryFan::dump_config() { LOG_FAN("", "Binary Fan", this); }
|
|
fan::FanTraits BinaryFan::get_traits() {
|
|
return fan::FanTraits(this->oscillating_ != nullptr, false, this->direction_ != nullptr, 0);
|
|
}
|
|
void BinaryFan::control(const fan::FanCall &call) {
|
|
if (call.get_state().has_value())
|
|
this->state = *call.get_state();
|
|
if (call.get_oscillating().has_value())
|
|
this->oscillating = *call.get_oscillating();
|
|
if (call.get_direction().has_value())
|
|
this->direction = *call.get_direction();
|
|
|
|
this->write_state_();
|
|
this->publish_state();
|
|
}
|
|
void BinaryFan::write_state_() {
|
|
this->output_->set_state(this->state);
|
|
if (this->oscillating_ != nullptr)
|
|
this->oscillating_->set_state(this->oscillating);
|
|
if (this->direction_ != nullptr)
|
|
this->direction_->set_state(this->direction == fan::FanDirection::REVERSE);
|
|
}
|
|
|
|
} // namespace binary
|
|
} // namespace esphome
|