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:
@@ -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
|
||||
|
||||
@@ -214,10 +214,14 @@ 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->static_ = false;
|
||||
}
|
||||
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 {
|
||||
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_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->static_) {
|
||||
data_vec.assign(this->data_.static_data.ptr, this->data_.static_data.ptr + this->data_.static_data.len);
|
||||
} else {
|
||||
data.set_data(this->data_static_);
|
||||
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};
|
||||
bool static_{true};
|
||||
union Data {
|
||||
std::vector<uint8_t> (*func)(Ts...);
|
||||
struct {
|
||||
const uint8_t *ptr;
|
||||
size_t len;
|
||||
} static_data;
|
||||
} data_;
|
||||
};
|
||||
|
||||
} // namespace remote_base
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user