ESPHome
2026.1.4
Loading...
Searching...
No Matches
esphome
components
zigbee
zigbee_binary_sensor_zephyr.cpp
Go to the documentation of this file.
1
#include "
zigbee_binary_sensor_zephyr.h
"
2
#if defined(USE_ZIGBEE) && defined(USE_NRF52) && defined(USE_BINARY_SENSOR)
3
#include "
esphome/core/log.h
"
4
extern
"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
}
11
namespace
esphome::zigbee
{
12
13
static
const
char
*
const
TAG
=
"zigbee.binary_sensor"
;
14
15
ZigbeeBinarySensor::ZigbeeBinarySensor
(
binary_sensor::BinarySensor
*binary_sensor) : binary_sensor_(binary_sensor) {}
16
17
void
ZigbeeBinarySensor::setup
() {
18
this->
binary_sensor_
->
add_on_state_callback
([
this
](
bool
state
) {
19
this->
cluster_attributes_
->
present_value
= state ? ZB_TRUE : ZB_FALSE;
20
ESP_LOGD(TAG,
"Set attribute endpoint: %d, present_value %d"
, this->
endpoint_
,
21
this->
cluster_attributes_
->
present_value
);
22
ZB_ZCL_SET_ATTRIBUTE(this->
endpoint_
, ZB_ZCL_CLUSTER_ID_BINARY_INPUT, ZB_ZCL_CLUSTER_SERVER_ROLE,
23
ZB_ZCL_ATTR_BINARY_INPUT_PRESENT_VALUE_ID, &this->
cluster_attributes_
->
present_value
,
24
ZB_FALSE);
25
this->
parent_
->
flush
();
26
});
27
}
28
29
void
ZigbeeBinarySensor::dump_config
() {
30
ESP_LOGCONFIG(TAG,
31
"Zigbee Binary Sensor\n"
32
" Endpoint: %d, present_value %u"
,
33
this->
endpoint_
, this->
cluster_attributes_
->
present_value
);
34
}
35
36
}
// namespace esphome::zigbee
37
#endif
esphome::StatefulEntityBase::add_on_state_callback
void add_on_state_callback(std::function< void(T)> &&callback)
Definition
entity_base.h:231
esphome::binary_sensor::BinarySensor
Base class for all binary_sensor-type classes.
Definition
binary_sensor.h:31
esphome::zigbee::ZigbeeBinarySensor::dump_config
void dump_config() override
Definition
zigbee_binary_sensor_zephyr.cpp:29
esphome::zigbee::ZigbeeBinarySensor::setup
void setup() override
Definition
zigbee_binary_sensor_zephyr.cpp:17
esphome::zigbee::ZigbeeBinarySensor::ZigbeeBinarySensor
ZigbeeBinarySensor(binary_sensor::BinarySensor *binary_sensor)
Definition
zigbee_binary_sensor_zephyr.cpp:15
esphome::zigbee::ZigbeeBinarySensor::binary_sensor_
binary_sensor::BinarySensor * binary_sensor_
Definition
zigbee_binary_sensor_zephyr.h:41
esphome::zigbee::ZigbeeBinarySensor::cluster_attributes_
BinaryAttrs * cluster_attributes_
Definition
zigbee_binary_sensor_zephyr.h:40
esphome::zigbee::ZigbeeComponent::flush
void flush()
Definition
zigbee_zephyr.cpp:233
esphome::zigbee::ZigbeeEntity::parent_
ZigbeeComponent * parent_
Definition
zigbee_zephyr.h:97
esphome::zigbee::ZigbeeEntity::endpoint_
zb_uint8_t endpoint_
Definition
zigbee_zephyr.h:96
state
bool state
Definition
fan.h:0
log.h
esphome::spi::TAG
const char *const TAG
Definition
spi.cpp:7
esphome::zigbee
Definition
automation.h:7
esphome::zigbee::BinaryAttrs::present_value
zb_bool_t present_value
Definition
zigbee_zephyr.h:50
zigbee_binary_sensor_zephyr.h
Generated by
1.12.0