ESPHome  2024.12.2
mqtt_fan.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "esphome/core/defines.h"
4 
5 #ifdef USE_MQTT
6 #ifdef USE_FAN
7 
9 #include "mqtt_component.h"
10 
11 namespace esphome {
12 namespace mqtt {
13 
15  public:
16  explicit MQTTFanComponent(fan::Fan *state);
17 
18  MQTT_COMPONENT_CUSTOM_TOPIC(oscillation, command)
19  MQTT_COMPONENT_CUSTOM_TOPIC(oscillation, state)
20  MQTT_COMPONENT_CUSTOM_TOPIC(speed_level, command)
21  MQTT_COMPONENT_CUSTOM_TOPIC(speed_level, state)
24 
25  void send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) override;
26 
27  // ========== INTERNAL METHODS ==========
28  // (In most use cases you won't need these)
30  void setup() override;
31 
32  void dump_config() override;
33 
35  bool send_initial_state() override;
36  bool publish_state();
38  std::string component_type() const override;
39 
40  fan::Fan *get_state() const;
41 
42  protected:
43  const EntityBase *get_entity() const override;
44 
46 };
47 
48 } // namespace mqtt
49 } // namespace esphome
50 
51 #endif
52 #endif // USE_MQTT
MQTTFanComponent(fan::Fan *state)
Definition: mqtt_fan.cpp:16
void setup() override
Setup the fan subscriptions and discovery.
Definition: mqtt_fan.cpp:22
const EntityBase * get_entity() const override
Definition: mqtt_fan.cpp:20
fan::Fan * get_state() const
Definition: mqtt_fan.cpp:18
int speed
Definition: fan.h:35
std::string component_type() const override
'fan' component type for discovery.
Definition: mqtt_fan.cpp:19
state state state void send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) override
Definition: mqtt_fan.cpp:109
Simple Helper struct used for Home Assistant MQTT send_discovery().
bool send_initial_state() override
Send the full current state to MQTT.
Definition: mqtt_fan.cpp:107
MQTT_COMPONENT_CUSTOM_TOPIC(oscillation, command) MQTT_COMPONENT_CUSTOM_TOPIC(oscillation
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
bool state
Definition: fan.h:34
MQTTComponent is the base class for all components that interact with MQTT to expose certain function...