ESPHome 2026.3.0-dev
Loading...
Searching...
No Matches
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
6namespace esphome {
7namespace xiaomi_mue4094rt {
8
9static 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 char addr_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
22 const char *addr_str = device.address_str_to(addr_buf);
23 ESP_LOGVV(TAG, "parse_device(): MAC address %s found.", addr_str);
24
25 bool success = false;
26 for (auto &service_data : device.get_service_datas()) {
27 auto res = xiaomi_ble::parse_xiaomi_header(service_data);
28 if (!res.has_value()) {
29 continue;
30 }
31 if (res->is_duplicate) {
32 continue;
33 }
34 if (res->has_encryption) {
35 ESP_LOGVV(TAG, "parse_device(): payload decryption is currently not supported on this device.");
36 continue;
37 }
38 if (!(xiaomi_ble::parse_xiaomi_message(service_data.data, *res))) {
39 continue;
40 }
41 if (!(xiaomi_ble::report_xiaomi_results(res, addr_str))) {
42 continue;
43 }
44 if (res->has_motion.has_value()) {
45 this->publish_state(*res->has_motion);
46 this->set_timeout("motion_timeout", timeout_, [this]() { this->publish_state(false); });
47 }
48 success = true;
49 }
50
51 return success;
52}
53
54} // namespace xiaomi_mue4094rt
55} // namespace esphome
56
57#endif
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_timeout(const std voi set_timeout)(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
Definition component.h:443
void publish_state(bool new_state)
Publish a new state to the front-end.
const char * address_str_to(std::span< char, MAC_ADDRESS_PRETTY_BUFFER_SIZE > buf) const
Format MAC address into provided buffer, returns pointer to buffer for convenience.
const std::vector< ServiceData > & get_service_datas() const
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override
optional< XiaomiParseResult > parse_xiaomi_header(const esp32_ble_tracker::ServiceData &service_data)
bool parse_xiaomi_message(const std::vector< uint8_t > &message, XiaomiParseResult &result)
bool report_xiaomi_results(const optional< XiaomiParseResult > &result, const char *address)
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7