ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
uart_switch.cpp
Go to the documentation of this file.
1#include "uart_switch.h"
2#include "esphome/core/log.h"
4
5namespace esphome::uart {
6
7ESPHOME_LOG_TAG(TAG, "uart.switch");
8
10 if (this->send_every_) {
12 if (now - this->last_transmission_ > this->send_every_) {
13 this->write_command_(this->state);
14 this->last_transmission_ = now;
15 }
16 }
17}
18
20 if (state && this->data_on_len_ != 0) {
21 ESP_LOGD(TAG, "'%s': Sending on data", LOG_STR_ARG(this->get_log_name()));
22 this->write_array_progmem(this->data_on_, this->data_on_len_);
23 }
24 if (!state && this->data_off_len_ != 0) {
25 ESP_LOGD(TAG, "'%s': Sending off data", LOG_STR_ARG(this->get_log_name()));
27 }
28}
29
31 if (!this->single_state_) {
32 this->publish_state(state);
33 this->write_command_(state);
34 this->last_transmission_ = millis();
35 return;
36 }
37
38 if (!state) {
39 this->publish_state(false);
40 return;
41 }
42
43 this->publish_state(true);
44 this->write_command_(true);
45
46 if (this->send_every_ == 0) {
47 this->publish_state(false);
48 } else {
49 this->last_transmission_ = millis();
50 }
51}
52
54 LOG_SWITCH("", "UART Switch", this);
55 if (this->send_every_) {
56 ESP_LOGCONFIG(TAG, " Send Every: %" PRIu32, this->send_every_);
57 }
58}
59
60} // namespace esphome::uart
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
bool state
The current reported state of the binary sensor.
Definition switch.h:60
void publish_state(bool state)
Publish a state to the front-end from the back-end.
Definition switch.cpp:70
void write_array_progmem(const uint8_t *data, size_t len)
Definition uart.h:31
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
bool state
Definition fan.h:2
ESPHOME_LOG_TAG(TAG, "uart.binary_sensor")
uint32_t IRAM_ATTR HOT millis()
Definition hal.cpp:25
Application App
Global storage of Application pointer - only one Application can exist.
static void uint32_t