ESPHome  2024.11.0
demo_fan.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 namespace esphome {
7 namespace demo {
8 
9 enum class DemoFanType {
10  TYPE_1,
11  TYPE_2,
12  TYPE_3,
13  TYPE_4,
14 };
15 
16 class DemoFan : public fan::Fan, public Component {
17  public:
18  void set_type(DemoFanType type) { type_ = type; }
20  fan::FanTraits traits{};
21 
22  // oscillation
23  // speed
24  // direction
25  // speed_count
26  switch (type_) {
28  break;
30  traits.set_oscillation(true);
31  break;
33  traits.set_direction(true);
34  traits.set_speed(true);
35  traits.set_supported_speed_count(5);
36  break;
38  traits.set_direction(true);
39  traits.set_speed(true);
40  traits.set_supported_speed_count(100);
41  traits.set_oscillation(true);
42  break;
43  }
44 
45  return traits;
46  }
47 
48  protected:
49  void control(const fan::FanCall &call) override {
50  if (call.get_state().has_value())
51  this->state = *call.get_state();
52  if (call.get_oscillating().has_value())
53  this->oscillating = *call.get_oscillating();
54  if (call.get_speed().has_value())
55  this->speed = *call.get_speed();
56  if (call.get_direction().has_value())
57  this->direction = *call.get_direction();
58 
59  this->publish_state();
60  }
61 
63 };
64 
65 } // namespace demo
66 } // namespace esphome
optional< FanDirection > get_direction() const
Definition: fan.h:74
void control(const fan::FanCall &call) override
Definition: demo_fan.h:49
optional< int > get_speed() const
Definition: fan.h:65
fan::FanTraits get_traits() override
Definition: demo_fan.h:19
int speed
Definition: fan.h:35
bool has_value() const
Definition: optional.h:87
FanDirection direction
Definition: fan.h:37
optional< bool > get_state() const
Definition: fan.h:49
uint8_t type
optional< bool > get_oscillating() const
Definition: fan.h:58
DemoFanType type_
Definition: demo_fan.h:62
bool oscillating
Definition: fan.h:36
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void set_type(DemoFanType type)
Definition: demo_fan.h:18
bool state
Definition: fan.h:34