ESPHome 2026.6.0-dev
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::tuya {
5
6static const char *const TAG = "tuya.switch";
7
9 this->parent_->register_listener(this->switch_id_, [this](const TuyaDatapoint &datapoint) {
10 ESP_LOGV(TAG, "MCU reported switch %u is: %s", this->switch_id_, ONOFF(datapoint.value_bool));
11 this->publish_state(datapoint.value_bool);
12 });
13}
14
16 ESP_LOGV(TAG, "Setting switch %u: %s", this->switch_id_, ONOFF(state));
18 this->publish_state(state);
19}
20
22 LOG_SWITCH("", "Tuya Switch", this);
23 ESP_LOGCONFIG(TAG, " Switch has datapoint ID %u", this->switch_id_);
24}
25
26} // namespace esphome::tuya
bool state
The current reported state of the binary sensor.
Definition switch.h:55
void publish_state(bool state)
Publish a state to the front-end from the back-end.
Definition switch.cpp:56
void set_boolean_datapoint_value(uint8_t datapoint_id, bool value)
Definition tuya.cpp:618
void register_listener(uint8_t datapoint_id, const std::function< void(TuyaDatapoint)> &func)
Definition tuya.cpp:749
void dump_config() override
void write_state(bool state) override
bool state
Definition fan.h:2
const char *const TAG
Definition spi.cpp:7