1
0
mirror of https://github.com/esphome/esphome.git synced 2025-04-01 16:38:19 +01:00
Chris Nussbaum 6144ce1fe0
Break the Tuya set_datapoint_value method into separate methods per datapoint type (#2059)
Co-authored-by: Chris Nussbaum <chris.nussbaum@protolabs.com>
Co-authored-by: Trevor North <trevor@freedisc.co.uk>
2021-08-11 07:44:31 +12:00

29 lines
830 B
C++

#include "esphome/core/log.h"
#include "tuya_switch.h"
namespace esphome {
namespace tuya {
static const char *const TAG = "tuya.switch";
void TuyaSwitch::setup() {
this->parent_->register_listener(this->switch_id_, [this](const 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_boolean_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