ESPHome 2026.1.4
Loading...
Searching...
No Matches
mqtt_switch.h
Go to the documentation of this file.
1#pragma once
2
4
5#ifdef USE_MQTT
6#ifdef USE_SWITCH
7
9#include "mqtt_component.h"
10
11namespace esphome::mqtt {
12
14 public:
15 explicit MQTTSwitchComponent(switch_::Switch *a_switch);
16
17 // ========== INTERNAL METHODS ==========
18 // (In most use cases you won't need these)
19 void setup() override;
20 void dump_config() override;
21
22 void send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) override;
23
24 bool send_initial_state() override;
25
26 bool publish_state(bool state);
27
28 protected:
30 const char *component_type() const override;
31 const EntityBase *get_entity() const override;
32
34};
35
36} // namespace esphome::mqtt
37
38#endif
39#endif // USE_MQTT
MQTTComponent is the base class for all components that interact with MQTT to expose certain function...
void send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) override
const EntityBase * get_entity() const override
MQTTSwitchComponent(switch_::Switch *a_switch)
const char * component_type() const override
"switch" component type.
Base class for all switches.
Definition switch.h:39
bool state
Definition fan.h:0
Simple Helper struct used for Home Assistant MQTT send_discovery().