ESPHome  2024.12.2
uart_switch.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 #include <cinttypes>
8 #include <vector>
9 
10 namespace esphome {
11 namespace uart {
12 
13 class UARTSwitch : public switch_::Switch, public UARTDevice, public Component {
14  public:
15  void loop() override;
16 
17  void set_data_on(const std::vector<uint8_t> &data) { this->data_on_ = data; }
18  void set_data_off(const std::vector<uint8_t> &data) { this->data_off_ = data; }
19  void set_send_every(uint32_t send_every) { this->send_every_ = send_every; }
20  void set_single_state(bool single) { this->single_state_ = single; }
21 
22  void dump_config() override;
23 
24  protected:
25  void write_command_(bool state);
26  void write_state(bool state) override;
27  std::vector<uint8_t> data_on_;
28  std::vector<uint8_t> data_off_;
29  bool single_state_{false};
30  uint32_t send_every_;
32 };
33 
34 } // namespace uart
35 } // namespace esphome
Base class for all switches.
Definition: switch.h:39
void set_send_every(uint32_t send_every)
Definition: uart_switch.h:19
void set_single_state(bool single)
Definition: uart_switch.h:20
std::vector< uint8_t > data_on_
Definition: uart_switch.h:27
void write_command_(bool state)
Definition: uart_switch.cpp:19
std::vector< uint8_t > data_off_
Definition: uart_switch.h:28
void dump_config() override
Definition: uart_switch.cpp:53
void set_data_on(const std::vector< uint8_t > &data)
Definition: uart_switch.h:17
void loop() override
Definition: uart_switch.cpp:9
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void write_state(bool state) override
Definition: uart_switch.cpp:30
void set_data_off(const std::vector< uint8_t > &data)
Definition: uart_switch.h:18
bool state
The current reported state of the binary sensor.
Definition: switch.h:53