8namespace xiaomi_cgpr1 {
10static const char *
const TAG =
"xiaomi_cgpr1";
13 ESP_LOGCONFIG(TAG,
"Xiaomi CGPR1");
14 LOG_BINARY_SENSOR(
" ",
"Motion",
this);
15 LOG_SENSOR(
" ",
"Idle Time", this->
idle_time_);
22 ESP_LOGVV(TAG,
"parse_device(): unknown MAC address.");
25 char addr_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
27 ESP_LOGVV(TAG,
"parse_device(): MAC address %s found.", addr_str);
32 if (!res.has_value()) {
35 if (res->is_duplicate) {
38 if (res->has_encryption &&
49 if (res->idle_time.has_value() && this->idle_time_ !=
nullptr)
51 if (res->battery_level.has_value() && this->battery_level_ !=
nullptr)
53 if (res->illuminance.has_value() && this->illuminance_ !=
nullptr)
55 if (res->has_motion.has_value())
void publish_state(bool new_state)
Publish a new state to the front-end.
uint64_t address_uint64() const
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.
void dump_config() override
sensor::Sensor * illuminance_
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override
void set_bindkey(const char *bindkey)
sensor::Sensor * battery_level_
sensor::Sensor * idle_time_
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 char *address)
Providing packet encoding functions for exchanging data with a remote host.
size_t parse_hex(const char *str, size_t length, uint8_t *data, size_t count)
Parse bytes from a hex-encoded string into a byte array.