1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-09 11:31:50 +00:00

Compare commits

..

5 Commits

Author SHA1 Message Date
J. Nick Koston
40f0be2d0f Merge remote-tracking branch 'origin/abbwelcome_protocol_automation' into abbwelcome_protocol_automation 2025-11-08 23:45:49 -06:00
J. Nick Koston
ff04a6da4b optimize 2025-11-08 23:45:42 -06:00
J. Nick Koston
772340cdc3 Merge branch 'abbwelcome_tests' into abbwelcome_protocol_automation 2025-11-08 22:51:59 -06:00
J. Nick Koston
d29882e4ad Add additonal abbwelcome remote_base tests 2025-11-08 22:51:11 -06:00
J. Nick Koston
a239460724 [remote_base] Optimize abbwelcome action memory usage - store static data in flash 2025-11-08 22:48:50 -06:00
4 changed files with 48 additions and 31 deletions

View File

@@ -39,7 +39,7 @@ from esphome.const import (
CONF_WAND_ID,
CONF_ZERO,
)
from esphome.core import coroutine
from esphome.core import ID, coroutine
from esphome.schema_extractors import SCHEMA_EXTRACT, schema_extractor
from esphome.util import Registry, SimpleRegistry
@@ -2104,7 +2104,9 @@ async def abbwelcome_action(var, config, args):
)
cg.add(var.set_data_template(template_))
else:
cg.add(var.set_data_static(data_))
arr_id = ID(f"{var.base}_data", is_declaration=True, type=cg.uint8)
arr = cg.static_const_array(arr_id, cg.ArrayInitializer(*data_))
cg.add(var.set_data_static(arr, len(data_)))
# Mirage

View File

@@ -214,10 +214,13 @@ template<typename... Ts> class ABBWelcomeAction : public RemoteTransmitterAction
TEMPLATABLE_VALUE(uint8_t, message_type)
TEMPLATABLE_VALUE(uint8_t, message_id)
TEMPLATABLE_VALUE(bool, auto_message_id)
void set_data_static(std::vector<uint8_t> data) { data_static_ = std::move(data); }
void set_data_template(std::function<std::vector<uint8_t>(Ts...)> func) {
this->data_func_ = func;
has_data_func_ = true;
void set_data_template(std::vector<uint8_t> (*func)(Ts...)) {
this->data_.func = func;
this->len_ = -1; // Sentinel value indicates template mode
}
void set_data_static(const uint8_t *data, size_t len) {
this->data_.data = data;
this->len_ = len; // Length >= 0 indicates static mode
}
void encode(RemoteTransmitData *dst, Ts... x) override {
ABBWelcomeData data;
@@ -228,19 +231,25 @@ template<typename... Ts> class ABBWelcomeAction : public RemoteTransmitterAction
data.set_message_type(this->message_type_.value(x...));
data.set_message_id(this->message_id_.value(x...));
data.auto_message_id = this->auto_message_id_.value(x...);
if (has_data_func_) {
data.set_data(this->data_func_(x...));
std::vector<uint8_t> data_vec;
if (this->len_ >= 0) {
// Static mode: copy from flash to vector
data_vec.assign(this->data_.data, this->data_.data + this->len_);
} else {
data.set_data(this->data_static_);
// Template mode: call function
data_vec = this->data_.func(x...);
}
data.set_data(data_vec);
data.finalize();
ABBWelcomeProtocol().encode(dst, data);
}
protected:
std::function<std::vector<uint8_t>(Ts...)> data_func_{};
std::vector<uint8_t> data_static_{};
bool has_data_func_{false};
ssize_t len_{-1}; // -1 = template mode, >=0 = static mode with length
union Data {
std::vector<uint8_t> (*func)(Ts...); // Function pointer (stateless lambdas)
const uint8_t *data; // Pointer to static data in flash
} data_;
};
} // namespace remote_base

View File

@@ -1,3 +1,11 @@
number:
- platform: template
id: test_number
optimistic: true
min_value: 0
max_value: 255
step: 1
button:
- platform: template
name: Beo4 audio mute
@@ -217,6 +225,23 @@ button:
command: 0xEC
rc_code_1: 0x0D
rc_code_2: 0x0D
- platform: template
name: ABBWelcome static
on_press:
remote_transmitter.transmit_abbwelcome:
source_address: 0x1234
destination_address: 0x5678
message_type: 0x01
data: [0x10, 0x20, 0x30]
- platform: template
name: ABBWelcome lambda
on_press:
remote_transmitter.transmit_abbwelcome:
source_address: 0x1234
destination_address: 0x5678
message_type: 0x01
data: !lambda |-
return {(uint8_t)id(test_number).state, 0x20, 0x30};
- platform: template
name: Digital Write
on_press:

View File

@@ -17,22 +17,3 @@ udp:
id: my_udp
data: !lambda |-
return std::vector<uint8_t>{1,3,4,5,6};
number:
- platform: template
name: "UDP Number"
id: my_number
optimistic: true
min_value: 0
max_value: 100
step: 1
button:
- platform: template
name: "UDP Button"
on_press:
then:
- udp.write:
data: [0x01, 0x02, 0x03]
- udp.write: !lambda |-
return {0x10, 0x20, (uint8_t)id(my_number).state};