ESPHome 2026.10.2
Loading...
Searching...
No Matches
gpio_switch.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
7
8namespace esphome::gpio {
9
10class GPIOSwitch final : public switch_::Switch, public Component {
11 public:
12 // User provided, not "= default": `new(p) GPIOSwitch()` would zero-fill .bss that is already zero.
14
15 void set_pin(GPIOPin *pin) { pin_ = pin; }
16
17 // ========== INTERNAL METHODS ==========
18 // (In most use cases you won't need these)
19 float get_setup_priority() const override;
20
21 void setup() override;
22 void dump_config() override;
23#ifdef USE_GPIO_SWITCH_INTERLOCK
24 void set_interlock(const std::initializer_list<Switch *> &interlock);
25 void set_interlock_wait_time(uint32_t interlock_wait_time) { interlock_wait_time_ = interlock_wait_time; }
26#endif
27
28 protected:
29 void write_state(bool state) override;
30
31 GPIOPin *pin_{nullptr};
32#ifdef USE_GPIO_SWITCH_INTERLOCK
35#endif
36};
37
38} // namespace esphome::gpio
Fixed-capacity vector - sized once through init() or try_init(); push_back never reallocates This avo...
Definition helpers.h:621
void dump_config() override
float get_setup_priority() const override
void set_interlock(const std::initializer_list< Switch * > &interlock)
void set_interlock_wait_time(uint32_t interlock_wait_time)
Definition gpio_switch.h:25
void write_state(bool state) override
void set_pin(GPIOPin *pin)
Definition gpio_switch.h:15
FixedVector< Switch * > interlock_
Definition gpio_switch.h:33
Base class for all switches.
Definition switch.h:38
bool state
The current reported state of the binary sensor.
Definition switch.h:55
static void uint32_t