ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
select.cpp
Go to the documentation of this file.
1#include "select.h"
2
3#include "esphome/core/hal.h"
4#include "esphome/core/log.h"
5
6namespace esphome::duco {
7
8ESPHOME_LOG_TAG(TAG, "duco.select");
9
10// Box code of each option, in the order of DUCO_MODE_OPTIONS in __init__.py
11static constexpr uint8_t MODE_CODES[] PROGMEM = {
12 0x00, // AUTO
13 0x04, // MAN1
14 0x05, // MAN2
15 0x06, // MAN3
16 0x07, // EMPT
17 0x08, // CNT1
18 0x09, // CNT2
19 0x0a, // CNT3
20 0x84, // MAN1x2
21 0x85, // MAN2x2
22 0x86, // MAN3x2
23 0xc4, // MAN1x3
24 0xc5, // MAN2x3
25 0xc6, // MAN3x3
26};
27
28void DucoSelect::update() { this->parent_->send(this, FUNCTION_NODE, {0x02, 0x01}); }
29
31 if (message.size < 1)
32 return;
33 for (size_t i = 0; i < sizeof(MODE_CODES); i++) {
34 if (progmem_read_byte(&MODE_CODES[i]) == message.data[0]) {
35 this->publish_state(i);
36 return;
37 }
38 }
39 ESP_LOGV(TAG, "Unknown mode %02X", message.data[0]);
40}
41
42void DucoSelect::control(size_t index) {
43 // The next update reads the new mode back
44 this->parent_->send(nullptr, FUNCTION_NODE, {0x04, 0x01, progmem_read_byte(&MODE_CODES[index])});
45}
46
47} // namespace esphome::duco
void update() override
Definition select.cpp:28
void receive_response(const DucoMessage &message) override
Definition select.cpp:30
void control(size_t index) override
Definition select.cpp:42
void publish_state(const std::string &state)
Definition select.h:35
const LogString * message
Definition component.cpp:35
ESPHOME_LOG_TAG(TAG, "duco")
uint8_t progmem_read_byte(const uint8_t *addr)
Definition hal.h:51
A received message; data points into the receive buffer and is valid only during the callback.
Definition duco.h:22