mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-22 21:58:29 +02:00
c5c24c1989
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
29 lines
809 B
C++
29 lines
809 B
C++
#include "esphome/core/log.h"
|
|
#include "tuya_switch.h"
|
|
|
|
namespace esphome {
|
|
namespace tuya {
|
|
|
|
static const char *TAG = "tuya.switch";
|
|
|
|
void TuyaSwitch::setup() {
|
|
this->parent_->register_listener(this->switch_id_, [this](TuyaDatapoint datapoint) {
|
|
ESP_LOGV(TAG, "MCU reported switch %u is: %s", this->switch_id_, ONOFF(datapoint.value_bool));
|
|
this->publish_state(datapoint.value_bool);
|
|
});
|
|
}
|
|
|
|
void TuyaSwitch::write_state(bool state) {
|
|
ESP_LOGV(TAG, "Setting switch %u: %s", this->switch_id_, ONOFF(state));
|
|
this->parent_->set_datapoint_value(this->switch_id_, state);
|
|
this->publish_state(state);
|
|
}
|
|
|
|
void TuyaSwitch::dump_config() {
|
|
LOG_SWITCH("", "Tuya Switch", this);
|
|
ESP_LOGCONFIG(TAG, " Switch has datapoint ID %u", this->switch_id_);
|
|
}
|
|
|
|
} // namespace tuya
|
|
} // namespace esphome
|