ESPHome  2024.4.0
tuya_sensor.cpp
Go to the documentation of this file.
1 #include "esphome/core/log.h"
2 #include "tuya_sensor.h"
3 #include <cinttypes>
4 
5 namespace esphome {
6 namespace tuya {
7 
8 static const char *const TAG = "tuya.sensor";
9 
11  this->parent_->register_listener(this->sensor_id_, [this](const TuyaDatapoint &datapoint) {
12  if (datapoint.type == TuyaDatapointType::BOOLEAN) {
13  ESP_LOGV(TAG, "MCU reported sensor %u is: %s", datapoint.id, ONOFF(datapoint.value_bool));
14  this->publish_state(datapoint.value_bool);
15  } else if (datapoint.type == TuyaDatapointType::INTEGER) {
16  ESP_LOGV(TAG, "MCU reported sensor %u is: %d", datapoint.id, datapoint.value_int);
17  this->publish_state(datapoint.value_int);
18  } else if (datapoint.type == TuyaDatapointType::ENUM) {
19  ESP_LOGV(TAG, "MCU reported sensor %u is: %u", datapoint.id, datapoint.value_enum);
20  this->publish_state(datapoint.value_enum);
21  } else if (datapoint.type == TuyaDatapointType::BITMASK) {
22  ESP_LOGV(TAG, "MCU reported sensor %u is: %" PRIx32, datapoint.id, datapoint.value_bitmask);
23  this->publish_state(datapoint.value_bitmask);
24  }
25  });
26 }
27 
29  LOG_SENSOR("", "Tuya Sensor", this);
30  ESP_LOGCONFIG(TAG, " Sensor has datapoint ID %u", this->sensor_id_);
31 }
32 
33 } // namespace tuya
34 } // namespace esphome
TuyaDatapointType type
Definition: tuya.h:30
void register_listener(uint8_t datapoint_id, const std::function< void(TuyaDatapoint)> &func)
Definition: tuya.cpp:667
const char *const TAG
Definition: spi.cpp:8
void dump_config() override
Definition: tuya_sensor.cpp:28
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7