15#define LOG_FAN(prefix, type, obj) \
16 if (log_entity_header(TAG, prefix, LOG_STR_LITERAL(type), (obj))) { \
17 (obj)->dump_traits_(TAG, prefix); \
135 this->supported_preset_modes_.assign_copy(preset_modes.begin(), preset_modes.size());
138 this->supported_preset_modes_.assign_copy(preset_modes.data(), preset_modes.size());
141 this->supported_preset_modes_.assign_copy(preset_modes.
data(), preset_modes.
size());
145 this->supported_preset_modes_.assign_static(preset_modes,
count);
194 const char *preset_mode_{
nullptr};
constexpr size_t size() const
StringRef is a reference to a string owned by something else.
static StringRef from_maybe_nullptr(const char *s)
FanCall & set_oscillating(bool oscillating)
FanCall & set_direction(FanDirection direction)
optional< bool > binary_state_
optional< FanDirection > direction_
FanCall & set_direction(optional< FanDirection > direction)
optional< bool > get_state() const
const char * preset_mode_
const char * get_preset_mode() const
optional< bool > get_oscillating() const
FanCall & set_state(optional< bool > binary_state)
bool has_preset_mode() const
FanCall & set_speed(int speed)
FanCall & set_state(bool binary_state)
FanCall & set_oscillating(optional< bool > oscillating)
optional< int > get_speed() const
optional< bool > oscillating_
FanCall & set_preset_mode(const std::string &preset_mode)
optional< FanDirection > get_direction() const
void set_supported_preset_modes(std::initializer_list< const char * > preset_modes)
Set the supported preset modes; the list is copied (stored on Fan, referenced by FanTraits).
void add_on_state_callback(F &&callback)
Register a callback that will be called each time the state changes.
void set_supported_preset_modes(const std::vector< const char * > &preset_modes)
virtual FanTraits get_traits()=0
void set_supported_preset_modes(const FanPresetModes &preset_modes)
LazyCallbackManager< void()> state_callback_
void apply_preset_mode_(const FanCall &call)
Apply preset mode from a FanCall (handles speed-clears-preset convention)
void clear_preset_mode_()
Clear the preset mode.
bool set_preset_mode_(const char *preset_mode, size_t len)
Set the preset mode (finds and stores pointer from traits).
StringRef get_preset_mode() const
Get the current preset mode.
FanDirection direction
The current direction of the fan.
void set_supported_preset_modes_static(const char *const *preset_modes, size_t count)
Points at a static table that outlives the fan (codegen); call before any runtime copy.
FanRestoreMode restore_mode_
bool oscillating
The current oscillation state of the fan.
virtual void control(const FanCall &call)=0
bool state
The current on/off state of the fan.
const char * find_preset_mode_(const char *preset_mode)
Find and return the matching preset mode pointer from traits, or nullptr if not found.
void wire_preset_modes_(FanTraits &traits)
Wire the Fan-owned preset modes pointer into the given traits object.
void set_restore_mode(FanRestoreMode restore_mode)
Set the restore mode of this fan.
bool has_preset_mode() const
Check if a preset mode is currently active.
int speed
The current fan speed level.
void dump_traits_(const char *tag, const char *prefix)
optional< FanRestoreState > restore_state_()
void set_supported_preset_modes_(const FanPresetModes *preset_modes)
Set the preset modes pointer (only Fan::wire_preset_modes_() should call this).
FanRestoreMode
Restore mode of a fan.
@ RESTORE_INVERTED_DEFAULT_OFF
@ RESTORE_INVERTED_DEFAULT_ON
const LogString * fan_direction_to_string(FanDirection direction)
esphome::fan::Fan __attribute__
FanDirection
Simple enum to represent the direction of a fan.
static constexpr uint8_t NO_PRESET
void apply(Fan &fan)
Apply these settings to the fan.
FanCall to_call(Fan &fan)
Convert this struct to a fan call that can be performed.