ESPHome 2026.8.0-dev
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_connected()) {
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 if (this->force_report_) {
19 this->report_(true);
20 }
21 this->set_attr_requested_ = false;
22 // Check for error
23 if (state != EZB_ZCL_STATUS_SUCCESS) {
24 ESP_LOGE(TAG, "Setting attribute failed, ZCL status: %u", static_cast<unsigned>(state));
25 }
26 esp_zigbee_lock_release();
27 }
28}
29
30void ZigbeeAttribute::report_(bool has_lock) {
31 if (!this->zb_->is_connected() || !this->report_enabled) {
32 return;
33 }
34 if (has_lock or esp_zigbee_lock_acquire(10 / portTICK_PERIOD_MS)) {
35 ezb_zcl_report_attr_cmd_t cmd = {};
36 cmd.cmd_ctrl.fc.direction = EZB_ZCL_CMD_DIRECTION_TO_CLI;
37 cmd.cmd_ctrl.fc.dis_default_rsp = 1;
38 cmd.cmd_ctrl.dst_addr.addr_mode = EZB_ADDR_MODE_SHORT;
39 cmd.cmd_ctrl.dst_addr.u.short_addr = 0x0000;
40 cmd.cmd_ctrl.dst_ep = 1;
41 cmd.cmd_ctrl.src_ep = this->endpoint_id_;
42 cmd.cmd_ctrl.cluster_id = this->cluster_id_;
43 cmd.cmd_ctrl.fc.manuf_specific = 0;
44 cmd.payload.attr_id = this->attr_id_;
45
46 ezb_zcl_report_attr_cmd_req(&cmd);
47 if (!has_lock) {
48 esp_zigbee_lock_release();
49 }
50 }
51}
52
54 this->report_enabled = true;
56 this->force_report_ = true;
57 }
58}
59
61 if (this->set_attr_requested_) {
62 this->set_attr_();
63 }
64
65 if (!this->set_attr_requested_) {
66 this->disable_loop();
67 }
68}
69
70} // namespace esphome::zigbee
71
72#endif
73#endif
void disable_loop()
Disable this component's loop.
bool state
Definition fan.h:2
const char *const TAG
Definition spi.cpp:7