diff --git a/esphome/components/tuya/tuya.cpp b/esphome/components/tuya/tuya.cpp index 96e832fe89..3f09db068d 100644 --- a/esphome/components/tuya/tuya.cpp +++ b/esphome/components/tuya/tuya.cpp @@ -31,7 +31,9 @@ void Tuya::dump_config() { return; } for (auto &info : this->datapoints_) { - if (info.type == TuyaDatapointType::BOOLEAN) + if (info.type == TuyaDatapointType::RAW) + ESP_LOGCONFIG(TAG, " Datapoint %u: raw (value: %s)", info.id, hexencode(info.value_raw).c_str()); + else if (info.type == TuyaDatapointType::BOOLEAN) ESP_LOGCONFIG(TAG, " Datapoint %u: switch (value: %s)", info.id, ONOFF(info.value_bool)); else if (info.type == TuyaDatapointType::INTEGER) ESP_LOGCONFIG(TAG, " Datapoint %u: int value (value: %d)", info.id, info.value_int); @@ -236,12 +238,17 @@ void Tuya::handle_datapoint_(const uint8_t *buffer, size_t len) { datapoint.len = data_len; switch (datapoint.type) { + case TuyaDatapointType::RAW: + datapoint.value_raw = std::vector(data, data + data_len); + ESP_LOGD(TAG, "Datapoint %u update to %s", datapoint.id, hexencode(datapoint.value_raw).c_str()); + break; case TuyaDatapointType::BOOLEAN: if (data_len != 1) { ESP_LOGW(TAG, "Datapoint %u has bad boolean len %zu", datapoint.id, data_len); return; } datapoint.value_bool = data[0]; + ESP_LOGD(TAG, "Datapoint %u update to %s", datapoint.id, ONOFF(datapoint.value_bool)); break; case TuyaDatapointType::INTEGER: if (data_len != 4) { @@ -249,9 +256,11 @@ void Tuya::handle_datapoint_(const uint8_t *buffer, size_t len) { return; } datapoint.value_uint = encode_uint32(data[0], data[1], data[2], data[3]); + ESP_LOGD(TAG, "Datapoint %u update to %d", datapoint.id, datapoint.value_int); break; case TuyaDatapointType::STRING: datapoint.value_string = std::string(reinterpret_cast(data), data_len); + ESP_LOGD(TAG, "Datapoint %u update to %s", datapoint.id, datapoint.value_string.c_str()); break; case TuyaDatapointType::ENUM: if (data_len != 1) { @@ -259,6 +268,7 @@ void Tuya::handle_datapoint_(const uint8_t *buffer, size_t len) { return; } datapoint.value_enum = data[0]; + ESP_LOGD(TAG, "Datapoint %u update to %d", datapoint.id, datapoint.value_enum); break; case TuyaDatapointType::BITMASK: switch (data_len) { @@ -275,12 +285,12 @@ void Tuya::handle_datapoint_(const uint8_t *buffer, size_t len) { ESP_LOGW(TAG, "Datapoint %u has bad bitmask len %zu", datapoint.id, data_len); return; } + ESP_LOGD(TAG, "Datapoint %u update to %#08X", datapoint.id, datapoint.value_bitmask); break; default: - ESP_LOGW(TAG, "Datapoint %u has unknown type 0x%02hhX", datapoint.id, datapoint.type); + ESP_LOGW(TAG, "Datapoint %u has unknown type %#02hhX", datapoint.id, datapoint.type); return; } - ESP_LOGD(TAG, "Datapoint %u update to %u", datapoint.id, datapoint.value_uint); // Update internal datapoints bool found = false; diff --git a/esphome/components/tuya/tuya.h b/esphome/components/tuya/tuya.h index f98b7522fc..42848b4914 100644 --- a/esphome/components/tuya/tuya.h +++ b/esphome/components/tuya/tuya.h @@ -32,6 +32,7 @@ struct TuyaDatapoint { uint32_t value_bitmask; }; std::string value_string; + std::vector value_raw; }; struct TuyaDatapointListener {