ESPHome 2026.8.0b4
Loading...
Searching...
No Matches
zigbee_attribute_esp32.cpp
Go to the documentation of this file.
2#include "esphome/core/log.h"
4#ifdef USE_ESP32
5#ifdef USE_ZIGBEE
6
7namespace esphome::zigbee {
8
9static const char *const TAG = "zigbee.attribute";
10
12 if (!this->zb_->is_started()) {
13 return;
14 }
15 if (esp_zigbee_lock_acquire(10 / portTICK_PERIOD_MS)) {
16 ezb_zcl_status_t state = ezb_zcl_set_attr_value(this->endpoint_id_, this->cluster_id_, this->role_, this->attr_id_,
17 EZB_ZCL_STD_MANUF_CODE, this->value_p_, false);
18 // cleared before report_() so it can disable the loop
19 // when the report has to wait for join
20 this->set_attr_requested_ = false;
21 if (this->force_report_) {
22 this->report_(true);
23 }
24 // Check for error
25 if (state != EZB_ZCL_STATUS_SUCCESS) {
26 ESP_LOGE(TAG, "Setting attribute failed, ZCL status: %u", static_cast<unsigned>(state));
27 }
28 esp_zigbee_lock_release();
29 }
30}
31
32void ZigbeeAttribute::report_(bool has_lock) {
33 if (!this->report_enabled) {
34 return;
35 }
36 if (!this->zb_->is_joined()) {
37 this->report_requested_ = true;
38 if (!this->set_attr_requested_) {
39 this->disable_loop();
40 }
41 return;
42 }
43 if (has_lock or esp_zigbee_lock_acquire(10 / portTICK_PERIOD_MS)) {
44 ezb_zcl_report_attr_cmd_t cmd = {};
45 cmd.cmd_ctrl.fc.direction = EZB_ZCL_CMD_DIRECTION_TO_CLI;
46 cmd.cmd_ctrl.fc.dis_default_rsp = 1;
47 cmd.cmd_ctrl.dst_addr.addr_mode = EZB_ADDR_MODE_SHORT;
48 cmd.cmd_ctrl.dst_addr.u.short_addr = 0x0000;
49 cmd.cmd_ctrl.dst_ep = 1;
50 cmd.cmd_ctrl.src_ep = this->endpoint_id_;
51 cmd.cmd_ctrl.cluster_id = this->cluster_id_;
52 cmd.cmd_ctrl.fc.manuf_specific = 0;
53 cmd.payload.attr_id = this->attr_id_;
54
55 ezb_zcl_report_attr_cmd_req(&cmd);
56 this->report_requested_ = false;
57 if (!has_lock) {
58 esp_zigbee_lock_release();
59 }
60 }
61}
62
64 this->report_enabled = true;
66 this->force_report_ = true;
67 }
68 this->zb_->add_on_join_callback([this](bool) {
69 if (this->report_requested_) {
70 this->enable_loop();
71 }
72 });
73}
74
76 if (this->set_attr_requested_) {
77 this->set_attr_();
78 }
79
80 if (this->report_requested_) {
81 this->report_(false);
82 }
83
84 if (!this->report_requested_ && !this->set_attr_requested_) {
85 this->disable_loop();
86 }
87}
88
89} // namespace esphome::zigbee
90
91#endif
92#endif
void enable_loop()
Enable this component's loop.
Definition component.h:246
void disable_loop()
Disable this component's loop.
bool state
Definition fan.h:2
const char *const TAG
Definition spi.cpp:7