ESPHome 2025.5.0
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 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:72
void publish_state(bool state)
Publish a new state to the front-end.
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 std::string &address)
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7