ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
xiaomi_rtcgq02lm.cpp
Go to the documentation of this file.
1#include "xiaomi_rtcgq02lm.h"
2#include "esphome/core/log.h"
3
5
6ESPHOME_LOG_TAG(TAG, "xiaomi_rtcgq02lm");
7
8static constexpr uint32_t MOTION_TIMEOUT_ID = 0;
9static constexpr uint32_t BUTTON_TIMEOUT_ID = 1;
10
12 ESP_LOGCONFIG(TAG, "Xiaomi RTCGQ02LM");
13 this->dump_bindkey_(TAG);
14#ifdef USE_BINARY_SENSOR
15 LOG_BINARY_SENSOR(" ", "Motion", this->motion_binary_sensor_);
16 LOG_BINARY_SENSOR(" ", "Light", this->light_binary_sensor_);
17 LOG_BINARY_SENSOR(" ", "Button", this->button_binary_sensor_);
18#endif
19#ifdef USE_SENSOR
20 LOG_SENSOR(" ", "Battery Level", this->battery_level_sensor_);
21#endif
22}
23
25#ifdef USE_BINARY_SENSOR
26 if (res.has_motion.has_value() && this->motion_binary_sensor_ != nullptr) {
27 this->motion_binary_sensor_->publish_state(*res.has_motion);
28 this->set_timeout(MOTION_TIMEOUT_ID, this->motion_timeout_,
29 [this]() { this->motion_binary_sensor_->publish_state(false); });
30 }
31 publish_optional(this->light_binary_sensor_, res.is_light);
32 if (res.button_press.has_value() && this->button_binary_sensor_ != nullptr) {
33 this->button_binary_sensor_->publish_state(*res.button_press);
34 this->set_timeout(BUTTON_TIMEOUT_ID, this->button_timeout_,
35 [this]() { this->button_binary_sensor_->publish_state(false); });
36 }
37#endif
38#ifdef USE_SENSOR
39 publish_optional(this->battery_level_sensor_, res.battery_level);
40#endif
41}
42
43} // namespace esphome::xiaomi_rtcgq02lm
virtual void dump_config()
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
Definition component.cpp:96
void dump_bindkey_(const char *tag) const
void publish_result(const xiaomi_ble::XiaomiParseResult &res) override
ESPHOME_LOG_TAG(TAG, "xiaomi_rtcgq02lm")
void publish_optional(E *entity, const optional< V > &value)
Publish value to entity when the entity is configured and the value is set.
static void uint32_t