ESPHome  2024.4.0
xiaomi_mue4094rt.cpp
Go to the documentation of this file.
1 #include "xiaomi_mue4094rt.h"
2 #include "esphome/core/log.h"
3 
4 #ifdef USE_ESP32
5 
6 namespace esphome {
7 namespace xiaomi_mue4094rt {
8 
9 static const char *const TAG = "xiaomi_mue4094rt";
10 
12  ESP_LOGCONFIG(TAG, "Xiaomi MUE4094RT");
13  LOG_BINARY_SENSOR(" ", "Motion", this);
14 }
15 
17  if (device.address_uint64() != this->address_) {
18  ESP_LOGVV(TAG, "parse_device(): unknown MAC address.");
19  return false;
20  }
21  ESP_LOGVV(TAG, "parse_device(): MAC address %s found.", device.address_str().c_str());
22 
23  bool success = false;
24  for (auto &service_data : device.get_service_datas()) {
25  auto res = xiaomi_ble::parse_xiaomi_header(service_data);
26  if (!res.has_value()) {
27  continue;
28  }
29  if (res->is_duplicate) {
30  continue;
31  }
32  if (res->has_encryption) {
33  ESP_LOGVV(TAG, "parse_device(): payload decryption is currently not supported on this device.");
34  continue;
35  }
36  if (!(xiaomi_ble::parse_xiaomi_message(service_data.data, *res))) {
37  continue;
38  }
39  if (!(xiaomi_ble::report_xiaomi_results(res, device.address_str()))) {
40  continue;
41  }
42  if (res->has_motion.has_value()) {
43  this->publish_state(*res->has_motion);
44  this->set_timeout("motion_timeout", timeout_, [this]() { this->publish_state(false); });
45  }
46  success = true;
47  }
48 
49  return success;
50 }
51 
52 } // namespace xiaomi_mue4094rt
53 } // namespace esphome
54 
55 #endif
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
Definition: component.cpp:69
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override
void publish_state(bool state)
Publish a new state to the front-end.
const std::vector< ServiceData > & get_service_datas() const
bool parse_xiaomi_message(const std::vector< uint8_t > &message, XiaomiParseResult &result)
Definition: xiaomi_ble.cpp:90
optional< XiaomiParseResult > parse_xiaomi_header(const esp32_ble_tracker::ServiceData &service_data)
Definition: xiaomi_ble.cpp:138
bool report_xiaomi_results(const optional< XiaomiParseResult > &result, const std::string &address)
Definition: xiaomi_ble.cpp:322
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7