18#define TAG (this->log_tag_)
20static constexpr uint32_t SETUP_DELAY_MS = 100;
23static constexpr uint16_t TYPE_CONTROL = 0x0201;
24static constexpr uint16_t TYPE_SET_AREA = 0x0202;
25static constexpr uint16_t TYPE_SET_HOLD_DELAY = 0x0203;
26static constexpr uint16_t TYPE_SET_Z_RANGE = 0x0204;
27static constexpr uint16_t TYPE_SET_LOW_POWER_SLEEP = 0x0205;
29static constexpr uint16_t TYPE_REPORT_TARGET = 0x0A04;
30static constexpr uint16_t TYPE_REPORT_POINT_CLOUD = 0x0A08;
31static constexpr uint16_t TYPE_REPORT_AREA_PRESENCE = 0x0A0A;
32static constexpr uint16_t TYPE_REPORT_INTERFERENCE_AREAS = 0x0A0B;
33static constexpr uint16_t TYPE_REPORT_DETECTION_AREAS = 0x0A0C;
34static constexpr uint16_t TYPE_REPORT_DELAY = 0x0A0D;
35static constexpr uint16_t TYPE_REPORT_SENSITIVITY = 0x0A0E;
36static constexpr uint16_t TYPE_REPORT_TRIGGER = 0x0A0F;
37static constexpr uint16_t TYPE_REPORT_Z_RANGE = 0x0A10;
38static constexpr uint16_t TYPE_REPORT_INSTALLATION = 0x0A11;
39static constexpr uint16_t TYPE_REPORT_MODE = 0x0A12;
40static constexpr uint16_t TYPE_REPORT_LOW_POWER_SLEEP = 0x0A13;
41#if LD600X_AREA_KINDS > 2
42static constexpr uint16_t TYPE_REPORT_DWELL_AREAS = 0x0A16;
44static constexpr uint16_t TYPE_QUERY_VERSION = 0xFFFF;
47static constexpr uint32_t CMD_AUTO_INTERFERENCE = 0x01;
48static constexpr uint32_t CMD_GET_AREAS = 0x02;
49static constexpr uint32_t CMD_CLEAR_INTERFERENCE = 0x03;
50static constexpr uint32_t CMD_RESET_DETECTION_AREA = 0x04;
51static constexpr uint32_t CMD_GET_DELAY = 0x05;
52static constexpr uint32_t CMD_POINT_CLOUD_ON = 0x06;
53static constexpr uint32_t CMD_POINT_CLOUD_OFF = 0x07;
54static constexpr uint32_t CMD_TARGET_DISPLAY_ON = 0x08;
55static constexpr uint32_t CMD_TARGET_DISPLAY_OFF = 0x09;
56static constexpr uint32_t CMD_SENSITIVITY_LOW = 0x0A;
57static constexpr uint32_t CMD_SENSITIVITY_MEDIUM = 0x0B;
58static constexpr uint32_t CMD_SENSITIVITY_HIGH = 0x0C;
59static constexpr uint32_t CMD_GET_SENSITIVITY = 0x0D;
60static constexpr uint32_t CMD_TRIGGER_SLOW = 0x0E;
61static constexpr uint32_t CMD_TRIGGER_MEDIUM = 0x0F;
62static constexpr uint32_t CMD_TRIGGER_FAST = 0x10;
63static constexpr uint32_t CMD_GET_TRIGGER = 0x11;
64static constexpr uint32_t CMD_GET_Z_RANGE = 0x12;
65static constexpr uint32_t CMD_INSTALL_TOP = 0x13;
66static constexpr uint32_t CMD_INSTALL_SIDE = 0x14;
68static_assert(CMD_SENSITIVITY_MEDIUM == CMD_SENSITIVITY_LOW + 1 && CMD_SENSITIVITY_HIGH == CMD_SENSITIVITY_LOW + 2);
69static_assert(CMD_TRIGGER_MEDIUM == CMD_TRIGGER_SLOW + 1 && CMD_TRIGGER_FAST == CMD_TRIGGER_SLOW + 2);
70static_assert(CMD_INSTALL_SIDE == CMD_INSTALL_TOP + 1);
71static constexpr uint32_t CMD_GET_INSTALLATION = 0x15;
73static constexpr uint32_t CMD_LOW_POWER_ON = 0x16;
74static constexpr uint32_t CMD_LOW_POWER_OFF = 0x17;
77static constexpr uint32_t CMD_GET_MODE = 0x18;
78static constexpr uint32_t CMD_GET_LOW_POWER_SLEEP = 0x19;
79static constexpr uint32_t CMD_RESET_UNATTENDED = 0x1A;
81static constexpr uint16_t TARGET_DATA_LEN = 20;
82static constexpr uint16_t AREA_DATA_LEN = 24;
83static constexpr uint16_t AREA_CONFIG_LEN = 28;
84static constexpr uint16_t AREA_PRESENCE_ENTRY_LEN = 4;
86static constexpr uint8_t AREA_ID_DEFAULT = 4;
88static constexpr uint8_t VERSION_QUERY_DATA[] = {0x01, 0x01, 0x00, 0x00};
90#ifdef ESPHOME_LOG_HAS_VERBOSE
93 "reset_detection_area",
"get_delay",
"point_cloud_on",
"point_cloud_off",
"target_display_on",
94 "target_display_off",
"sensitivity_low",
"sensitivity_medium",
"sensitivity_high",
95 "get_sensitivity",
"trigger_slow",
"trigger_medium",
"trigger_fast",
"get_trigger",
"get_z_range",
96 "install_top",
"install_side",
"get_installation",
"low_power_on",
"low_power_off",
"get_mode",
97 "get_low_power_sleep",
"reset_unattended",
"unknown");
98static_assert(CMD_AUTO_INTERFERENCE == 1 && CMD_RESET_UNATTENDED == ControlCommandNames::LAST_INDEX,
99 "ControlCommandNames is indexed by command - 1");
101static const LogString *control_command_name(
uint32_t command) {
103 return ControlCommandNames::get_log_str(command - 1);
106static const LogString *frame_type_name(uint16_t
type) {
109 return LOG_STR(
"control");
111 return LOG_STR(
"set_area");
112 case TYPE_SET_HOLD_DELAY:
113 return LOG_STR(
"set_hold_delay");
114 case TYPE_SET_Z_RANGE:
115 return LOG_STR(
"set_z_range");
116 case TYPE_SET_LOW_POWER_SLEEP:
117 return LOG_STR(
"set_low_power_sleep");
118 case TYPE_REPORT_TARGET:
119 return LOG_STR(
"report_target");
120 case TYPE_REPORT_POINT_CLOUD:
121 return LOG_STR(
"report_point_cloud");
122 case TYPE_REPORT_AREA_PRESENCE:
123 return LOG_STR(
"report_area_presence");
124 case TYPE_REPORT_INTERFERENCE_AREAS:
125 return LOG_STR(
"report_interference_areas");
126 case TYPE_REPORT_DETECTION_AREAS:
127 return LOG_STR(
"report_detection_areas");
128 case TYPE_REPORT_DELAY:
129 return LOG_STR(
"report_delay");
130 case TYPE_REPORT_SENSITIVITY:
131 return LOG_STR(
"report_sensitivity");
132 case TYPE_REPORT_TRIGGER:
133 return LOG_STR(
"report_trigger");
134 case TYPE_REPORT_Z_RANGE:
135 return LOG_STR(
"report_z_range");
136 case TYPE_REPORT_INSTALLATION:
137 return LOG_STR(
"report_installation");
138 case TYPE_REPORT_MODE:
139 return LOG_STR(
"report_mode");
140 case TYPE_REPORT_LOW_POWER_SLEEP:
141 return LOG_STR(
"report_low_power_sleep");
142 case TYPE_QUERY_VERSION:
143 return LOG_STR(
"query_version");
145 return LOG_STR(
"unknown");
149static bool is_expected_control_report(
uint32_t command, uint16_t
type) {
152 return type == TYPE_REPORT_INTERFERENCE_AREAS ||
type == TYPE_REPORT_DETECTION_AREAS;
154 return type == TYPE_REPORT_DELAY;
155 case CMD_GET_SENSITIVITY:
156 return type == TYPE_REPORT_SENSITIVITY;
157 case CMD_GET_TRIGGER:
158 return type == TYPE_REPORT_TRIGGER;
159 case CMD_GET_Z_RANGE:
160 return type == TYPE_REPORT_Z_RANGE;
161 case CMD_GET_INSTALLATION:
162 return type == TYPE_REPORT_INSTALLATION;
163 case CMD_LOW_POWER_ON:
164 case CMD_LOW_POWER_OFF:
166 return type == TYPE_REPORT_MODE;
167 case CMD_GET_LOW_POWER_SLEEP:
168 return type == TYPE_REPORT_LOW_POWER_SLEEP;
180 bool want_target_stream =
false;
182 want_target_stream = want_target_stream || this->target_count_sensor_.has_sensor();
183 if (!want_target_stream) {
184 for (
const auto &target : this->
targets_) {
185 if (target.x !=
nullptr || target.y !=
nullptr || target.z !=
nullptr || target.dop_idx !=
nullptr ||
186 target.cluster_id.has_sensor()) {
187 want_target_stream =
true;
193#ifdef USE_BINARY_SENSOR
194 want_target_stream = want_target_stream || this->presence_binary_sensor_ !=
nullptr;
195 if (!want_target_stream) {
198 want_target_stream =
true;
207 bool target_display_controlled =
false;
209 if (this->target_display_switch_ !=
nullptr) {
210 target_display_controlled =
true;
212 this->target_display_switch_->restore(
true);
215 if (!target_display_controlled) {
220 if (want_target_stream) {
225 bool point_cloud_controlled =
false;
227 if (this->point_cloud_switch_ !=
nullptr) {
228 point_cloud_controlled =
true;
229 this->point_cloud_switch_->restore(
false);
232 if (!point_cloud_controlled) {
235 bool want_point_cloud =
false;
237 want_point_cloud = this->point_count_sensor_.has_sensor();
244 if (this->sensitivity_select_ !=
nullptr) {
247 if (this->trigger_speed_select_ !=
nullptr) {
250 if (this->installation_select_ !=
nullptr) {
255 if (this->z_min_number_ !=
nullptr || this->z_max_number_ !=
nullptr) {
258 if (this->low_power_sleep_number_ !=
nullptr) {
261 if (this->hold_delay_number_ !=
nullptr) {
265 bool want_area_report =
false;
267 for (
const auto &area : this->
areas_) {
269 want_area_report = want_area_report ||
sensor !=
nullptr;
273 if (this->area_x_min_number_ !=
nullptr || this->area_x_max_number_ !=
nullptr ||
274 this->area_y_min_number_ !=
nullptr || this->area_y_max_number_ !=
nullptr ||
275 this->area_z_min_number_ !=
nullptr || this->area_z_max_number_ !=
nullptr) {
276 want_area_report =
true;
279 if (want_area_report) {
286#ifdef USE_TEXT_SENSOR
287 if (this->ota_version_text_sensor_ !=
nullptr) {
288 this->
queue_command_(TYPE_QUERY_VERSION, VERSION_QUERY_DATA,
sizeof(VERSION_QUERY_DATA));
297 char model[16] =
"HLK-";
299 for (
const auto *p =
reinterpret_cast<const uint8_t *
>(this->
log_tag_); pos <
sizeof(model) - 1; p++) {
303 model[
pos++] =
static_cast<char>(std::toupper(c));
308 " Max data length: %u",
311 LOG_SENSOR_WITH_DEDUP(
" ",
"Target Count", this->target_count_sensor_);
312 LOG_SENSOR_WITH_DEDUP(
" ",
"Point Count", this->point_count_sensor_);
313 for (
auto &target : this->
targets_) {
314 LOG_SENSOR(
" ",
"Target X", target.x);
315 LOG_SENSOR(
" ",
"Target Y", target.y);
316 LOG_SENSOR(
" ",
"Target Z", target.z);
317 LOG_SENSOR(
" ",
"Target Doppler Index", target.dop_idx);
318 LOG_SENSOR_WITH_DEDUP(
" ",
"Target Cluster ID", target.cluster_id);
320 for (uint8_t i = 0; i < AREA_COUNT; i++) {
329 for (uint8_t i = 0; i < AREA_COUNT; i++) {
338#if LD600X_AREA_KINDS > 2
339 for (uint8_t i = 0; i < AREA_COUNT; i++) {
350#ifdef USE_BINARY_SENSOR
351 LOG_BINARY_SENSOR(
" ",
"Presence", this->presence_binary_sensor_);
352 for (uint8_t i = 0; i < LD600X_MAX_TARGETS; i++) {
355 for (uint8_t i = 0; i < AREA_COUNT; i++) {
356 LOG_BINARY_SENSOR(
" ",
"Detection Area Presence", this->
area_presence_[i]);
359#ifdef USE_TEXT_SENSOR
360 LOG_TEXT_SENSOR(
" ",
"Work Mode", this->work_mode_text_sensor_);
361 LOG_TEXT_SENSOR(
" ",
"OTA Version", this->ota_version_text_sensor_);
364 LOG_NUMBER(
" ",
"Hold Delay", this->hold_delay_number_);
365 LOG_NUMBER(
" ",
"Z Min", this->z_min_number_);
366 LOG_NUMBER(
" ",
"Z Max", this->z_max_number_);
367 LOG_NUMBER(
" ",
"Low Power Sleep", this->low_power_sleep_number_);
368 LOG_NUMBER(
" ",
"Area X Min", this->area_x_min_number_);
369 LOG_NUMBER(
" ",
"Area X Max", this->area_x_max_number_);
370 LOG_NUMBER(
" ",
"Area Y Min", this->area_y_min_number_);
371 LOG_NUMBER(
" ",
"Area Y Max", this->area_y_max_number_);
372 LOG_NUMBER(
" ",
"Area Z Min", this->area_z_min_number_);
373 LOG_NUMBER(
" ",
"Area Z Max", this->area_z_max_number_);
376 LOG_SWITCH(
" ",
"Point Cloud", this->point_cloud_switch_);
377 LOG_SWITCH(
" ",
"Target Display", this->target_display_switch_);
380 LOG_SELECT(
" ",
"Sensitivity", this->sensitivity_select_);
381 LOG_SELECT(
" ",
"Trigger Speed", this->trigger_speed_select_);
382 LOG_SELECT(
" ",
"Installation Mode", this->installation_select_);
383 LOG_SELECT(
" ",
"Area ID", this->area_id_select_);
406 ESP_LOGV(TAG,
"Ignoring ACK for command 0x%04X from an earlier attempt (module frame 0x%04X)",
type,
411 ESP_LOGV(TAG,
"ACK for command 0x%04X (module frame 0x%04X)",
type, this->
parser_.
id());
429#ifdef ESPHOME_LOG_HAS_VERBOSE
430 const uint32_t active_control_command =
434 if (active_control_command != 0 && is_expected_control_report(active_control_command,
type)) {
435 ESP_LOGV(TAG,
"Received %s (0x%04X) while waiting for %s (0x%02" PRIX32
") ACK", LOG_STR_ARG(frame_type_name(
type)),
436 type, LOG_STR_ARG(control_command_name(active_control_command)), active_control_command);
444 case TYPE_REPORT_TARGET:
447 case TYPE_REPORT_POINT_CLOUD:
450 case TYPE_REPORT_AREA_PRESENCE:
453 case TYPE_REPORT_INTERFERENCE_AREAS:
456 case TYPE_REPORT_DETECTION_AREAS:
459#if LD600X_AREA_KINDS > 2
460 case TYPE_REPORT_DWELL_AREAS:
464 case TYPE_REPORT_DELAY:
467 case TYPE_REPORT_SENSITIVITY:
470 case TYPE_REPORT_TRIGGER:
473 case TYPE_REPORT_Z_RANGE:
476 case TYPE_REPORT_INSTALLATION:
479 case TYPE_REPORT_LOW_POWER_SLEEP:
482 case TYPE_QUERY_VERSION:
504 uint8_t
count =
static_cast<uint8_t
>(std::min<uint32_t>(reported, LD600X_MAX_TARGETS));
507 std::array<int32_t, LD600X_MAX_TARGETS> wire_cluster{};
508 std::array<bool, LD600X_MAX_TARGETS> wire_placed{};
509 std::array<bool, LD600X_MAX_TARGETS> slot_seen{};
510 std::array<uint8_t, LD600X_MAX_TARGETS> slot_wire{};
511 for (uint8_t i = 0; i <
count; i++) {
512 uint16_t cluster_offset = 4 + (i * TARGET_DATA_LEN) + 16;
515 for (uint8_t i = 0; i <
count; i++) {
516 for (uint8_t s = 0; s < LD600X_MAX_TARGETS; s++) {
519 wire_placed[i] =
true;
525 for (uint8_t s = 0; s < LD600X_MAX_TARGETS; s++) {
530 for (uint8_t i = 0; i <
count; i++) {
531 if (wire_placed[i]) {
534 for (uint8_t s = 0; s < LD600X_MAX_TARGETS; s++) {
545 this->target_count_sensor_.publish_state_if_not_dup(reported);
549#ifdef USE_BINARY_SENSOR
551 PUBLISH_STATE(this->presence_binary_sensor_, presence);
555 for (uint8_t i = 0; i < LD600X_MAX_TARGETS; i++) {
559 uint16_t offset = 4 + (slot_wire[i] * TARGET_DATA_LEN);
566 PUBLISH_STATE(target.
x,
x);
567 PUBLISH_STATE(target.
y,
y);
568 PUBLISH_STATE(target.
z,
z);
569 PUBLISH_STATE(target.
dop_idx,
static_cast<float>(dop_idx));
577#ifdef USE_BINARY_SENSOR
606 const uint16_t needed = AREA_COUNT * AREA_PRESENCE_ENTRY_LEN;
611 for (uint8_t i = 0; i < AREA_COUNT; i++) {
613 bool present =
state != 0;
615#ifdef USE_BINARY_SENSOR
620#ifdef USE_BINARY_SENSOR
622 PUBLISH_STATE(this->presence_binary_sensor_, presence);
628 uint16_t needed = AREA_COUNT * AREA_DATA_LEN;
632 for (uint8_t i = 0; i < AREA_COUNT; i++) {
633 uint16_t offset = i * AREA_DATA_LEN;
643 const float values[
AREA_AXIS_COUNT] = {x_min, x_max, y_min, y_max, z_min, z_max};
645 PUBLISH_STATE(area[axis], values[axis]);
657 if (selected_id == area_index(kind, i)) {
677 if (this->sensitivity_select_ ==
nullptr)
679 uint8_t
value = data[0];
681 this->sensitivity_select_->publish_state(
value);
690 if (this->trigger_speed_select_ ==
nullptr)
692 uint8_t
value = data[0];
694 this->trigger_speed_select_->publish_state(
value);
716 if (this->installation_select_ ==
nullptr)
718 uint8_t
value = data[0];
720 this->installation_select_->publish_state(
value);
736 if (number ==
nullptr)
738 if (std::isnan(
value)) {
753 ESP_LOGW(TAG,
"'%s': module reported %.1f, clamped to %.1f..%.1f", LOG_STR_ARG(number->
get_log_name()),
value,
754 min_value, max_value);
755 value = std::clamp(
value, min_value, max_value);
764#ifdef USE_TEXT_SENSOR
765 if (this->ota_version_text_sensor_ ==
nullptr)
767 uint8_t project = data[0];
768 uint8_t major = data[1];
769 uint8_t minor = data[2];
770 uint8_t patch = data[3];
773 std::snprintf(buf,
sizeof(buf),
"%u.%u.%u", major, minor, patch);
775 std::snprintf(buf,
sizeof(buf),
"p%u %u.%u.%u", project, major, minor, patch);
777 this->ota_version_text_sensor_->publish_state(buf);
783 if (
len > CMD_MAX_DATA_LEN) {
784 ESP_LOGW(TAG,
"Command data too large: %u",
len);
788 ESP_LOGW(TAG,
"Command queue full, dropping command 0x%04X",
type);
795 if (
len > 0 && data !=
nullptr) {
796 std::memcpy(cmd.
data.data(), data,
len);
810 const uint32_t active_control_command =
815#ifdef ESPHOME_LOG_HAS_VERBOSE
816 if (active_control_command != 0) {
817 ESP_LOGV(TAG,
"Retrying %s (0x%02" PRIX32
"), %u attempt(s) remaining",
818 LOG_STR_ARG(control_command_name(active_control_command)), active_control_command,
822 ESP_LOGV(TAG,
"Retrying command 0x%04X, %u attempt(s) remaining", this->
active_command_.
type,
823 this->retries_left_);
831 if (active_control_command != 0) {
832 ESP_LOGW(TAG,
"Command 0x%04X subcommand 0x%02" PRIX32
" timed out", this->
active_command_.
type,
833 active_control_command);
847 ESP_LOGW(TAG,
"Area read timed out, dropping deferred area apply");
856 this->
stale_ack_count_ =
static_cast<uint8_t
>(std::min<uint16_t>(owed, 255));
891 if (
len > CMD_MAX_DATA_LEN) {
892 ESP_LOGW(TAG,
"Command data too large: %u",
len);
910 uint8_t frame[TF_FRAME_OVERHEAD + CMD_MAX_DATA_LEN];
934 if (std::isnan(z_min) || std::isnan(z_max)) {
935 ESP_LOGW(TAG,
"Z range not written, other bound unknown");
940 ESP_LOGW(TAG,
"Z range not written, min above max");
946 return this->
queue_command_(TYPE_SET_Z_RANGE, data,
sizeof(data));
954 ESP_LOGW(TAG,
"Invalid number value: %f",
value);
965 ESP_LOGW(TAG,
"Area ID not selected; ignoring apply");
968 if (this->
area_id_ >= AREA_ID_COUNT) {
969 ESP_LOGW(TAG,
"Invalid area id: %u", this->
area_id_);
987 if (std::isnan(desired.
x_min) || std::isnan(desired.
x_max) || std::isnan(desired.
y_min) ||
988 std::isnan(desired.
y_max) || std::isnan(desired.
z_min) || std::isnan(desired.
z_max)) {
992 ESP_LOGW(TAG,
"Area read not queued; area config left unapplied");
1010 ESP_LOGI(TAG,
"Area config incomplete; requesting current areas before applying");
1022 if (entity == this->hold_delay_number_)
1024 if (entity == this->low_power_sleep_number_)
1027 if (entity == this->z_min_number_ || entity == this->z_max_number_) {
1028 const bool is_min = entity == this->z_min_number_;
1029 const float z_min = is_min ?
value : this->
z_min_;
1030 const float z_max = is_min ? this->
z_max_ :
value;
1037 if (entity == this->area_x_min_number_) {
1040 }
else if (entity == this->area_x_max_number_) {
1043 }
else if (entity == this->area_y_min_number_) {
1046 }
else if (entity == this->area_y_max_number_) {
1049 }
else if (entity == this->area_z_min_number_) {
1062 if (entity == this->sensitivity_select_)
1064 if (entity == this->trigger_speed_select_)
1066 if (entity == this->installation_select_)
1069 this->
area_id_ =
static_cast<uint8_t
>(index);
1082 if (std::isnan(edits.
x_min))
1084 if (std::isnan(edits.
x_max))
1086 if (std::isnan(edits.
y_min))
1088 if (std::isnan(edits.
y_max))
1090 if (std::isnan(edits.
z_min))
1092 if (std::isnan(edits.
z_max))
1111 if (area_id >= AREA_ID_COUNT)
1126 ESP_LOGW(TAG,
"Area %u not written, min above max", area_id);
1129 uint8_t data[AREA_CONFIG_LEN];
1152 if (area_id == selected_id) {
1182 if (std::isnan(desired.
x_min) || std::isnan(desired.
x_max) || std::isnan(desired.
y_min) ||
1183 std::isnan(desired.
y_max) || std::isnan(desired.
z_min) || std::isnan(desired.
z_max)) {
1187 if (reported_kind == kind) {
1190 ESP_LOGW(TAG,
"Dropping deferred area apply, area report incomplete");
1206 if (this->area_id_select_ ==
nullptr) {
1209 this->
area_id_pref_ = this->area_id_select_->make_entity_preference<uint8_t>();
1217 value = AREA_ID_DEFAULT;
1219 this->area_id_select_->publish_state(
value);
1236#ifdef USE_TEXT_SENSOR
1237 if (this->ota_version_text_sensor_ ==
nullptr) {
1245 pref.value[
sizeof(pref.value) - 1] =
'\0';
1246 this->ota_version_text_sensor_->publish_state(pref.value);
1252#ifdef USE_TEXT_SENSOR
1257 std::strncpy(pref.value,
value,
sizeof(pref.value) - 1);
1258 pref.value[
sizeof(pref.value) - 1] =
'\0';
1269 PUBLISH_STATE(target.
x, NAN);
1270 PUBLISH_STATE(target.
y, NAN);
1271 PUBLISH_STATE(target.
z, NAN);
1272 PUBLISH_STATE(target.
dop_idx, NAN);
1333#ifdef USE_BINARY_SENSOR
1334 for (uint8_t i = 0; i < AREA_COUNT; i++) {
1338 PUBLISH_STATE(this->presence_binary_sensor_, presence);
1348 for (uint8_t i = 0; i < LD600X_MAX_TARGETS; i++) {
1355#ifdef USE_BINARY_SENSOR
1361 this->target_count_sensor_.publish_state_unknown();
1365#ifdef USE_BINARY_SENSOR
1367 PUBLISH_STATE(this->presence_binary_sensor_, presence);
1375 if (entity == this->point_cloud_switch_) {
1384 this->point_count_sensor_.publish_state_unknown();
1448 ESP_LOGW(TAG,
"Unknown %s kind %u", LOG_STR_LITERAL(
"button"), kind);
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
bool ESPHOME_ALWAYS_INLINE setup_check(bool ok)
Marks the component failed with message (default "Communication failed") unless ok; returns ok.
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
uint16_t capacity() const
static constexpr uint8_t CMD_MAX_RETRIES
void init_area_id_pref_()
bool queue_u32_setting_(uint16_t type, float value)
bool version_pref_initialized_
void restore_deferred_edits_()
PendingCommand active_command_
void dump_config() override
static constexpr uint32_t CMD_ACK_TIMEOUT_MS
void update_area_numbers_for_id_(uint8_t area_id)
void clear_target_state_()
std::array< AreaConfig, AREA_COUNT *LD600X_AREA_KINDS > area_values_
bool queue_area_config_(uint8_t area_id, const AreaConfig &desired)
std::array< int32_t, LD600X_MAX_TARGETS > slot_cluster_
bool send_z_range_(float z_min, float z_max)
void handle_sensitivity_report_(const uint8_t *data, uint16_t len)
void handle_z_range_report_(const uint8_t *data, uint16_t len)
virtual bool set_switch_state(switch_::Switch *entity, bool state)
AreaConfig pending_area_updates_
void write_frame_(uint16_t type, const uint8_t *data, uint8_t len, bool track)
virtual void press_button(uint8_t kind)
void handle_low_power_sleep_report_(const uint8_t *data, uint16_t len)
bool point_cloud_enabled_
virtual bool model_wants_target_stream() const
uint32_t last_traffic_ms_
bool target_display_enabled_
static constexpr uint32_t AREA_REFRESH_TIMEOUT_ID
std::array< bool, LD600X_MAX_TARGETS > slot_occupied_
void handle_trigger_speed_report_(const uint8_t *data, uint16_t len)
std::array< bool, LD600X_MAX_TARGETS > last_target_presence_
std::array< AreaSensors, AREA_COUNT *LD600X_AREA_KINDS > areas_
virtual bool defer_frame_write(uint16_t type, const uint8_t *data, uint8_t len, bool track)
void clear_area_presence_()
void clear_target_slot_(uint8_t index)
bool queue_command_(uint16_t type, const uint8_t *data, uint8_t len)
bool deferred_apply_pending_
bool area_id_pref_initialized_
void handle_area_presence_(const uint8_t *data, uint16_t len)
static constexpr uint32_t STALE_ACK_MAX_AGE_MS
void update_area_numbers_(const AreaConfig &area)
void handle_target_report_(const uint8_t *data, uint16_t len)
void process_command_queue_()
void try_apply_pending_area_(uint8_t reported_kind)
bool target_presence_any_
void handle_version_report_(const uint8_t *data, uint16_t len)
void handle_point_cloud_(const uint8_t *data, uint16_t len)
void publish_number_clamped_(number::Number *number, float value)
void publish_area_numbers_()
virtual bool handle_model_report(uint16_t type, const uint8_t *data, uint16_t len)
StaticRingBuffer< PendingCommand, CMD_QUEUE_SIZE > cmd_queue_
binary_sensor::BinarySensor * sensor
std::array< binary_sensor::BinarySensor *, AREA_COUNT > area_presence_
void handle_installation_report_(const uint8_t *data, uint16_t len)
virtual void on_presence_update()
std::array< TargetSensors, LD600X_MAX_TARGETS > targets_
this target_presence_[target]
void handle_area_report_(uint8_t kind, const uint8_t *data, uint16_t len)
static constexpr uint32_t CMD_FIRST_ACK_TIMEOUT_MS
void handle_frame_(uint16_t type, const uint8_t *data, uint16_t len)
virtual void dump_model_config()
ESPPreferenceObject version_pref_
void apply_area_config_()
ESPPreferenceObject area_id_pref_
void send_command_internal_(uint16_t type, const uint8_t *data, uint8_t len, bool track)
void init_version_pref_()
bool send_control_command_(uint32_t command)
virtual SUB_TEXT_SENSOR(work_mode) SUB_TEXT_SENSOR(ota_version) SUB_NUMBER(hold_delay) SUB_NUMBER(z_min) SUB_NUMBER(z_max) SUB_NUMBER(low_power_sleep) SUB_NUMBER(area_x_min) SUB_NUMBER(area_x_max) SUB_NUMBER(area_y_min) SUB_NUMBER(area_y_max) SUB_NUMBER(area_z_min) SUB_NUMBER(area_z_max) SUB_SELECT(sensitivity) SUB_SELECT(trigger_speed) SUB_SELECT(installation) SUB_SELECT(area_id) SUB_SWITCH(point_cloud) SUB_SWITCH(target_display) virtual bool set_number_value(number bool set_select_value(select::Select *entity, size_t index)
static constexpr uint8_t CMD_QUEUE_SIZE
void handle_delay_report_(const uint8_t *data, uint16_t len)
bool area_write_in_flight_
virtual void setup_model()
static constexpr uint32_t MODULE_AWAKE_MS
void save_version_pref_(const char *value)
void send_command_(uint16_t type, const uint8_t *data, uint8_t len)
void save_area_id_pref_(uint8_t value)
Base-class for all numbers.
void publish_state(float state)
float get_min_value() const
float get_max_value() const
Base-class for all selects.
void publish_state_unknown()
void publish_state_if_not_dup(T state)
Base class for all switches.
bool read_available(F &&on_byte)
Same as read_available_chunks(), calling on_byte(uint8_t) once per byte.
void write_array(const uint8_t *data, size_t len)
uint16_t next_frame_id(uint16_t &counter)
void write_f32_le(uint8_t *data, float value)
PROGMEM_STRING_TABLE(ControlCommandNames, "auto_interference", "get_areas", "clear_interference", "reset_detection_area", "get_delay", "point_cloud_on", "point_cloud_off", "target_display_on", "target_display_off", "sensitivity_low", "sensitivity_medium", "sensitivity_high", "get_sensitivity", "trigger_slow", "trigger_medium", "trigger_fast", "get_trigger", "get_z_range", "install_top", "install_side", "get_installation", "low_power_on", "low_power_off", "get_mode", "get_low_power_sleep", "reset_unattended", "unknown")
@ BUTTON_GET_LOW_POWER_MODE
@ BUTTON_CLEAR_INTERFERENCE
@ BUTTON_GET_TRIGGER_SPEED
@ BUTTON_AUTO_INTERFERENCE
@ BUTTON_GET_LOW_POWER_SLEEP_TIME
@ BUTTON_RESET_UNATTENDED
@ BUTTON_RESET_DETECTION_AREA
@ BUTTON_GET_INSTALLATION
std::array< sensor::Sensor *, AREA_AXIS_COUNT > AreaSensors
float read_f32_le(const uint8_t *data)
size_t encode_frame(uint16_t frame_id, uint16_t type, const uint8_t *data, uint16_t len, uint8_t *out)
constexpr T encode_value_le(const uint8_t *bytes)
Encode a value from its constituent bytes (from least to most significant) in an array with length si...
constexpr uint8_t * put_le32(uint8_t *dst, uint32_t value)
void HOT delay(uint32_t ms)
Application App
Global storage of Application pointer - only one Application can exist.
uint8_t progmem_read_byte(const uint8_t *addr)
std::array< uint8_t, CMD_MAX_DATA_LEN > data
sensor::SensorWithDedup< int32_t > cluster_id