1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-14 06:38:17 +00:00

Merge branch 'dev' into feature_dallas_pio

This commit is contained in:
Thierry Duvernoy 2025-02-07 08:31:40 +01:00 committed by GitHub
commit 411f23b16e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 267 additions and 51 deletions

View File

@ -46,9 +46,9 @@ jobs:
with:
python-version: "3.9"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.8.0
uses: docker/setup-buildx-action@v3.9.0
- name: Set up QEMU
uses: docker/setup-qemu-action@v3.3.0
uses: docker/setup-qemu-action@v3.4.0
- name: Set TAG
run: |

View File

@ -89,10 +89,10 @@ jobs:
python-version: "3.9"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.8.0
uses: docker/setup-buildx-action@v3.9.0
- name: Set up QEMU
if: matrix.platform != 'linux/amd64'
uses: docker/setup-qemu-action@v3.3.0
uses: docker/setup-qemu-action@v3.4.0
- name: Log in to docker hub
uses: docker/login-action@v3.3.0
@ -183,7 +183,7 @@ jobs:
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.8.0
uses: docker/setup-buildx-action@v3.9.0
- name: Log in to docker hub
if: matrix.registry == 'dockerhub'

View File

@ -1,41 +1,41 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import automation
import esphome.codegen as cg
from esphome.components import binary_sensor
import esphome.config_validation as cv
from esphome.const import (
CONF_ADDRESS,
CONF_BUTTON,
CONF_CARRIER_FREQUENCY,
CONF_CHANNEL,
CONF_CHECK,
CONF_CODE,
CONF_COMMAND,
CONF_COMMAND_REPEATS,
CONF_DATA,
CONF_TRIGGER_ID,
CONF_NBITS,
CONF_ADDRESS,
CONF_COMMAND,
CONF_CODE,
CONF_PULSE_LENGTH,
CONF_SYNC,
CONF_ZERO,
CONF_ONE,
CONF_INVERTED,
CONF_PROTOCOL,
CONF_GROUP,
CONF_DELTA,
CONF_DEVICE,
CONF_SECOND,
CONF_STATE,
CONF_CHANNEL,
CONF_FAMILY,
CONF_REPEAT,
CONF_WAIT_TIME,
CONF_TIMES,
CONF_TYPE_ID,
CONF_CARRIER_FREQUENCY,
CONF_GROUP,
CONF_ID,
CONF_INVERTED,
CONF_LEVEL,
CONF_MAGNITUDE,
CONF_NBITS,
CONF_ONE,
CONF_PROTOCOL,
CONF_PULSE_LENGTH,
CONF_RC_CODE_1,
CONF_RC_CODE_2,
CONF_MAGNITUDE,
CONF_REPEAT,
CONF_SECOND,
CONF_STATE,
CONF_SYNC,
CONF_TIMES,
CONF_TRIGGER_ID,
CONF_TYPE_ID,
CONF_WAIT_TIME,
CONF_WAND_ID,
CONF_LEVEL,
CONF_DELTA,
CONF_ID,
CONF_BUTTON,
CONF_CHECK,
CONF_ZERO,
)
from esphome.core import coroutine
from esphome.schema_extractors import SCHEMA_EXTRACT, schema_extractor
@ -1963,3 +1963,55 @@ async def mirage_action(var, config, args):
vec_ = cg.std_vector.template(cg.uint8)
template_ = await cg.templatable(config[CONF_CODE], args, vec_, vec_)
cg.add(var.set_code(template_))
# Toto
(
TotoData,
TotoBinarySensor,
TotoTrigger,
TotoAction,
TotoDumper,
) = declare_protocol("Toto")
TOTO_SCHEMA = cv.Schema(
{
cv.Optional(CONF_RC_CODE_1, default=0): cv.hex_int_range(0, 0xF),
cv.Optional(CONF_RC_CODE_2, default=0): cv.hex_int_range(0, 0xF),
cv.Required(CONF_COMMAND): cv.hex_uint8_t,
}
)
@register_binary_sensor("toto", TotoBinarySensor, TOTO_SCHEMA)
def toto_binary_sensor(var, config):
cg.add(
var.set_data(
cg.StructInitializer(
TotoData,
("rc_code_1", config[CONF_RC_CODE_1]),
("rc_code_2", config[CONF_RC_CODE_2]),
("command", config[CONF_COMMAND]),
)
)
)
@register_trigger("toto", TotoTrigger, TotoData)
def toto_trigger(var, config):
pass
@register_dumper("toto", TotoDumper)
def toto_dumper(var, config):
pass
@register_action("toto", TotoAction, TOTO_SCHEMA)
async def Toto_action(var, config, args):
template_ = await cg.templatable(config[CONF_RC_CODE_1], args, cg.uint8)
cg.add(var.set_rc_code_1(template_))
template_ = await cg.templatable(config[CONF_RC_CODE_2], args, cg.uint8)
cg.add(var.set_rc_code_2(template_))
template_ = await cg.templatable(config[CONF_COMMAND], args, cg.uint8)
cg.add(var.set_command(template_))

