1
0
mirror of https://github.com/esphome/esphome.git synced 2025-02-14 08:58:14 +00:00
DAVe3283 e0cee472c3
Fix compile with latest esp-idf on esp32c6 (#5677)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2023-11-05 23:13:01 +00:00

35 lines
1.3 KiB
C++

#include "esphome/core/log.h"
#include "tuya_sensor.h"
#include <cinttypes>
namespace esphome {
namespace tuya {
static const char *const TAG = "tuya.sensor";
void TuyaSensor::setup() {
this->parent_->register_listener(this->sensor_id_, [this](const TuyaDatapoint &datapoint) {
if (datapoint.type == TuyaDatapointType::BOOLEAN) {
ESP_LOGV(TAG, "MCU reported sensor %u is: %s", datapoint.id, ONOFF(datapoint.value_bool));
this->publish_state(datapoint.value_bool);
} else if (datapoint.type == TuyaDatapointType::INTEGER) {
ESP_LOGV(TAG, "MCU reported sensor %u is: %d", datapoint.id, datapoint.value_int);
this->publish_state(datapoint.value_int);
} else if (datapoint.type == TuyaDatapointType::ENUM) {
ESP_LOGV(TAG, "MCU reported sensor %u is: %u", datapoint.id, datapoint.value_enum);
this->publish_state(datapoint.value_enum);
} else if (datapoint.type == TuyaDatapointType::BITMASK) {
ESP_LOGV(TAG, "MCU reported sensor %u is: %" PRIx32, datapoint.id, datapoint.value_bitmask);
this->publish_state(datapoint.value_bitmask);
}
});
}
void TuyaSensor::dump_config() {
LOG_SENSOR("", "Tuya Sensor", this);
ESP_LOGCONFIG(TAG, " Sensor has datapoint ID %u", this->sensor_id_);
}
} // namespace tuya
} // namespace esphome