ESPHome 2026.6.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
7
8static const char *const TAG = "xiaomi_mue4094rt";
9
11 ESP_LOGCONFIG(TAG, "Xiaomi MUE4094RT");
12 LOG_BINARY_SENSOR(" ", "Motion", this);
13}
14
16 if (device.address_uint64() != this->address_) {
17 ESP_LOGVV(TAG, "parse_device(): unknown MAC address.");
18 return false;
19 }
20 char addr_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
21 const char *addr_str = device.address_str_to(addr_buf);
22 ESP_LOGVV(TAG, "parse_device(): MAC address %s found.", addr_str);
23
24 bool success = false;
25 for (auto &service_data : device.get_service_datas()) {
26 auto res = xiaomi_ble::parse_xiaomi_header(service_data);
27 if (!res.has_value()) {
28 continue;
29 }
30 if (res->is_duplicate) {
31 continue;
32 }
33 if (res->has_encryption) {
34 ESP_LOGVV(TAG, "parse_device(): payload decryption is currently not supported on this device.");
35 continue;
36 }
37 if (!(xiaomi_ble::parse_xiaomi_message(service_data.data, *res))) {
38 continue;
39 }
40 if (!(xiaomi_ble::report_xiaomi_results(res, addr_str))) {
41 continue;
42 }
43 if (res->has_motion.has_value()) {
44 this->publish_state(*res->has_motion);
45 this->set_timeout("motion_timeout", timeout_, [this]() { this->publish_state(false); });
46 }
47 success = true;
48 }
49
50 return success;
51}
52
53} // namespace esphome::xiaomi_mue4094rt
54
55#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:493
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)