ESPHome 2026.11.0-dev
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
25 void set_interlock(Switch *const *interlock, size_t count) {
26 this->interlock_ = ConstVector<Switch *>(interlock, count);
27 }
28 void set_interlock_wait_time(uint32_t interlock_wait_time) { interlock_wait_time_ = interlock_wait_time; }
29#endif
30
31 protected:
32 void write_state(bool state) override;
33
34 GPIOPin *pin_{nullptr};
35#ifdef USE_GPIO_SWITCH_INTERLOCK
38#endif
39};
40
41} // namespace esphome::gpio
Lightweight read-only view over a const array stored in RODATA (will typically be in flash memory).
Definition helpers.h:130
void dump_config() override
float get_setup_priority() const override
ConstVector< Switch * > interlock_
Definition gpio_switch.h:36
void set_interlock(Switch *const *interlock, size_t count)
Codegen only: the table must outlive this switch; it may list this switch, which is skipped.
Definition gpio_switch.h:25
void set_interlock_wait_time(uint32_t interlock_wait_time)
Definition gpio_switch.h:28
void write_state(bool state) override
void set_pin(GPIOPin *pin)
Definition gpio_switch.h:15
Base class for all switches.
Definition switch.h:43
bool state
The current reported state of the binary sensor.
Definition switch.h:60
unsigned count
Definition gif.cpp:51
static void uint32_t