mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 22:48:10 +01:00
Support raw datapoints for tuya components (#1669)
This commit is contained in:
parent
2b9350ce76
commit
913ac8b7e8
2 changed files with 14 additions and 3 deletions
|
@ -31,7 +31,9 @@ void Tuya::dump_config() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (auto &info : this->datapoints_) {
|
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));
|
ESP_LOGCONFIG(TAG, " Datapoint %u: switch (value: %s)", info.id, ONOFF(info.value_bool));
|
||||||
else if (info.type == TuyaDatapointType::INTEGER)
|
else if (info.type == TuyaDatapointType::INTEGER)
|
||||||
ESP_LOGCONFIG(TAG, " Datapoint %u: int value (value: %d)", info.id, info.value_int);
|
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;
|
datapoint.len = data_len;
|
||||||
|
|
||||||
switch (datapoint.type) {
|
switch (datapoint.type) {
|
||||||
|
case TuyaDatapointType::RAW:
|
||||||
|
datapoint.value_raw = std::vector<uint8_t>(data, data + data_len);
|
||||||
|
ESP_LOGD(TAG, "Datapoint %u update to %s", datapoint.id, hexencode(datapoint.value_raw).c_str());
|
||||||
|
break;
|
||||||
case TuyaDatapointType::BOOLEAN:
|
case TuyaDatapointType::BOOLEAN:
|
||||||
if (data_len != 1) {
|
if (data_len != 1) {
|
||||||
ESP_LOGW(TAG, "Datapoint %u has bad boolean len %zu", datapoint.id, data_len);
|
ESP_LOGW(TAG, "Datapoint %u has bad boolean len %zu", datapoint.id, data_len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
datapoint.value_bool = data[0];
|
datapoint.value_bool = data[0];
|
||||||
|
ESP_LOGD(TAG, "Datapoint %u update to %s", datapoint.id, ONOFF(datapoint.value_bool));
|
||||||
break;
|
break;
|
||||||
case TuyaDatapointType::INTEGER:
|
case TuyaDatapointType::INTEGER:
|
||||||
if (data_len != 4) {
|
if (data_len != 4) {
|
||||||
|
@ -249,9 +256,11 @@ void Tuya::handle_datapoint_(const uint8_t *buffer, size_t len) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
datapoint.value_uint = encode_uint32(data[0], data[1], data[2], data[3]);
|
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;
|
break;
|
||||||
case TuyaDatapointType::STRING:
|
case TuyaDatapointType::STRING:
|
||||||
datapoint.value_string = std::string(reinterpret_cast<const char *>(data), data_len);
|
datapoint.value_string = std::string(reinterpret_cast<const char *>(data), data_len);
|
||||||
|
ESP_LOGD(TAG, "Datapoint %u update to %s", datapoint.id, datapoint.value_string.c_str());
|
||||||
break;
|
break;
|
||||||
case TuyaDatapointType::ENUM:
|
case TuyaDatapointType::ENUM:
|
||||||
if (data_len != 1) {
|
if (data_len != 1) {
|
||||||
|
@ -259,6 +268,7 @@ void Tuya::handle_datapoint_(const uint8_t *buffer, size_t len) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
datapoint.value_enum = data[0];
|
datapoint.value_enum = data[0];
|
||||||
|
ESP_LOGD(TAG, "Datapoint %u update to %d", datapoint.id, datapoint.value_enum);
|
||||||
break;
|
break;
|
||||||
case TuyaDatapointType::BITMASK:
|
case TuyaDatapointType::BITMASK:
|
||||||
switch (data_len) {
|
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);
|
ESP_LOGW(TAG, "Datapoint %u has bad bitmask len %zu", datapoint.id, data_len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ESP_LOGD(TAG, "Datapoint %u update to %#08X", datapoint.id, datapoint.value_bitmask);
|
||||||
break;
|
break;
|
||||||
default:
|
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;
|
return;
|
||||||
}
|
}
|
||||||
ESP_LOGD(TAG, "Datapoint %u update to %u", datapoint.id, datapoint.value_uint);
|
|
||||||
|
|
||||||
// Update internal datapoints
|
// Update internal datapoints
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
|
@ -32,6 +32,7 @@ struct TuyaDatapoint {
|
||||||
uint32_t value_bitmask;
|
uint32_t value_bitmask;
|
||||||
};
|
};
|
||||||
std::string value_string;
|
std::string value_string;
|
||||||
|
std::vector<uint8_t> value_raw;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TuyaDatapointListener {
|
struct TuyaDatapointListener {
|
||||||
|
|
Loading…
Reference in a new issue