add template fan (#6310)

This commit is contained in:
Samuel Sieb
2024-03-10 15:42:02 -07:00
committed by GitHub
parent 0cdd0b295e
commit 6a46548a8b
10 changed files with 213 additions and 20 deletions
+3 -6
View File
@@ -14,14 +14,12 @@ from esphome.const import (
from .. import speed_ns
AUTO_LOAD = ["output"]
SpeedFan = speed_ns.class_("SpeedFan", cg.Component, fan.Fan)
CONFIG_SCHEMA = fan.FAN_SCHEMA.extend(
{
cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(SpeedFan),
cv.Optional(CONF_OUTPUT): cv.use_id(output.FloatOutput),
cv.Required(CONF_OUTPUT): cv.use_id(output.FloatOutput),
cv.Optional(CONF_OSCILLATION_OUTPUT): cv.use_id(output.BinaryOutput),
cv.Optional(CONF_DIRECTION_OUTPUT): cv.use_id(output.BinaryOutput),
cv.Optional(CONF_SPEED): cv.invalid(
@@ -38,9 +36,8 @@ async def to_code(config):
await cg.register_component(var, config)
await fan.register_fan(var, config)
if CONF_OUTPUT in config:
output_ = await cg.get_variable(config[CONF_OUTPUT])
cg.add(var.set_output(output_))
output_ = await cg.get_variable(config[CONF_OUTPUT])
cg.add(var.set_output(output_))
if CONF_OSCILLATION_OUTPUT in config:
oscillation_output = await cg.get_variable(config[CONF_OSCILLATION_OUTPUT])
+2 -4
View File
@@ -36,10 +36,8 @@ void SpeedFan::control(const fan::FanCall &call) {
}
void SpeedFan::write_state_() {
if (this->output_ != nullptr) {
float speed = this->state ? static_cast<float>(this->speed) / static_cast<float>(this->speed_count_) : 0.0f;
this->output_->set_level(speed);
}
float speed = this->state ? static_cast<float>(this->speed) / static_cast<float>(this->speed_count_) : 0.0f;
this->output_->set_level(speed);
if (this->oscillating_ != nullptr)
this->oscillating_->set_state(this->oscillating);
if (this->direction_ != nullptr)
+1 -1
View File
@@ -25,7 +25,7 @@ class SpeedFan : public Component, public fan::Fan {
void control(const fan::FanCall &call) override;
void write_state_();
output::FloatOutput *output_{nullptr};
output::FloatOutput *output_;
output::BinaryOutput *oscillating_{nullptr};
output::BinaryOutput *direction_{nullptr};
int speed_count_{};