mirror of
https://github.com/esphome/esphome.git
synced 2024-11-09 16:57:47 +01:00
parent
b12dc98150
commit
6839de69c1
5 changed files with 81 additions and 0 deletions
|
@ -323,6 +323,7 @@ esphome/components/tuya/sensor/* @jesserockz
|
|||
esphome/components/tuya/switch/* @jesserockz
|
||||
esphome/components/tuya/text_sensor/* @dentra
|
||||
esphome/components/uart/* @esphome/core
|
||||
esphome/components/uart/button/* @ssieb
|
||||
esphome/components/ufire_ec/* @pvizeli
|
||||
esphome/components/ufire_ise/* @pvizeli
|
||||
esphome/components/ultrasonic/* @OttoWinter
|
||||
|
|
35
esphome/components/uart/button/__init__.py
Normal file
35
esphome/components/uart/button/__init__.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import button, uart
|
||||
from esphome.const import CONF_DATA
|
||||
from esphome.core import HexInt
|
||||
from .. import uart_ns, validate_raw_data
|
||||
|
||||
CODEOWNERS = ["@ssieb"]
|
||||
|
||||
DEPENDENCIES = ["uart"]
|
||||
|
||||
UARTButton = uart_ns.class_("UARTButton", button.Button, uart.UARTDevice, cg.Component)
|
||||
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
button.button_schema(UARTButton)
|
||||
.extend(
|
||||
{
|
||||
cv.Required(CONF_DATA): validate_raw_data,
|
||||
}
|
||||
)
|
||||
.extend(uart.UART_DEVICE_SCHEMA)
|
||||
.extend(cv.COMPONENT_SCHEMA)
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = await button.new_button(config)
|
||||
await cg.register_component(var, config)
|
||||
await uart.register_uart_device(var, config)
|
||||
|
||||
data = config[CONF_DATA]
|
||||
if isinstance(data, bytes):
|
||||
data = [HexInt(x) for x in data]
|
||||
cg.add(var.set_data(data))
|
17
esphome/components/uart/button/uart_button.cpp
Normal file
17
esphome/components/uart/button/uart_button.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "uart_button.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace uart {
|
||||
|
||||
static const char *const TAG = "uart.button";
|
||||
|
||||
void UARTButton::press_action() {
|
||||
ESP_LOGD(TAG, "'%s': Sending data...", this->get_name().c_str());
|
||||
this->write_array(this->data_.data(), this->data_.size());
|
||||
}
|
||||
|
||||
void UARTButton::dump_config() { LOG_BUTTON("", "UART Button", this); }
|
||||
|
||||
} // namespace uart
|
||||
} // namespace esphome
|
24
esphome/components/uart/button/uart_button.h
Normal file
24
esphome/components/uart/button/uart_button.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/uart/uart.h"
|
||||
#include "esphome/components/button/button.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace esphome {
|
||||
namespace uart {
|
||||
|
||||
class UARTButton : public button::Button, public UARTDevice, public Component {
|
||||
public:
|
||||
void set_data(const std::vector<uint8_t> &data) { this->data_ = data; }
|
||||
|
||||
void dump_config() override;
|
||||
|
||||
protected:
|
||||
void press_action() override;
|
||||
std::vector<uint8_t> data_;
|
||||
};
|
||||
|
||||
} // namespace uart
|
||||
} // namespace esphome
|
|
@ -3504,6 +3504,10 @@ button:
|
|||
name: "restart"
|
||||
query_params:
|
||||
name: query params
|
||||
- platform: uart
|
||||
uart_id: uart_0
|
||||
name: UART button
|
||||
data: "Pressed\r\n"
|
||||
|
||||
ld2410:
|
||||
id: my_ld2410
|
||||
|
|
Loading…
Reference in a new issue