View File

@ -0,0 +1,100 @@
#include "toto_protocol.h"
#include "esphome/core/log.h"
namespace esphome {
namespace remote_base {
static const char *const TAG = "remote.toto";
static const uint32_t PREAMBLE_HIGH_US = 6200;
static const uint32_t PREAMBLE_LOW_US = 2800;
static const uint32_t BIT_HIGH_US = 550;
static const uint32_t BIT_ONE_LOW_US = 1700;
static const uint32_t BIT_ZERO_LOW_US = 550;
static const uint32_t TOTO_HEADER = 0x2008;
void TotoProtocol::encode(RemoteTransmitData *dst, const TotoData &data) {
uint32_t payload = 0;
payload = data.rc_code_1 << 20;
payload |= data.rc_code_2 << 16;
payload |= data.command << 8;
payload |= ((payload & 0xFF0000) >> 16) ^ ((payload & 0x00FF00) >> 8);
dst->reserve(80);
dst->set_carrier_frequency(38000);
dst->item(PREAMBLE_HIGH_US, PREAMBLE_LOW_US);
for (uint32_t mask = 1UL << 14; mask; mask >>= 1) {
if (TOTO_HEADER & mask) {
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
} else {
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
}
}
for (uint32_t mask = 1UL << 23; mask; mask >>= 1) {
if (payload & mask) {
dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
} else {
dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
}
}
dst->mark(BIT_HIGH_US);
}
optional<TotoData> TotoProtocol::decode(RemoteReceiveData src) {
uint16_t header = 0;
uint32_t payload = 0;
TotoData data{
.rc_code_1 = 0,
.rc_code_2 = 0,
.command = 0,
};
if (!src.expect_item(PREAMBLE_HIGH_US, PREAMBLE_LOW_US)) {
return {};
}
for (uint32_t mask = 1UL << 14; mask; mask >>= 1) {
if (src.expect_item(BIT_HIGH_US, BIT_ONE_LOW_US)) {
header |= mask;
} else if (src.expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) {
header &= ~mask;
} else {
return {};
}
}
if (header != TOTO_HEADER) {
return {};
}
for (uint32_t mask = 1UL << 23; mask; mask >>= 1) {
if (src.expect_item(BIT_HIGH_US, BIT_ONE_LOW_US)) {
payload |= mask;
} else if (src.expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) {
payload &= ~mask;
} else {
return {};
}
}
if ((((payload & 0xFF0000) >> 16) ^ ((payload & 0x00FF00) >> 8)) != (payload & 0x0000FF)) {
return {};
}
data.rc_code_1 = (payload & 0xF00000) >> 20;
data.rc_code_2 = (payload & 0x0F0000) >> 16;
data.command = (payload & 0x00FF00) >> 8;
return data;
}
void TotoProtocol::dump(const TotoData &data) {
ESP_LOGI(TAG, "Received Toto data: rc_code_1=0x%01X, rc_code_2=0x%01X, command=0x%02X", data.rc_code_1,
data.rc_code_2, data.command);
}
} // namespace remote_base
} // namespace esphome

View File

@ -0,0 +1,45 @@
#pragma once
#include "remote_base.h"
namespace esphome {
namespace remote_base {
struct TotoData {
uint8_t rc_code_1 : 4;
uint8_t rc_code_2 : 4;
uint8_t command;
bool operator==(const TotoData &rhs) const {
return (rc_code_1 == rhs.rc_code_1) && (rc_code_2 == rhs.rc_code_2) && (command == rhs.command);
}
};
class TotoProtocol : public RemoteProtocol<TotoData> {
public:
void encode(RemoteTransmitData *dst, const TotoData &data) override;
optional<TotoData> decode(RemoteReceiveData src) override;
void dump(const TotoData &data) override;
};
DECLARE_REMOTE_PROTOCOL(Toto)
template<typename... Ts> class TotoAction : public RemoteTransmitterActionBase<Ts...> {
public:
TEMPLATABLE_VALUE(uint8_t, rc_code_1)
TEMPLATABLE_VALUE(uint8_t, rc_code_2)
TEMPLATABLE_VALUE(uint8_t, command)
void encode(RemoteTransmitData *dst, Ts... x) override {
TotoData data{};
data.rc_code_1 = this->rc_code_1_.value(x...);
data.rc_code_2 = this->rc_code_2_.value(x...);
data.command = this->command_.value(x...);
this->set_send_times(this->send_times_.value_or(x..., 3));
this->set_send_wait(this->send_wait_.value_or(x..., 32000));
TotoProtocol().encode(dst, data);
}
};
} // namespace remote_base
} // namespace esphome

