ESPHome 2026.5.0b1
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_zb_lock_acquire(10 / portTICK_PERIOD_MS)) {
16 esp_zb_zcl_status_t state = esp_zb_zcl_set_attribute_val(this->endpoint_id_, this->cluster_id_, this->role_,
17 this->attr_id_, 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 != ESP_ZB_ZCL_STATUS_SUCCESS) {
24 ESP_LOGE(TAG, "Setting attribute failed, ZCL status: %u", static_cast<unsigned>(state));
25 }
26 esp_zb_lock_release();
27 }
28}
29
30void ZigbeeAttribute::report_(bool has_lock) {
31 if (!this->zb_->is_connected()) {
32 return;
33 }
34 if (has_lock or esp_zb_lock_acquire(10 / portTICK_PERIOD_MS)) {
35 esp_zb_zcl_report_attr_cmd_t cmd = {};
36 cmd.address_mode = ESP_ZB_APS_ADDR_MODE_16_ENDP_PRESENT;
37 cmd.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_CLI;
38 cmd.zcl_basic_cmd.dst_addr_u.addr_short = 0x0000;
39 cmd.zcl_basic_cmd.dst_endpoint = 1;
40 cmd.zcl_basic_cmd.src_endpoint = this->endpoint_id_;
41 cmd.clusterID = this->cluster_id_;
42 cmd.attributeID = this->attr_id_;
43
44 esp_zb_zcl_report_attr_cmd_req(&cmd);
45 if (!has_lock) {
46 esp_zb_lock_release();
47 }
48 }
49}
50
51esp_zb_zcl_reporting_info_t ZigbeeAttribute::get_reporting_info() {
52 esp_zb_zcl_reporting_info_t reporting_info = {};
53 reporting_info.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_SRV;
54 reporting_info.ep = this->endpoint_id_;
55 reporting_info.cluster_id = this->cluster_id_;
56 reporting_info.cluster_role = this->role_;
57 reporting_info.attr_id = this->attr_id_;
58 reporting_info.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC;
59 reporting_info.dst.profile_id = ESP_ZB_AF_HA_PROFILE_ID;
60 reporting_info.u.send_info.min_interval = 10;
61 reporting_info.u.send_info.max_interval = 0;
62 reporting_info.u.send_info.def_min_interval = 10;
63 reporting_info.u.send_info.def_max_interval = 0;
64 reporting_info.u.send_info.delta.s16 = 0;
66 return reporting_info;
67}
68
70 this->report_enabled = true;
71 this->force_report_ = force;
72}
73
75 if (this->set_attr_requested_) {
76 this->set_attr_();
77 }
78
79 if (!this->set_attr_requested_) {
80 this->disable_loop();
81 }
82}
83
84} // namespace esphome::zigbee
85
86#endif
87#endif
void disable_loop()
Disable this component's loop.
esp_zb_zcl_reporting_info_t get_reporting_info()
bool state
Definition fan.h:2
const char *const TAG
Definition spi.cpp:7