ESPHome 2026.1.4
Loading...
Searching...
No Matches
xiaomi_jqjcy01ym.cpp
Go to the documentation of this file.
1#include "xiaomi_jqjcy01ym.h"
2#include "esphome/core/log.h"
3
4#ifdef USE_ESP32
5
6namespace esphome {
7namespace xiaomi_jqjcy01ym {
8
9static const char *const TAG = "xiaomi_jqjcy01ym";
10
12 ESP_LOGCONFIG(TAG, "Xiaomi JQJCY01YM");
13 LOG_SENSOR(" ", "Temperature", this->temperature_);
14 LOG_SENSOR(" ", "Humidity", this->humidity_);
15 LOG_SENSOR(" ", "Formaldehyde", this->formaldehyde_);
16 LOG_SENSOR(" ", "Battery Level", this->battery_level_);
17}
18
20 if (device.address_uint64() != this->address_) {
21 ESP_LOGVV(TAG, "parse_device(): unknown MAC address.");
22 return false;
23 }
24 char addr_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
25 const char *addr_str = device.address_str_to(addr_buf);
26 ESP_LOGVV(TAG, "parse_device(): MAC address %s found.", addr_str);
27
28 bool success = false;
29 for (auto &service_data : device.get_service_datas()) {
30 auto res = xiaomi_ble::parse_xiaomi_header(service_data);
31 if (!res.has_value()) {
32 continue;
33 }
34 if (res->is_duplicate) {
35 continue;
36 }
37 if (res->has_encryption) {
38 ESP_LOGVV(TAG, "parse_device(): payload decryption is currently not supported on this device.");
39 continue;
40 }
41 if (!(xiaomi_ble::parse_xiaomi_message(service_data.data, *res))) {
42 continue;
43 }
44 if (!(xiaomi_ble::report_xiaomi_results(res, addr_str))) {
45 continue;
46 }
47 if (res->temperature.has_value() && this->temperature_ != nullptr)
48 this->temperature_->publish_state(*res->temperature);
49 if (res->humidity.has_value() && this->humidity_ != nullptr)
50 this->humidity_->publish_state(*res->humidity);
51 if (res->formaldehyde.has_value() && this->formaldehyde_ != nullptr)
52 this->formaldehyde_->publish_state(*res->formaldehyde);
53 if (res->battery_level.has_value() && this->battery_level_ != nullptr)
54 this->battery_level_->publish_state(*res->battery_level);
55 success = true;
56 }
57
58 return success;
59}
60
61} // namespace xiaomi_jqjcy01ym
62} // namespace esphome
63
64#endif
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
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:76
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