28static constexpr ReadingLayout READINGS[] PROGMEM = {
39static ReadingLayout layout_of(
DucoReading reading) {
41 progmem_memcpy(&layout, &READINGS[
static_cast<uint8_t
>(reading)],
sizeof(layout));
46 switch (layout_of(this->
reading_).function) {
47 case FUNCTION_NODE_DATA:
48 this->
parent_->send(
this, FUNCTION_NODE_DATA, {0x01, this->
argument_, 0x00, 0x49, 0x04});
50 case FUNCTION_PARAMETER:
51 this->
parent_->send(
this, FUNCTION_PARAMETER, {0x00, this->
argument_, 0x09});
60 const ReadingLayout layout = layout_of(this->
reading_);
62 if (
message.size < layout.offset + (wide ? 2 : 1)) {
63 ESP_LOGV(TAG,
"Answer of %u bytes is too short",
message.size);
67 const uint8_t *field =
message.data + layout.offset;
68 int32_t value = field[0];
74 if (value >= layout.minimum && value <= layout.maximum)
75 this->
publish_state(
static_cast<float>(value) / layout.divisor);
void receive_response(const DucoMessage &message) override
void publish_state(float state)
Publish a new state to the front-end.
const LogString * message
ESPHOME_LOG_TAG(TAG, "duco")
DucoReading
What a sensor reads; the request and where the value is in the answer are in READINGS in sensor....
@ DUCO_VALUE_FORMAT_UINT16
@ DUCO_VALUE_FORMAT_INT16
@ DUCO_VALUE_FORMAT_UINT8
void progmem_memcpy(void *dst, const void *src, size_t len)
constexpr T encode_value_le(const uint8_t *bytes)
Encode a value from its constituent bytes (from least to most significant) in an array with length si...
A received message; data points into the receive buffer and is valid only during the callback.