ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
uart_switch.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <cinttypes>
8
9namespace esphome::uart {
10
11class UARTSwitch final : public switch_::Switch, public UARTDevice, public Component {
12 public:
13 void loop() override;
14
15 void set_data_on(const uint8_t *data, uint16_t len) {
16 this->data_on_ = data;
17 this->data_on_len_ = len;
18 }
19 void set_data_off(const uint8_t *data, uint16_t len) {
20 this->data_off_ = data;
21 this->data_off_len_ = len;
22 }
23 void set_send_every(uint32_t send_every) { this->send_every_ = send_every; }
24 void set_single_state(bool single) { this->single_state_ = single; }
25
26 void dump_config() override;
27
28 protected:
29 void write_command_(bool state);
30 void write_state(bool state) override;
31 const uint8_t *data_on_{nullptr};
32 const uint8_t *data_off_{nullptr};
33 uint16_t data_on_len_{0};
34 uint16_t data_off_len_{0};
35 bool single_state_{false};
38};
39
40} // namespace esphome::uart
Base class for all switches.
Definition switch.h:43
bool state
The current reported state of the binary sensor.
Definition switch.h:60
const uint8_t * data_on_
Definition uart_switch.h:31
void write_state(bool state) override
const uint8_t * data_off_
Definition uart_switch.h:32
void write_command_(bool state)
void dump_config() override
void set_data_on(const uint8_t *data, uint16_t len)
Definition uart_switch.h:15
void set_single_state(bool single)
Definition uart_switch.h:24
void set_data_off(const uint8_t *data, uint16_t len)
Definition uart_switch.h:19
void set_send_every(uint32_t send_every)
Definition uart_switch.h:23
const void size_t len
Definition hal.h:68
static void uint32_t