ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
zigbee_number_zephyr.cpp
Go to the documentation of this file.
2#if defined(USE_ZIGBEE) && defined(USE_NRF52) && defined(USE_NUMBER)
3#include "esphome/core/log.h"
4extern "C" {
5#include <zboss_api.h>
6#include <zboss_api_addons.h>
7#include <zb_nrf_platform.h>
8#include <zigbee/zigbee_app_utils.h>
9#include <zb_error_to_string.h>
10}
11namespace esphome::zigbee {
12
13ESPHOME_LOG_TAG(TAG, "zigbee.number");
14
16 this->number_->add_on_state_callback([this](float state) {
18 ESP_LOGD(TAG, "Set attribute endpoint: %d, present_value %f", this->endpoint_,
20 ZB_ZCL_SET_ATTRIBUTE(this->endpoint_, ZB_ZCL_CLUSTER_ID_ANALOG_OUTPUT, ZB_ZCL_CLUSTER_SERVER_ROLE,
22 ZB_FALSE);
23 this->parent_->force_report();
24 });
25}
26
28 ESP_LOGCONFIG(TAG,
29 "Zigbee Number\n"
30 " Endpoint: %d, present_value %f",
32}
33
34void ZigbeeNumber::on_zcl_device_event(zb_bufid_t bufid) {
35 zb_zcl_device_callback_param_t *p_device_cb_param = ZB_BUF_GET_PARAM(bufid, zb_zcl_device_callback_param_t);
36 zb_zcl_device_callback_id_t device_cb_id = p_device_cb_param->device_cb_id;
37 zb_uint16_t cluster_id = p_device_cb_param->cb_param.set_attr_value_param.cluster_id;
38 zb_uint16_t attr_id = p_device_cb_param->cb_param.set_attr_value_param.attr_id;
39
40 switch (device_cb_id) {
41 /* ZCL set attribute value */
42 case ZB_ZCL_SET_ATTR_VALUE_CB_ID:
43 if (cluster_id == ZB_ZCL_CLUSTER_ID_ANALOG_OUTPUT) {
44 ESP_LOGI(TAG, "Analog output attribute setting");
46 float value =
47 *reinterpret_cast<const float *>(&p_device_cb_param->cb_param.set_attr_value_param.values.data32);
48 this->defer([this, value]() {
50 auto call = this->number_->make_call();
51 call.set_value(value);
52 call.perform();
53 });
54 }
55 } else {
56 /* other clusters attribute handled here */
57 ESP_LOGI(TAG, "Unhandled cluster attribute id: %d", cluster_id);
58 p_device_cb_param->status = RET_NOT_IMPLEMENTED;
59 }
60 break;
61 default:
62 p_device_cb_param->status = RET_NOT_IMPLEMENTED;
63 break;
64 }
65
66 ESP_LOGD(TAG, "%s status: %hd", __func__, p_device_cb_param->status);
67}
68
70
71static zb_ret_t check_value_analog_server(zb_uint16_t attr_id, zb_uint8_t endpoint,
72 zb_uint8_t *value) { // NOLINT(readability-non-const-parameter)
73 zb_ret_t ret = RET_OK;
74 ZVUNUSED(endpoint);
75
76 switch (attr_id) {
78 ret = ZB_ZCL_CHECK_BOOL_VALUE(*value) ? RET_OK : RET_ERROR;
79 break;
81 break;
82
85 ret = RET_ERROR;
86 }
87 break;
88
89 default:
90 break;
91 }
92
93 return ret;
94}
95
96} // namespace esphome::zigbee
97
99 zb_zcl_add_cluster_handlers(ZB_ZCL_CLUSTER_ID_ANALOG_OUTPUT, ZB_ZCL_CLUSTER_SERVER_ROLE,
100 esphome::zigbee::check_value_analog_server, (zb_zcl_cluster_write_attr_hook_t) NULL,
101 (zb_zcl_cluster_handler_t) NULL);
102}
103
105 zb_zcl_add_cluster_handlers(ZB_ZCL_CLUSTER_ID_ANALOG_OUTPUT, ZB_ZCL_CLUSTER_CLIENT_ROLE,
106 (zb_zcl_cluster_check_value_t) NULL, (zb_zcl_cluster_write_attr_hook_t) NULL,
107 (zb_zcl_cluster_handler_t) NULL);
108}
109
110#endif
void defer(const char *name, SchedulerCallback &&f)
Defer a callback to the next loop() call with a const char* name.
NumberCall & set_value(float value)
NumberCall make_call()
Definition number.h:35
void add_on_state_callback(F &&callback)
Definition number.h:37
AnalogAttrsOutput * cluster_attributes_
void on_zcl_device_event(zb_bufid_t bufid)
bool state
Definition fan.h:2
int ret
const zb_uint8_t ZB_ZCL_ANALOG_OUTPUT_STATUS_FLAG_MAX_VALUE
ESPHOME_LOG_TAG(TAG, "zigbee.time")
uint32_t value
Definition hal.cpp:59
void zb_zcl_analog_output_init_server()
void zb_zcl_analog_output_init_client()
@ ZB_ZCL_ATTR_ANALOG_OUTPUT_PRESENT_VALUE_ID
@ ZB_ZCL_ATTR_ANALOG_OUTPUT_OUT_OF_SERVICE_ID
@ ZB_ZCL_ATTR_ANALOG_OUTPUT_STATUS_FLAG_ID