ESPHome 2026.10.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
5
6static const char *const TAG = "xiaomi_mue4094rt";
7
9 ESP_LOGCONFIG(TAG, "Xiaomi MUE4094RT");
10 LOG_BINARY_SENSOR(" ", "Motion", this);
11}
12
14 if (device.address_uint64() != this->address_) {
15 ESP_LOGVV(TAG, "parse_device(): unknown MAC address.");
16 return false;
17 }
18 char addr_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
19 const char *addr_str = device.address_str_to(addr_buf);
20 ESP_LOGVV(TAG, "parse_device(): MAC address %s found.", addr_str);
21
22 bool success = false;
23 for (auto &service_data : device.get_service_datas()) {
24 auto res = xiaomi_ble::parse_xiaomi_header(service_data);
25 if (!res.has_value()) {
26 continue;
27 }
28 if (res->is_duplicate) {
29 continue;
30 }
31 if (res->has_encryption) {
32 ESP_LOGVV(TAG, "parse_device(): payload decryption is currently not supported on this device.");
33 continue;
34 }
35 if (!(xiaomi_ble::parse_xiaomi_message(service_data.data, *res))) {
36 continue;
37 }
38 if (!(xiaomi_ble::report_xiaomi_results(res, addr_str))) {
39 continue;
40 }
41 if (res->has_motion.has_value()) {
42 this->publish_state(*res->has_motion);
43 this->set_timeout("motion_timeout", timeout_, [this]() { this->publish_state(false); });
44 }
45 success = true;
46 }
47
48 return success;
49}
50
51} // namespace esphome::xiaomi_mue4094rt
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
Definition component.cpp:96
void publish_state(bool new_state)
Publish a new state to the front-end.
ESPDEPRECATED("Use address_str_to() instead. Removed in 2027.2.0.", "2026.8.0") std const char * address_str_to(char *buf) const
Return MAC as "XX:XX:XX:XX:XX:XX" string.
uint64_t address_uint64() const
Return MAC as packed uint64 (byte 0 in LSB — matches esp32's address_uint64).
const std::vector< ServiceData > & get_service_datas() const
Definition ble_device.h:225
bool parse_device(const ble_device_base::ESPBTDevice &device) override
bool parse_xiaomi_message(const std::vector< uint8_t > &message, XiaomiParseResult &result)
optional< XiaomiParseResult > parse_xiaomi_header(const ble_device_base::ServiceData &service_data)
bool report_xiaomi_results(const optional< XiaomiParseResult > &result, const char *address)