ESPHome 2026.5.1
Loading...
Searching...
No Matches
demo_fan.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace esphome::demo {
7
8enum class DemoFanType {
9 TYPE_1,
10 TYPE_2,
11 TYPE_3,
12 TYPE_4,
13};
14
15class DemoFan : public fan::Fan, public Component {
16 public:
19 fan::FanTraits traits{};
20
21 // oscillation
22 // speed
23 // direction
24 // speed_count
25 switch (type_) {
27 break;
29 traits.set_oscillation(true);
30 break;
32 traits.set_direction(true);
33 traits.set_speed(true);
34 traits.set_supported_speed_count(5);
35 break;
37 traits.set_direction(true);
38 traits.set_speed(true);
39 traits.set_supported_speed_count(100);
40 traits.set_oscillation(true);
41 break;
42 }
43
44 return traits;
45 }
46
47 protected:
48 void control(const fan::FanCall &call) override {
49 auto state = call.get_state();
50 if (state.has_value())
51 this->state = *state;
52 auto oscillating = call.get_oscillating();
53 if (oscillating.has_value())
54 this->oscillating = *oscillating;
55 auto speed = call.get_speed();
56 if (speed.has_value())
57 this->speed = *speed;
58 auto direction = call.get_direction();
59 if (direction.has_value())
60 this->direction = *direction;
61
62 this->publish_state();
63 }
64
66};
67
68} // namespace esphome::demo
fan::FanTraits get_traits() override
Definition demo_fan.h:18
DemoFanType type_
Definition demo_fan.h:65
void control(const fan::FanCall &call) override
Definition demo_fan.h:48
void set_type(DemoFanType type)
Definition demo_fan.h:17
optional< bool > get_oscillating() const
Definition fan.h:58
optional< int > get_speed() const
Definition fan.h:63
optional< FanDirection > get_direction() const
Definition fan.h:72
void publish_state()
Definition fan.cpp:223
FanDirection direction
The current direction of the fan.
Definition fan.h:116
bool oscillating
The current oscillation state of the fan.
Definition fan.h:112
bool state
The current on/off state of the fan.
Definition fan.h:110
int speed
The current fan speed level.
Definition fan.h:114
uint16_t type