Tuya improvements (#1491)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Trevor North
2021-06-02 10:31:56 +01:00
committed by GitHub
parent c3938d04f3
commit c5c24c1989
12 changed files with 321 additions and 219 deletions
@@ -8,19 +8,14 @@ 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);
ESP_LOGD(TAG, "MCU reported switch is: %s", ONOFF(datapoint.value_bool));
});
}
void TuyaSwitch::write_state(bool state) {
TuyaDatapoint datapoint{};
datapoint.id = this->switch_id_;
datapoint.type = TuyaDatapointType::BOOLEAN;
datapoint.value_bool = state;
this->parent_->set_datapoint_value(datapoint);
ESP_LOGD(TAG, "Setting switch: %s", ONOFF(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);
}