ESPHome  2024.10.2
automation.cpp
Go to the documentation of this file.
1 #include "esphome/core/log.h"
2 
3 #include "automation.h"
4 
5 static const char *const TAG = "tuya.automation";
6 
7 namespace esphome {
8 namespace tuya {
9 
11  if (dp.type != expected) {
12  ESP_LOGW(TAG, "Tuya sensor %u expected datapoint type %#02hhX but got %#02hhX", dp.id,
13  static_cast<uint8_t>(expected), static_cast<uint8_t>(dp.type));
14  }
15 }
16 
18  parent->register_listener(sensor_id, [this](const TuyaDatapoint &dp) {
20  this->trigger(dp.value_raw);
21  });
22 }
23 
25  parent->register_listener(sensor_id, [this](const TuyaDatapoint &dp) {
27  this->trigger(dp.value_bool);
28  });
29 }
30 
32  parent->register_listener(sensor_id, [this](const TuyaDatapoint &dp) {
34  this->trigger(dp.value_int);
35  });
36 }
37 
39  parent->register_listener(sensor_id, [this](const TuyaDatapoint &dp) {
41  this->trigger(dp.value_uint);
42  });
43 }
44 
46  parent->register_listener(sensor_id, [this](const TuyaDatapoint &dp) {
48  this->trigger(dp.value_string);
49  });
50 }
51 
53  parent->register_listener(sensor_id, [this](const TuyaDatapoint &dp) {
55  this->trigger(dp.value_enum);
56  });
57 }
58 
60  parent->register_listener(sensor_id, [this](const TuyaDatapoint &dp) {
62  this->trigger(dp.value_bitmask);
63  });
64 }
65 
66 } // namespace tuya
67 } // namespace esphome
TuyaDatapointType type
Definition: tuya.h:30
void check_expected_datapoint(const TuyaDatapoint &dp, TuyaDatapointType expected)
Definition: automation.cpp:10
TuyaDatapointType
Definition: tuya.h:19
void register_listener(uint8_t datapoint_id, const std::function< void(TuyaDatapoint)> &func)
Definition: tuya.cpp:697
TuyaBoolDatapointUpdateTrigger(Tuya *parent, uint8_t sensor_id)
Definition: automation.cpp:24
void trigger(Ts... x)
Inform the parent automation that the event has triggered.
Definition: automation.h:95
TuyaBitmaskDatapointUpdateTrigger(Tuya *parent, uint8_t sensor_id)
Definition: automation.cpp:59
const char *const TAG
Definition: spi.cpp:8
TuyaStringDatapointUpdateTrigger(Tuya *parent, uint8_t sensor_id)
Definition: automation.cpp:45
std::string value_string
Definition: tuya.h:39
TuyaUIntDatapointUpdateTrigger(Tuya *parent, uint8_t sensor_id)
Definition: automation.cpp:38
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
TuyaIntDatapointUpdateTrigger(Tuya *parent, uint8_t sensor_id)
Definition: automation.cpp:31
std::vector< uint8_t > value_raw
Definition: tuya.h:40
TuyaEnumDatapointUpdateTrigger(Tuya *parent, uint8_t sensor_id)
Definition: automation.cpp:52
TuyaRawDatapointUpdateTrigger(Tuya *parent, uint8_t sensor_id)
Definition: automation.cpp:17