ESPHome 2025.5.0
Loading...
Searching...
No Matches
tuya_switch.cpp
Go to the documentation of this file.
1#include "esphome/core/log.h"
2#include "tuya_switch.h"
3
4namespace esphome {
5namespace tuya {
6
7static const char *const TAG = "tuya.switch";
8
10 this->parent_->register_listener(this->switch_id_, [this](const TuyaDatapoint &datapoint) {
11 ESP_LOGV(TAG, "MCU reported switch %u is: %s", this->switch_id_, ONOFF(datapoint.value_bool));
12 this->publish_state(datapoint.value_bool);
13 });
14}
15
17 ESP_LOGV(TAG, "Setting switch %u: %s", this->switch_id_, ONOFF(state));
19 this->publish_state(state);
20}
21
23 LOG_SWITCH("", "Tuya Switch", this);
24 ESP_LOGCONFIG(TAG, " Switch has datapoint ID %u", this->switch_id_);
25}
26
27} // namespace tuya
28} // namespace esphome
bool state
The current reported state of the binary sensor.
Definition switch.h:53
void publish_state(bool state)
Publish a state to the front-end from the back-end.
Definition switch.cpp:47
void set_boolean_datapoint_value(uint8_t datapoint_id, bool value)
Definition tuya.cpp:569
void register_listener(uint8_t datapoint_id, const std::function< void(TuyaDatapoint)> &func)
Definition tuya.cpp:697
void dump_config() override
void write_state(bool state) override
bool state
Definition fan.h:0
const char *const TAG
Definition spi.cpp:8
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7