View File

@ -2,6 +2,7 @@
#include "esphome/core/log.h"
#ifdef USE_ESP32
#include <driver/gpio.h>
namespace esphome {
namespace remote_receiver {
@ -62,6 +63,11 @@ void RemoteReceiverComponent::setup() {
this->mark_failed();
return;
}
if (this->pin_->get_flags() & gpio::FLAG_PULLUP) {
gpio_pullup_en(gpio_num_t(this->pin_->get_pin()));
} else {
gpio_pullup_dis(gpio_num_t(this->pin_->get_pin()));
}
error = rmt_enable(this->channel_);
if (error != ESP_OK) {
this->error_code_ = error;

View File

@ -8,6 +8,8 @@ from esphome.const import (
CONF_CLOCK_RESOLUTION,
CONF_ID,
CONF_INVERTED,
CONF_MODE,
CONF_OPEN_DRAIN,
CONF_PIN,
CONF_RMT_CHANNEL,
CONF_RMT_SYMBOLS,
@ -20,7 +22,6 @@ AUTO_LOAD = ["remote_base"]
CONF_EOT_LEVEL = "eot_level"
CONF_ON_TRANSMIT = "on_transmit"
CONF_ON_COMPLETE = "on_complete"
CONF_ONE_WIRE = "one_wire"
remote_transmitter_ns = cg.esphome_ns.namespace("remote_transmitter")
RemoteTransmitterComponent = remote_transmitter_ns.class_(
@ -44,7 +45,6 @@ CONFIG_SCHEMA = cv.Schema(
cv.only_on_esp32, cv.only_with_arduino, cv.int_range(min=1, max=255)
),
cv.Optional(CONF_EOT_LEVEL): cv.All(cv.only_with_esp_idf, cv.boolean),
cv.Optional(CONF_ONE_WIRE): cv.All(cv.only_with_esp_idf, cv.boolean),
cv.Optional(CONF_USE_DMA): cv.All(cv.only_with_esp_idf, cv.boolean),
cv.SplitDefault(
CONF_RMT_SYMBOLS,
@ -74,14 +74,15 @@ async def to_code(config):
cg.add(var.set_clock_resolution(config[CONF_CLOCK_RESOLUTION]))
if CONF_USE_DMA in config:
cg.add(var.set_with_dma(config[CONF_USE_DMA]))
if CONF_ONE_WIRE in config:
cg.add(var.set_one_wire(config[CONF_ONE_WIRE]))
if CONF_EOT_LEVEL in config:
cg.add(var.set_eot_level(config[CONF_EOT_LEVEL]))
elif CONF_ONE_WIRE in config and config[CONF_ONE_WIRE]:
cg.add(var.set_eot_level(True))
elif CONF_INVERTED in config[CONF_PIN] and config[CONF_PIN][CONF_INVERTED]:
cg.add(var.set_eot_level(True))
else:
cg.add(
var.set_eot_level(
config[CONF_PIN][CONF_MODE][CONF_OPEN_DRAIN]
or config[CONF_PIN][CONF_INVERTED]
)
)
else:
if (rmt_channel := config.get(CONF_RMT_CHANNEL, None)) is not None:
var = cg.new_Pvariable(config[CONF_ID], pin, rmt_channel)

View File

@ -40,7 +40,6 @@ class RemoteTransmitterComponent : public remote_base::RemoteTransmitterBase,
#if defined(USE_ESP32) && ESP_IDF_VERSION_MAJOR >= 5
void set_with_dma(bool with_dma) { this->with_dma_ = with_dma; }
void set_one_wire(bool one_wire) { this->one_wire_ = one_wire; }
void set_eot_level(bool eot_level) { this->eot_level_ = eot_level; }
void digital_write(bool value);
#endif
@ -69,7 +68,6 @@ class RemoteTransmitterComponent : public remote_base::RemoteTransmitterBase,
#if ESP_IDF_VERSION_MAJOR >= 5
std::vector<rmt_symbol_word_t> rmt_temp_;
bool with_dma_{false};
bool one_wire_{false};
bool eot_level_{false};
rmt_channel_handle_t channel_{NULL};
rmt_encoder_handle_t encoder_{NULL};

View File

@ -3,6 +3,7 @@
#include "esphome/core/application.h"
#ifdef USE_ESP32
#include <driver/gpio.h>
namespace esphome {
namespace remote_transmitter {
@ -18,7 +19,6 @@ void RemoteTransmitterComponent::setup() {
void RemoteTransmitterComponent::dump_config() {
ESP_LOGCONFIG(TAG, "Remote Transmitter:");
#if ESP_IDF_VERSION_MAJOR >= 5
ESP_LOGCONFIG(TAG, " One wire: %s", this->one_wire_ ? "true" : "false");
ESP_LOGCONFIG(TAG, " Clock resolution: %" PRIu32 " hz", this->clock_resolution_);
ESP_LOGCONFIG(TAG, " RMT symbols: %" PRIu32, this->rmt_symbols_);
#else
@ -68,6 +68,7 @@ void RemoteTransmitterComponent::configure_rmt_() {
esp_err_t error;
if (!this->initialized_) {
bool open_drain = (this->pin_->get_flags() & gpio::FLAG_OPEN_DRAIN) != 0;
rmt_tx_channel_config_t channel;
memset(&channel, 0, sizeof(channel));
channel.clk_src = RMT_CLK_SRC_DEFAULT;
@ -75,8 +76,8 @@ void RemoteTransmitterComponent::configure_rmt_() {
channel.gpio_num = gpio_num_t(this->pin_->get_pin());
channel.mem_block_symbols = this->rmt_symbols_;
channel.trans_queue_depth = 1;
channel.flags.io_loop_back = this->one_wire_;
channel.flags.io_od_mode = this->one_wire_;
channel.flags.io_loop_back = open_drain;
channel.flags.io_od_mode = open_drain;
channel.flags.invert_out = 0;
channel.flags.with_dma = this->with_dma_;
channel.intr_priority = 0;
@ -91,6 +92,11 @@ void RemoteTransmitterComponent::configure_rmt_() {
this->mark_failed();
return;
}
if (this->pin_->get_flags() & gpio::FLAG_PULLUP) {
gpio_pullup_en(gpio_num_t(this->pin_->get_pin()));
} else {
gpio_pullup_dis(gpio_num_t(this->pin_->get_pin()));
}
rmt_copy_encoder_config_t encoder;
memset(&encoder, 0, sizeof(encoder));
@ -109,7 +115,7 @@ void RemoteTransmitterComponent::configure_rmt_() {
this->mark_failed();
return;
}
this->digital_write(this->one_wire_ || this->inverted_);
this->digital_write(open_drain || this->inverted_);
this->initialized_ = true;
}

View File

@ -142,3 +142,8 @@ on_mirage:
then:
- lambda: |-
ESP_LOGD("mirage", "Mirage data: %s", format_hex(x.data).c_str());
on_toto:
then:
- logger.log:
format: "on_toto: %u %u %u"
args: ["x.rc_code_1", "x.rc_code_2", "x.command"]

View File

@ -190,3 +190,10 @@ button:
channel: 1
button: 1
check: 1
- platform: template
name: Toto
on_press:
- remote_transmitter.transmit_toto:
command: 0xEC
rc_code_1: 0x0D
rc_code_2: 0x0D

View File

@ -3,7 +3,6 @@ remote_transmitter:
pin: ${pin}
carrier_duty_percent: 50%
clock_resolution: ${clock_resolution}
one_wire: ${one_wire}
rmt_symbols: ${rmt_symbols}
use_dma: ${use_dma}

View File

@ -1,7 +1,6 @@
substitutions:
pin: GPIO2
clock_resolution: "2000000"
one_wire: "true"
rmt_symbols: "64"
use_dma: "true"

View File

@ -1,7 +1,6 @@
substitutions:
pin: GPIO2
clock_resolution: "2000000"
one_wire: "true"
rmt_symbols: "64"
use_dma: "true"

View File

@ -1,7 +1,6 @@
substitutions:
pin: GPIO38
clock_resolution: "2000000"
one_wire: "true"
rmt_symbols: "64"
use_dma: "true"