esphome/esphome/components/demo/demo_fan.h
Oxan van Leeuwen 2a84db7f85
Refactor fan platform to resemble climate/cover platforms (#2848)
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>
2022-01-23 22:21:54 +13:00

67 lines
1.5 KiB
C++

#pragma once
#include "esphome/core/component.h"
#include "esphome/components/fan/fan.h"
namespace esphome {
namespace demo {
enum class DemoFanType {
TYPE_1,
TYPE_2,
TYPE_3,
TYPE_4,
};
class DemoFan : public fan::Fan, public Component {
public:
void set_type(DemoFanType type) { type_ = type; }
fan::FanTraits get_traits() override {
fan::FanTraits traits{};
// oscillation
// speed
// direction
// speed_count
switch (type_) {
case DemoFanType::TYPE_1:
break;
case DemoFanType::TYPE_2:
traits.set_oscillation(true);
break;
case DemoFanType::TYPE_3:
traits.set_direction(true);
traits.set_speed(true);
traits.set_supported_speed_count(5);
break;
case DemoFanType::TYPE_4:
traits.set_direction(true);
traits.set_speed(true);
traits.set_supported_speed_count(100);
traits.set_oscillation(true);
break;
}
return traits;
}
protected:
void control(const fan::FanCall &call) override {
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_speed().has_value())
this->speed = *call.get_speed();
if (call.get_direction().has_value())
this->direction = *call.get_direction();
this->publish_state();
}
DemoFanType type_;
};
} // namespace demo
} // namespace esphome