8namespace xiaomi_rtcgq02lm {
10static const char *
const TAG =
"xiaomi_rtcgq02lm";
12static constexpr size_t RTCGQ02LM_BINDKEY_SIZE = 16;
16 ESP_LOGCONFIG(TAG,
"Xiaomi RTCGQ02LM");
18#ifdef USE_BINARY_SENSOR
19 LOG_BINARY_SENSOR(
" ",
"Motion", this->
motion_);
20 LOG_BINARY_SENSOR(
" ",
"Light", this->
light_);
21 LOG_BINARY_SENSOR(
" ",
"Button", this->
button_);
30 ESP_LOGVV(TAG,
"parse_device(): unknown MAC address.");
33 ESP_LOGVV(TAG,
"parse_device(): MAC address %s found.", device.
address_str().c_str());
38 if (!res.has_value()) {
41 if (res->is_duplicate) {
44 if (res->has_encryption &&
56#ifdef USE_BINARY_SENSOR
57 if (res->has_motion.has_value() && this->motion_ !=
nullptr) {
62 if (res->is_light.has_value() && this->light_ !=
nullptr)
64 if (res->button_press.has_value() && this->button_ !=
nullptr) {
71 if (res->battery_level.has_value() && this->battery_level_ !=
nullptr)
82 if (bindkey.size() != 32) {
86 for (
int i = 0; i < 16; i++) {
87 strncpy(temp, &(bindkey.c_str()[i * 2]), 2);
88 bindkey_[i] = std::strtoul(temp,
nullptr, 16);
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
void publish_state(bool new_state)
Publish a new state to the front-end.
uint64_t address_uint64() const
const std::vector< ServiceData > & get_service_datas() const
std::string address_str() const
void publish_state(float state)
Publish a new state to the front-end.
void dump_config() override
sensor::Sensor * battery_level_
binary_sensor::BinarySensor * motion_
binary_sensor::BinarySensor * button_
void set_bindkey(const std::string &bindkey)
binary_sensor::BinarySensor * light_
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override
bool decrypt_xiaomi_payload(std::vector< uint8_t > &raw, const uint8_t *bindkey, const uint64_t &address)
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.
char * format_hex_pretty_to(char *buffer, size_t buffer_size, const uint8_t *data, size_t length, char separator)
Format byte array as uppercase hex to buffer (base implementation).
constexpr size_t format_hex_pretty_size(size_t byte_count)
Calculate buffer size needed for format_hex_pretty_to with separator: "XX:XX:...:XX\0".