ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
fan_traits.h
Go to the documentation of this file.
1#include <set>
2#include <utility>
3
4#pragma once
5
6namespace esphome {
7
8#ifdef USE_API
9namespace api {
10class APIConnection;
11} // namespace api
12#endif
13
14namespace fan {
15
16class FanTraits {
17 public:
18 FanTraits() = default;
19 FanTraits(bool oscillation, bool speed, bool direction, int speed_count)
20 : oscillation_(oscillation), speed_(speed), direction_(direction), speed_count_(speed_count) {}
21
23 bool supports_oscillation() const { return this->oscillation_; }
25 void set_oscillation(bool oscillation) { this->oscillation_ = oscillation; }
27 bool supports_speed() const { return this->speed_; }
29 void set_speed(bool speed) { this->speed_ = speed; }
31 int supported_speed_count() const { return this->speed_count_; }
33 void set_supported_speed_count(int speed_count) { this->speed_count_ = speed_count; }
35 bool supports_direction() const { return this->direction_; }
39 std::set<std::string> supported_preset_modes() const { return this->preset_modes_; }
41 void set_supported_preset_modes(const std::set<std::string> &preset_modes) { this->preset_modes_ = preset_modes; }
43 bool supports_preset_modes() const { return !this->preset_modes_.empty(); }
44
45 protected:
46#ifdef USE_API
47 // The API connection is a friend class to access internal methods
48 friend class api::APIConnection;
49 // This method returns a reference to the internal preset modes set.
50 // It is used by the API to avoid copying data when encoding messages.
51 // Warning: Do not use this method outside of the API connection code.
52 // It returns a reference to internal data that can be invalidated.
53 const std::set<std::string> &supported_preset_modes_for_api_() const { return this->preset_modes_; }
54#endif
55 bool oscillation_{false};
56 bool speed_{false};
57 bool direction_{false};
59 std::set<std::string> preset_modes_{};
60};
61
62} // namespace fan
63} // namespace esphome
void set_direction(bool direction)
Set whether this fan supports changing direction.
Definition fan_traits.h:37
bool supports_preset_modes() const
Return if preset modes are supported.
Definition fan_traits.h:43
void set_speed(bool speed)
Set whether this fan supports speed levels.
Definition fan_traits.h:29
int supported_speed_count() const
Return how many speed levels the fan has.
Definition fan_traits.h:31
void set_supported_speed_count(int speed_count)
Set how many speed levels this fan has.
Definition fan_traits.h:33
bool supports_direction() const
Return if this fan supports changing direction.
Definition fan_traits.h:35
void set_oscillation(bool oscillation)
Set whether this fan supports oscillation.
Definition fan_traits.h:25
bool supports_speed() const
Return if this fan supports speed modes.
Definition fan_traits.h:27
FanTraits(bool oscillation, bool speed, bool direction, int speed_count)
Definition fan_traits.h:19
std::set< std::string > preset_modes_
Definition fan_traits.h:59
const std::set< std::string > & supported_preset_modes_for_api_() const
Definition fan_traits.h:53
void set_supported_preset_modes(const std::set< std::string > &preset_modes)
Set the preset modes supported by the fan.
Definition fan_traits.h:41
std::set< std::string > supported_preset_modes() const
Return the preset modes supported by the fan.
Definition fan_traits.h:39
bool supports_oscillation() const
Return if this fan supports oscillation.
Definition fan_traits.h:23
FanDirection direction
Definition fan.h:3
int speed
Definition fan.h:1
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7