ESPHome  2024.12.2
tuya_binary_sensor.cpp
Go to the documentation of this file.
1 #include "esphome/core/log.h"
2 #include "tuya_binary_sensor.h"
3 
4 namespace esphome {
5 namespace tuya {
6 
7 static const char *const TAG = "tuya.binary_sensor";
8 
10  this->parent_->register_listener(this->sensor_id_, [this](const TuyaDatapoint &datapoint) {
11  ESP_LOGV(TAG, "MCU reported binary sensor %u is: %s", datapoint.id, ONOFF(datapoint.value_bool));
12  this->publish_state(datapoint.value_bool);
13  });
14 }
15 
17  ESP_LOGCONFIG(TAG, "Tuya Binary Sensor:");
18  ESP_LOGCONFIG(TAG, " Binary Sensor has datapoint ID %u", this->sensor_id_);
19 }
20 
21 } // namespace tuya
22 } // namespace esphome
void register_listener(uint8_t datapoint_id, const std::function< void(TuyaDatapoint)> &func)
Definition: tuya.cpp:697
const char *const TAG
Definition: spi.cpp:8
void publish_state(bool state)
Publish a new state to the front-end.
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7