ESPHome 2026.10.0-dev
Loading...
Searching...
No Matches
xiaomi_hhccpot002.cpp
Go to the documentation of this file.
1#include "xiaomi_hhccpot002.h"
2#include "esphome/core/log.h"
3
5
6static const char *const TAG = "xiaomi_hhccpot002";
7
8void XiaomiHHCCPOT002 ::dump_config() {
9 ESP_LOGCONFIG(TAG, "Xiaomi HHCCPOT002");
10 LOG_SENSOR(" ", "Moisture", this->moisture_);
11 LOG_SENSOR(" ", "Conductivity", this->conductivity_);
12}
13
15 if (device.address_uint64() != this->address_) {
16 ESP_LOGVV(TAG, "parse_device(): unknown MAC address.");
17 return false;
18 }
19 char addr_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
20 const char *addr_str = device.address_str_to(addr_buf);
21 ESP_LOGVV(TAG, "parse_device(): MAC address %s found.", addr_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, addr_str))) {
40 continue;
41 }
42 if (res->moisture.has_value() && this->moisture_ != nullptr)
43 this->moisture_->publish_state(*res->moisture);
44 if (res->conductivity.has_value() && this->conductivity_ != nullptr)
45 this->conductivity_->publish_state(*res->conductivity);
46 success = true;
47 }
48
49 return success;
50}
51
52} // namespace esphome::xiaomi_hhccpot002
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
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:68
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)