ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
xiaomi_cgpr1.cpp
Go to the documentation of this file.
1#include "xiaomi_cgpr1.h"
2#include "esphome/core/log.h"
3
5
6ESPHOME_LOG_TAG(TAG, "xiaomi_cgpr1");
7
9 ESP_LOGCONFIG(TAG, "Xiaomi CGPR1");
10 this->dump_bindkey_(TAG);
11 LOG_BINARY_SENSOR(" ", "Motion", this);
12 LOG_SENSOR(" ", "Idle Time", this->idle_time_sensor_);
13 LOG_SENSOR(" ", "Battery Level", this->battery_level_sensor_);
14 LOG_SENSOR(" ", "Illuminance", this->illuminance_sensor_);
15}
16
18 publish_optional(this->idle_time_sensor_, res.idle_time);
19 publish_optional(this->battery_level_sensor_, res.battery_level);
20 publish_optional(this->illuminance_sensor_, res.illuminance);
21 if (res.has_motion.has_value())
22 this->publish_state(*res.has_motion);
23}
24
25} // namespace esphome::xiaomi_cgpr1
virtual void dump_config()
void publish_state(bool new_state)
Publish a new state to the front-end.
void dump_bindkey_(const char *tag) const
void publish_result(const xiaomi_ble::XiaomiParseResult &res) override
ESPHOME_LOG_TAG(TAG, "xiaomi_cgpr1")
void publish_optional(E *entity, const optional< V > &value)
Publish value to entity when the entity is configured and the value is set.