14#include "esp_zigbee.h"
20#ifdef USE_BINARY_SENSOR
42 uint8_t
attr_type,
float scale, uint8_t max_size)
52 template<
typename T>
void add_attr(T value);
53 template<
typename T>
void set_attr(
const T &value);
60 if (attribute.data.type == this->attr_type() && attribute.data.value) {
69#ifdef USE_BINARY_SENSOR
110 *
static_cast<T *
>(this->
value_p_) = value;
116 static_assert(
sizeof(T) <= 2 || std::is_floating_point_v<T>);
117 if constexpr (std::is_integral<T>::value) {
118 const float scaled = this->
scale_ * value;
119 if (std::isnan(value) || scaled <
static_cast<float>(std::numeric_limits<T>::lowest()) ||
120 scaled >
static_cast<float>(std::numeric_limits<T>::max())) {
123 return static_cast<T
>(lroundf(scaled));
125 return static_cast<T
>(this->
scale_ * value);
129 if constexpr (std::is_integral_v<T>) {
130 if constexpr (std::is_signed_v<T>) {
132 return static_cast<T
>(std::numeric_limits<T>::min());
135 if (this->
attr_type_ >= EZB_ZCL_ATTR_TYPE_UINT8 && this->
attr_type_ <= EZB_ZCL_ATTR_TYPE_ENUM16) {
137 return static_cast<T
>(std::numeric_limits<T>::max());
141 return static_cast<T
>(0);
144 return std::numeric_limits<T>::quiet_NaN();
155#ifdef USE_BINARY_SENSOR
163 [device](ezb_zcl_attribute_t attribute) { device->
control(*(T *) attribute.data.value); });
170 if (this->
cluster_id_ == EZB_ZCL_CLUSTER_ID_ANALOG_OUTPUT) {
180 call.
set_value(
static_cast<float>(*(T *) attribute.data.value) / this->scale_);
void enable_loop()
Enable this component's loop.
void add_on_state_callback(F &&callback)
Base class for all binary_sensor-type classes.
NumberCall & set_value(float value)
Base-class for all numbers.
void add_on_state_callback(F &&callback)
float get_min_value() const
float get_max_value() const
Base-class for all sensors.
void add_on_state_callback(F &&callback)
Add a callback that will be called every time a filtered value arrives.
Base class for all switches.
void add_on_state_callback(F &&callback)
Set callback for state changes.
void control(bool target_state)
Control this switch using a boolean state value.
void report_(bool has_lock)
void set_report(ZigbeeReportT report)
LazyCallbackManager< void(ezb_zcl_attribute_t attribute)> on_value_callback_
void connect(sensor::Sensor *sensor)
void on_value(ezb_zcl_attribute_t attribute)
ZigbeeAttribute(ZigbeeComponent *parent, uint8_t endpoint_id, uint16_t cluster_id, uint8_t role, uint16_t attr_id, uint8_t attr_type, float scale, uint8_t max_size)
void set_attr(const T &value)
T scale_value_(float value)
void add_on_value_callback(F &&callback)
void add_attr(ZigbeeAttribute *attr, uint8_t endpoint_id, uint16_t cluster_id, uint8_t role, uint16_t attr_id, uint8_t max_size, T value)
@ ZIGBEE_REPORT_COORDINATOR