1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-14 13:55:45 +00:00

Merge branch 'abbwelcome_protocol_automation' into integration

This commit is contained in:
J. Nick Koston
2025-11-08 22:57:01 -06:00
3 changed files with 50 additions and 12 deletions

View File

@@ -39,7 +39,7 @@ from esphome.const import (
CONF_WAND_ID, CONF_WAND_ID,
CONF_ZERO, CONF_ZERO,
) )
from esphome.core import coroutine from esphome.core import ID, coroutine
from esphome.schema_extractors import SCHEMA_EXTRACT, schema_extractor from esphome.schema_extractors import SCHEMA_EXTRACT, schema_extractor
from esphome.util import Registry, SimpleRegistry from esphome.util import Registry, SimpleRegistry
@@ -2104,7 +2104,9 @@ async def abbwelcome_action(var, config, args):
) )
cg.add(var.set_data_template(template_)) cg.add(var.set_data_template(template_))
else: 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 # Mirage

View File

@@ -214,10 +214,14 @@ template<typename... Ts> class ABBWelcomeAction : public RemoteTransmitterAction
TEMPLATABLE_VALUE(uint8_t, message_type) TEMPLATABLE_VALUE(uint8_t, message_type)
TEMPLATABLE_VALUE(uint8_t, message_id) TEMPLATABLE_VALUE(uint8_t, message_id)
TEMPLATABLE_VALUE(bool, auto_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::vector<uint8_t> (*func)(Ts...)) {
void set_data_template(std::function<std::vector<uint8_t>(Ts...)> func) { this->data_.func = func;
this->data_func_ = func; this->static_ = false;
has_data_func_ = true; }
void set_data_static(const uint8_t *data, size_t len) {
this->data_.static_data.ptr = data;
this->data_.static_data.len = len;
this->static_ = true;
} }
void encode(RemoteTransmitData *dst, Ts... x) override { void encode(RemoteTransmitData *dst, Ts... x) override {
ABBWelcomeData data; ABBWelcomeData data;
@@ -228,19 +232,26 @@ template<typename... Ts> class ABBWelcomeAction : public RemoteTransmitterAction
data.set_message_type(this->message_type_.value(x...)); data.set_message_type(this->message_type_.value(x...));
data.set_message_id(this->message_id_.value(x...)); data.set_message_id(this->message_id_.value(x...));
data.auto_message_id = this->auto_message_id_.value(x...); data.auto_message_id = this->auto_message_id_.value(x...);
if (has_data_func_) { std::vector<uint8_t> data_vec;
data.set_data(this->data_func_(x...)); if (this->static_) {
data_vec.assign(this->data_.static_data.ptr, this->data_.static_data.ptr + this->data_.static_data.len);
} else { } else {
data.set_data(this->data_static_); data_vec = this->data_.func(x...);
} }
data.set_data(data_vec);
data.finalize(); data.finalize();
ABBWelcomeProtocol().encode(dst, data); ABBWelcomeProtocol().encode(dst, data);
} }
protected: protected:
std::function<std::vector<uint8_t>(Ts...)> data_func_{}; bool static_{true};
std::vector<uint8_t> data_static_{}; union Data {
bool has_data_func_{false}; std::vector<uint8_t> (*func)(Ts...);
struct {
const uint8_t *ptr;
size_t len;
} static_data;
} data_;
}; };
} // namespace remote_base } // 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: button:
- platform: template - platform: template
name: Beo4 audio mute name: Beo4 audio mute
@@ -217,6 +225,23 @@ button:
command: 0xEC command: 0xEC
rc_code_1: 0x0D rc_code_1: 0x0D
rc_code_2: 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 - platform: template
name: Digital Write name: Digital Write
on_press: on_press: