mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-25 15:18:29 +02:00
Add support for Tuya Sensors (#1088)
* Add Tuya sensor * Add tuya sensor to test4 * Forgot id
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#include "esphome/core/log.h"
|
||||
#include "tuya_sensor.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace tuya {
|
||||
|
||||
static const char *TAG = "tuya.sensor";
|
||||
|
||||
void TuyaSensor::setup() {
|
||||
this->parent_->register_listener(this->sensor_id_, [this](TuyaDatapoint datapoint) {
|
||||
if (datapoint.type == TuyaDatapointType::BOOLEAN) {
|
||||
this->publish_state(datapoint.value_bool);
|
||||
ESP_LOGD(TAG, "MCU reported sensor is: %s", ONOFF(datapoint.value_bool));
|
||||
} else if (datapoint.type == TuyaDatapointType::INTEGER) {
|
||||
this->publish_state(datapoint.value_int);
|
||||
ESP_LOGD(TAG, "MCU reported sensor is: %d", datapoint.value_int);
|
||||
} else if (datapoint.type == TuyaDatapointType::ENUM) {
|
||||
this->publish_state(datapoint.value_enum);
|
||||
ESP_LOGD(TAG, "MCU reported sensor is: %d", datapoint.value_enum);
|
||||
} else if (datapoint.type == TuyaDatapointType::BITMASK) {
|
||||
this->publish_state(datapoint.value_bitmask);
|
||||
ESP_LOGD(TAG, "MCU reported sensor is: %x", datapoint.value_bitmask);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// void TuyaSensor::write_state(bool state) {
|
||||
// TuyaDatapoint datapoint{};
|
||||
// datapoint.id = this->sensor_id_;
|
||||
// datapoint.type = TuyaDatapointType::BOOLEAN;
|
||||
// datapoint.value_bool = state;
|
||||
// this->parent_->set_datapoint_value(datapoint);
|
||||
// ESP_LOGD(TAG, "Setting sensor: %s", ONOFF(state));
|
||||
|
||||
// this->publish_state(state);
|
||||
// }
|
||||
|
||||
void TuyaSensor::dump_config() {
|
||||
LOG_SENSOR("", "Tuya Sensor", this);
|
||||
ESP_LOGCONFIG(TAG, " Sensor has datapoint ID %u", this->sensor_id_);
|
||||
}
|
||||
|
||||
} // namespace tuya
|
||||
} // namespace esphome
|
||||
Reference in New Issue
Block a user