ESPHome 2026.3.3
Loading...
Searching...
No Matches
demo_fan.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace esphome {
7namespace demo {
8
9enum class DemoFanType {
10 TYPE_1,
11 TYPE_2,
12 TYPE_3,
13 TYPE_4,
14};
15
16class DemoFan : public fan::Fan, public Component {
17 public:
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 auto state = call.get_state();
51 if (state.has_value())
52 this->state = *state;
53 auto oscillating = call.get_oscillating();
54 if (oscillating.has_value())
55 this->oscillating = *oscillating;
56 auto speed = call.get_speed();
57 if (speed.has_value())
58 this->speed = *speed;
59 auto direction = call.get_direction();
60 if (direction.has_value())
61 this->direction = *direction;
62
63 this->publish_state();
64 }
65
67};
68
69} // namespace demo
70} // namespace esphome
fan::FanTraits get_traits() override
Definition demo_fan.h:19
DemoFanType type_
Definition demo_fan.h:66
void control(const fan::FanCall &call) override
Definition demo_fan.h:49
void set_type(DemoFanType type)
Definition demo_fan.h:18
optional< bool > get_oscillating() const
Definition fan.h:59
optional< int > get_speed() const
Definition fan.h:64
optional< FanDirection > get_direction() const
Definition fan.h:73
void publish_state()
Definition fan.cpp:197
FanDirection direction
The current direction of the fan.
Definition fan.h:117
bool oscillating
The current oscillation state of the fan.
Definition fan.h:113
bool state
The current on/off state of the fan.
Definition fan.h:111
int speed
The current fan speed level.
Definition fan.h:115
uint16_t type
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7