12static constexpr int SPEED_COUNT = SPEED_VEL3;
21static constexpr Preset PRESETS[] = {
22 {
"In", OPER_IN,
false},
23 {
"Out", OPER_OUT,
false},
24 {
"In-Out", OPER_IN_OUT,
false},
25 {
"Sensor", OPER_SENSOR_OR_AUTO,
false},
26 {
"Auto", OPER_SENSOR_OR_AUTO,
true},
28static constexpr const Preset &PRESET_IN_OUT = PRESETS[2];
29static constexpr const Preset &PRESET_SENSOR = PRESETS[3];
31static const Preset *find_preset(
const char *name) {
32 for (
const auto &
preset : PRESETS) {
39static const Preset *find_preset(uint8_t
mode,
bool auto_mode) {
40 for (
const auto &
preset : PRESETS) {
49 {PRESETS[0].name, PRESETS[1].name, PRESETS[2].name, PRESETS[3].name, PRESETS[4].name});
52 if (restore.has_value()) {
53 this->
speed = restore->speed;
54 if (restore->preset_mode < std::size(PRESETS))
70 if (!this->
parent_->is_ready()) {
71 ESP_LOGW(TAG,
"Not ready, cannot handle control call");
88 if (
speed.has_value()) {
91 if (preset->auto_mode) {
96 this->
speed = clamp(this->
speed, 1, SPEED_COUNT);
99 this->
parent_->write_oper(OPER_OFF, SPEED_OFF);
101 this->
parent_->write_oper(preset->mode,
preset->auto_mode ? FLAG_AUTO :
static_cast<uint8_t
>(this->speed));
108 uint8_t raw_speed = this->
parent_->get_speed();
111 if (mode == OPER_OFF) {
119 int new_speed = this->
speed;
120 uint8_t base_speed = raw_speed & SPEED_MASK;
121 if (base_speed >= SPEED_SLEEP && base_speed <= SPEED_VEL3)
122 new_speed = base_speed;
123 const Preset *
preset = find_preset(
mode, (raw_speed & FLAG_AUTO) != 0);
124 const char *new_preset =
preset !=
nullptr ?
preset->name :
nullptr;
126 if (this->
state && this->
speed == new_speed && same_preset)
130 this->
speed = new_speed;
131 if (new_preset !=
nullptr) {
BedjetMode mode
BedJet operating mode.
constexpr const char * c_str() const
void on_status() override
void control(const fan::FanCall &call) override
void dump_config() override
fan::FanTraits get_traits() override
const char * get_preset_mode() const
bool has_preset_mode() const
void set_supported_preset_modes(std::initializer_list< const char * > preset_modes)
Set the supported preset modes (stored on Fan, referenced by FanTraits via pointer).
void clear_preset_mode_()
Clear the preset mode.
bool set_preset_mode_(const char *preset_mode, size_t len)
Set the preset mode (finds and stores pointer from traits).
StringRef get_preset_mode() const
Get the current preset mode.
bool state
The current on/off state of the fan.
void wire_preset_modes_(FanTraits &traits)
Wire the Fan-owned preset modes pointer into the given traits object.
bool has_preset_mode() const
Check if a preset mode is currently active.
int speed
The current fan speed level.
optional< FanRestoreState > restore_state_()
void set_speed(bool speed)
Set whether this fan supports speed levels.
void set_supported_speed_count(int speed_count)
Set how many speed levels this fan has.
ESPHOME_LOG_TAG(TAG, "ecocomfort2.fan")