ESPHome  2024.12.2
fan_traits.h
Go to the documentation of this file.
1 #include <set>
2 #include <utility>
3 
4 #pragma once
5 
6 namespace esphome {
7 namespace fan {
8 
9 class FanTraits {
10  public:
11  FanTraits() = default;
12  FanTraits(bool oscillation, bool speed, bool direction, int speed_count)
13  : oscillation_(oscillation), speed_(speed), direction_(direction), speed_count_(speed_count) {}
14 
16  bool supports_oscillation() const { return this->oscillation_; }
18  void set_oscillation(bool oscillation) { this->oscillation_ = oscillation; }
20  bool supports_speed() const { return this->speed_; }
22  void set_speed(bool speed) { this->speed_ = speed; }
24  int supported_speed_count() const { return this->speed_count_; }
26  void set_supported_speed_count(int speed_count) { this->speed_count_ = speed_count; }
28  bool supports_direction() const { return this->direction_; }
30  void set_direction(bool direction) { this->direction_ = direction; }
32  std::set<std::string> supported_preset_modes() const { return this->preset_modes_; }
34  void set_supported_preset_modes(const std::set<std::string> &preset_modes) { this->preset_modes_ = preset_modes; }
36  bool supports_preset_modes() const { return !this->preset_modes_.empty(); }
37 
38  protected:
39  bool oscillation_{false};
40  bool speed_{false};
41  bool direction_{false};
42  int speed_count_{};
43  std::set<std::string> preset_modes_{};
44 };
45 
46 } // namespace fan
47 } // namespace esphome
int speed
Definition: fan.h:35
bool supports_direction() const
Return if this fan supports changing direction.
Definition: fan_traits.h:28
bool supports_oscillation() const
Return if this fan supports oscillation.
Definition: fan_traits.h:16
bool supports_preset_modes() const
Return if preset modes are supported.
Definition: fan_traits.h:36
int supported_speed_count() const
Return how many speed levels the fan has.
Definition: fan_traits.h:24
FanDirection direction
Definition: fan.h:37
void set_oscillation(bool oscillation)
Set whether this fan supports oscillation.
Definition: fan_traits.h:18
std::set< std::string > preset_modes_
Definition: fan_traits.h:43
void set_speed(bool speed)
Set whether this fan supports speed levels.
Definition: fan_traits.h:22
std::set< std::string > supported_preset_modes() const
Return the preset modes supported by the fan.
Definition: fan_traits.h:32
void set_supported_preset_modes(const std::set< std::string > &preset_modes)
Set the preset modes supported by the fan.
Definition: fan_traits.h:34
void set_direction(bool direction)
Set whether this fan supports changing direction.
Definition: fan_traits.h:30
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
FanTraits(bool oscillation, bool speed, bool direction, int speed_count)
Definition: fan_traits.h:12
void set_supported_speed_count(int speed_count)
Set how many speed levels this fan has.
Definition: fan_traits.h:26
bool supports_speed() const
Return if this fan supports speed modes.
Definition: fan_traits.h:20