7 namespace xiaomi_rtcgq02lm {
9 static const char *
const TAG =
"xiaomi_rtcgq02lm";
12 ESP_LOGCONFIG(TAG,
"Xiaomi RTCGQ02LM");
14 #ifdef USE_BINARY_SENSOR 15 LOG_BINARY_SENSOR(
" ",
"Motion", this->
motion_);
16 LOG_BINARY_SENSOR(
" ",
"Light", this->
light_);
17 LOG_BINARY_SENSOR(
" ",
"Button", this->
button_);
26 ESP_LOGVV(TAG,
"parse_device(): unknown MAC address.");
29 ESP_LOGVV(TAG,
"parse_device(): MAC address %s found.", device.
address_str().c_str());
34 if (!res.has_value()) {
37 if (res->is_duplicate) {
40 if (res->has_encryption &&
52 #ifdef USE_BINARY_SENSOR 53 if (res->has_motion.has_value() && this->
motion_ !=
nullptr) {
58 if (res->is_light.has_value() && this->
light_ !=
nullptr)
60 if (res->button_press.has_value() && this->
button_ !=
nullptr) {
67 if (res->battery_level.has_value() && this->
battery_level_ !=
nullptr)
78 if (bindkey.size() != 32) {
82 for (
int i = 0; i < 16; i++) {
83 strncpy(temp, &(bindkey.c_str()[i * 2]), 2);
84 bindkey_[i] = std::strtoul(temp,
nullptr, 16);
std::string format_hex_pretty(const uint8_t *data, size_t length)
Format the byte array data of length len in pretty-printed, human-readable hex.
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
binary_sensor::BinarySensor * motion_
binary_sensor::BinarySensor * button_
std::string address_str() const
bool decrypt_xiaomi_payload(std::vector< uint8_t > &raw, const uint8_t *bindkey, const uint64_t &address)
sensor::Sensor * battery_level_
void publish_state(float state)
Publish a new state to the front-end.
void publish_state(bool state)
Publish a new state to the front-end.
const std::vector< ServiceData > & get_service_datas() const
void set_bindkey(const std::string &bindkey)
void dump_config() override
uint64_t address_uint64() const
bool parse_xiaomi_message(const std::vector< uint8_t > &message, XiaomiParseResult &result)
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override
optional< XiaomiParseResult > parse_xiaomi_header(const esp32_ble_tracker::ServiceData &service_data)
bool report_xiaomi_results(const optional< XiaomiParseResult > &result, const std::string &address)
Implementation of SPI Controller mode.
binary_sensor::BinarySensor * light_