ESPHome
2026.5.0
Loading...
Searching...
No Matches
esphome
components
tuya
sensor
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::tuya
{
6
7
static
const
char
*
const
TAG
=
"tuya.sensor"
;
8
9
void
TuyaSensor::setup
() {
10
this->
parent_
->
register_listener
(this->
sensor_id_
, [
this
](
const
TuyaDatapoint
&datapoint) {
11
if
(datapoint.
type
==
TuyaDatapointType::BOOLEAN
) {
12
ESP_LOGV(TAG,
"MCU reported sensor %u is: %s"
, datapoint.
id
, ONOFF(datapoint.
value_bool
));
13
this->
publish_state
(datapoint.
value_bool
);
14
}
else
if
(datapoint.
type
==
TuyaDatapointType::INTEGER
) {
15
ESP_LOGV(TAG,
"MCU reported sensor %u is: %d"
, datapoint.
id
, datapoint.
value_int
);
16
this->
publish_state
(datapoint.
value_int
);
17
}
else
if
(datapoint.
type
==
TuyaDatapointType::ENUM
) {
18
ESP_LOGV(TAG,
"MCU reported sensor %u is: %u"
, datapoint.
id
, datapoint.
value_enum
);
19
this->
publish_state
(datapoint.
value_enum
);
20
}
else
if
(datapoint.
type
==
TuyaDatapointType::BITMASK
) {
21
ESP_LOGV(TAG,
"MCU reported sensor %u is: %"
PRIx32, datapoint.
id
, datapoint.
value_bitmask
);
22
this->
publish_state
(datapoint.
value_bitmask
);
23
}
24
});
25
}
26
27
void
TuyaSensor::dump_config
() {
28
LOG_SENSOR(
""
,
"Tuya Sensor"
,
this
);
29
ESP_LOGCONFIG(TAG,
" Sensor has datapoint ID %u"
, this->
sensor_id_
);
30
}
31
32
}
// namespace esphome::tuya
esphome::sensor::Sensor::publish_state
void publish_state(float state)
Publish a new state to the front-end.
Definition
sensor.cpp:68
esphome::tuya::Tuya::register_listener
void register_listener(uint8_t datapoint_id, const std::function< void(TuyaDatapoint)> &func)
Definition
tuya.cpp:747
esphome::tuya::TuyaSensor::setup
void setup() override
Definition
tuya_sensor.cpp:9
esphome::tuya::TuyaSensor::dump_config
void dump_config() override
Definition
tuya_sensor.cpp:27
esphome::tuya::TuyaSensor::sensor_id_
uint8_t sensor_id_
Definition
tuya_sensor.h:19
esphome::tuya::TuyaSensor::parent_
Tuya * parent_
Definition
tuya_sensor.h:18
log.h
esphome::spi::TAG
const char *const TAG
Definition
spi.cpp:7
esphome::tuya
Definition
automation.cpp:7
esphome::tuya::TuyaDatapointType::BITMASK
@ BITMASK
esphome::tuya::TuyaDatapointType::INTEGER
@ INTEGER
esphome::tuya::TuyaDatapointType::ENUM
@ ENUM
esphome::tuya::TuyaDatapointType::BOOLEAN
@ BOOLEAN
esphome::tuya::TuyaDatapoint
Definition
tuya.h:27
esphome::tuya::TuyaDatapoint::value_enum
uint8_t value_enum
Definition
tuya.h:35
esphome::tuya::TuyaDatapoint::value_int
int value_int
Definition
tuya.h:33
esphome::tuya::TuyaDatapoint::value_bool
bool value_bool
Definition
tuya.h:32
esphome::tuya::TuyaDatapoint::value_bitmask
uint32_t value_bitmask
Definition
tuya.h:36
esphome::tuya::TuyaDatapoint::id
uint8_t id
Definition
tuya.h:28
esphome::tuya::TuyaDatapoint::type
TuyaDatapointType type
Definition
tuya.h:29
tuya_sensor.h
Generated by
1.12.0