7 namespace xiaomi_cgpr1 {
9 static const char *
const TAG =
"xiaomi_cgpr1";
12 ESP_LOGCONFIG(TAG,
"Xiaomi CGPR1");
13 LOG_BINARY_SENSOR(
" ",
"Motion",
this);
14 LOG_SENSOR(
" ",
"Idle Time", this->
idle_time_);
21 ESP_LOGVV(TAG,
"parse_device(): unknown MAC address.");
24 ESP_LOGVV(TAG,
"parse_device(): MAC address %s found.", device.
address_str().c_str());
29 if (!res.has_value()) {
32 if (res->is_duplicate) {
35 if (res->has_encryption &&
46 if (res->idle_time.has_value() && this->
idle_time_ !=
nullptr)
48 if (res->battery_level.has_value() && this->
battery_level_ !=
nullptr)
50 if (res->illuminance.has_value() && this->
illuminance_ !=
nullptr)
52 if (res->has_motion.has_value())
62 if (bindkey.size() != 32) {
66 for (
int i = 0; i < 16; i++) {
67 strncpy(temp, &(bindkey.c_str()[i * 2]), 2);
68 bindkey_[i] = std::strtoul(temp,
nullptr, 16);
sensor::Sensor * illuminance_
void dump_config() override
std::string address_str() const
void set_bindkey(const std::string &bindkey)
bool decrypt_xiaomi_payload(std::vector< uint8_t > &raw, const uint8_t *bindkey, const uint64_t &address)
sensor::Sensor * idle_time_
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
uint64_t address_uint64() const
bool parse_xiaomi_message(const std::vector< uint8_t > &message, XiaomiParseResult &result)
optional< XiaomiParseResult > parse_xiaomi_header(const esp32_ble_tracker::ServiceData &service_data)
bool report_xiaomi_results(const optional< XiaomiParseResult > &result, const std::string &address)
sensor::Sensor * battery_level_
Implementation of SPI Controller mode.
bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override