ESPHome 2025.5.0
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 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
fan::FanTraits get_traits() override
Definition demo_fan.h:19
DemoFanType type_
Definition demo_fan.h:62
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_state() const
Definition fan.h:49
optional< bool > get_oscillating() const
Definition fan.h:58
optional< int > get_speed() const
Definition fan.h:65
optional< FanDirection > get_direction() const
Definition fan.h:74
void publish_state()
Definition fan.cpp:117
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
uint8_t type
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7