ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
zigbee_zephyr.h
Go to the documentation of this file.
1#pragma once
3#if defined(USE_ZIGBEE) && defined(USE_NRF52)
6extern "C" {
7#include <zboss_api.h>
8#include <zboss_api_addons.h>
9}
10
11// copy of ZB_DECLARE_SIMPLE_DESC. Due to https://github.com/nrfconnect/sdk-nrfxlib/pull/666
12#define ESPHOME_ZB_DECLARE_SIMPLE_DESC(ep_name, in_clusters_count, out_clusters_count) \
13 typedef ZB_PACKED_PRE struct zb_af_simple_desc_##ep_name##_##in_clusters_count##_##out_clusters_count##_s { \
14 zb_uint8_t endpoint; /* Endpoint */ \
15 zb_uint16_t app_profile_id; /* Application profile identifier */ \
16 zb_uint16_t app_device_id; /* Application device identifier */ \
17 zb_bitfield_t app_device_version : 4; /* Application device version */ \
18 zb_bitfield_t reserved : 4; /* Reserved */ \
19 zb_uint8_t app_input_cluster_count; /* Application input cluster count */ \
20 zb_uint8_t app_output_cluster_count; /* Application output cluster count */ \
21 /* Application input and output cluster list */ \
22 zb_uint16_t app_cluster_list[(in_clusters_count) + (out_clusters_count)]; \
23 } ZB_PACKED_STRUCT zb_af_simple_desc_##ep_name##_##in_clusters_count##_##out_clusters_count##_t
24
25#define ESPHOME_CAT7(a, b, c, d, e, f, g) a##b##c##d##e##f##g
26// needed to use ESPHOME_ZB_DECLARE_SIMPLE_DESC
27#define ESPHOME_ZB_AF_SIMPLE_DESC_TYPE(ep_name, in_num, out_num) \
28 ESPHOME_CAT7(zb_af_simple_desc_, ep_name, _, in_num, _, out_num, _t)
29
30// needed to use ESPHOME_ZB_DECLARE_SIMPLE_DESC
31#define ESPHOME_ZB_ZCL_DECLARE_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num, app_device_id, ...) \
32 ESPHOME_ZB_DECLARE_SIMPLE_DESC(ep_name, in_clust_num, out_clust_num); \
33 ESPHOME_ZB_AF_SIMPLE_DESC_TYPE(ep_name, in_clust_num, out_clust_num) \
34 simple_desc_##ep_name = {ep_id, ZB_AF_HA_PROFILE_ID, app_device_id, 0, 0, in_clust_num, out_clust_num, {__VA_ARGS__}}
35
36// needed to use ESPHOME_ZB_ZCL_DECLARE_SIMPLE_DESC
37#define ESPHOME_ZB_HA_DECLARE_EP(ep_name, ep_id, cluster_list, in_cluster_num, out_cluster_num, report_attr_count, \
38 app_device_id, ...) \
39 ESPHOME_ZB_ZCL_DECLARE_SIMPLE_DESC(ep_name, ep_id, in_cluster_num, out_cluster_num, app_device_id, __VA_ARGS__); \
40 ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info##ep_name, report_attr_count); \
41 ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, 0, NULL, \
42 ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list, \
43 (zb_af_simple_desc_1_1_t *) &simple_desc_##ep_name, report_attr_count, \
44 reporting_info##ep_name, 0, NULL)
45
46namespace esphome::zigbee {
47
49 zb_bool_t out_of_service;
50 zb_bool_t present_value;
51 zb_uint8_t status_flags;
52 zb_uchar_t description[ZB_ZCL_MAX_STRING_SIZE];
53};
54
56 zb_bool_t out_of_service;
58 zb_uint8_t status_flags;
59 zb_uint16_t engineering_units;
60 zb_uchar_t description[ZB_ZCL_MAX_STRING_SIZE];
61};
62
68
69class ZigbeeComponent final : public Component {
70 public:
71 void setup() override;
72 void dump_config() override;
73 // Each switch, number and time entity adds its handler, matched by endpoint, in codegen
74 HUB_PUBLISHER_RETURNING(bool, zcl_device, zb_uint8_t, zb_bufid_t)
75 template<typename F> void add_on_join_callback(F &&cb) { this->join_cb_.add(std::forward<F>(cb)); }
76 template<typename F> void add_on_start_callback(F &&cb) { this->start_cb_.add(std::forward<F>(cb)); }
77 void zboss_signal_handler_esphome(zb_bufid_t bufid);
78 void after_reporting_info(zb_zcl_configure_reporting_req_t *config_rep_req, zb_zcl_attr_addr_info_t *attr_addr_info);
80 void force_report();
81 void loop() override;
82 void set_sleepy(bool sleepy) { this->sleepy_ = sleepy; }
84
85 protected:
86 static void zcl_device_cb(zb_bufid_t bufid);
87 void on_join_(bool factory_new);
88 void on_start_();
89#ifdef USE_ZIGBEE_WIPE_ON_BOOT
90 void erase_flash_(int area);
91#endif
92 void dump_reporting_();
93 CallbackManager<void(bool)> join_cb_;
99 bool force_report_{false};
100 bool sleepy_{};
101};
102
104 public:
105 void set_parent(ZigbeeComponent *parent) { this->parent_ = parent; }
106 void set_endpoint(zb_uint8_t endpoint) { this->endpoint_ = endpoint; }
107
108 protected:
109 zb_uint8_t endpoint_{0};
111};
112
113extern ZigbeeComponent *global_zigbee; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
114
115} // namespace esphome::zigbee
116#endif
void after_reporting_info(zb_zcl_configure_reporting_req_t *config_rep_req, zb_zcl_attr_addr_info_t *attr_addr_info)
CallbackManager< void(bool)> join_cb_
HUB_PUBLISHER_RETURNING(bool, zcl_device, zb_uint8_t, zb_bufid_t) template< typename F > void add_on_join_callback(F &&cb)
static void zcl_device_cb(zb_bufid_t bufid)
LazyCallbackManager< void()> start_cb_
void on_join_(bool factory_new)
void zboss_signal_handler_esphome(zb_bufid_t bufid)
void add_radio_sleep_time_ms(uint32_t ms)
void set_endpoint(zb_uint8_t endpoint)
void set_parent(ZigbeeComponent *parent)
static void uint32_t
zb_uchar_t description[ZB_ZCL_MAX_STRING_SIZE]
zb_uchar_t description[ZB_ZCL_MAX_STRING_SIZE]