mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 11:47:30 +01:00
Allow empty UART debug: option, logging in hex format by default (#2771)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Co-authored-by: Maurice Makaay <account-github@makaay.nl>
This commit is contained in:
parent
ccfa1e23f0
commit
ceb9b1d1ff
@ -3,6 +3,7 @@ from typing import Optional
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
import esphome.final_validate as fv
|
||||
from esphome.yaml_util import make_data_base
|
||||
from esphome import pins, automation
|
||||
from esphome.const import (
|
||||
CONF_BAUD_RATE,
|
||||
@ -24,6 +25,7 @@ from esphome.const import (
|
||||
CONF_DELIMITER,
|
||||
CONF_DUMMY_RECEIVER,
|
||||
CONF_DUMMY_RECEIVER_ID,
|
||||
CONF_LAMBDA,
|
||||
)
|
||||
from esphome.core import CORE
|
||||
|
||||
@ -94,7 +96,26 @@ UART_DIRECTIONS = {
|
||||
"BOTH": UARTDirection.UART_DIRECTION_BOTH,
|
||||
}
|
||||
|
||||
AFTER_DEFAULTS = {CONF_BYTES: 256, CONF_TIMEOUT: "100ms"}
|
||||
# The reason for having CONF_BYTES at 150 by default:
|
||||
#
|
||||
# The log message buffer size is 512 bytes by default. About 35 bytes are
|
||||
# used for the log prefix. That leaves us with 477 bytes for logging data.
|
||||
# The default log output is hex, which uses 3 characters per represented
|
||||
# byte (2 hex chars + 1 separator). That means that 477 / 3 = 159 bytes
|
||||
# can be represented in a single log line. Using 150, because people love
|
||||
# round numbers.
|
||||
AFTER_DEFAULTS = {CONF_BYTES: 150, CONF_TIMEOUT: "100ms"}
|
||||
|
||||
# By default, log in hex format when no specific sequence is provided.
|
||||
DEFAULT_DEBUG_OUTPUT = "UARTDebug::log_hex(direction, bytes, ':');"
|
||||
DEFAULT_SEQUENCE = [{CONF_LAMBDA: make_data_base(DEFAULT_DEBUG_OUTPUT)}]
|
||||
|
||||
|
||||
def maybe_empty_debug(value):
|
||||
if value is None:
|
||||
value = {}
|
||||
return DEBUG_SCHEMA(value)
|
||||
|
||||
|
||||
DEBUG_SCHEMA = cv.Schema(
|
||||
{
|
||||
@ -113,7 +134,9 @@ DEBUG_SCHEMA = cv.Schema(
|
||||
cv.Optional(CONF_DELIMITER): cv.templatable(validate_raw_data),
|
||||
}
|
||||
),
|
||||
cv.Required(CONF_SEQUENCE): automation.validate_automation(),
|
||||
cv.Optional(
|
||||
CONF_SEQUENCE, default=DEFAULT_SEQUENCE
|
||||
): automation.validate_automation(),
|
||||
cv.Optional(CONF_DUMMY_RECEIVER, default=False): cv.boolean,
|
||||
cv.GenerateID(CONF_DUMMY_RECEIVER_ID): cv.declare_id(UARTDummyReceiver),
|
||||
}
|
||||
@ -135,7 +158,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
cv.Optional(CONF_INVERT): cv.invalid(
|
||||
"This option has been removed. Please instead use invert in the tx/rx pin schemas."
|
||||
),
|
||||
cv.Optional(CONF_DEBUG): DEBUG_SCHEMA,
|
||||
cv.Optional(CONF_DEBUG): maybe_empty_debug,
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA),
|
||||
cv.has_at_least_one_key(CONF_TX_PIN, CONF_RX_PIN),
|
||||
|
@ -254,6 +254,8 @@ uart:
|
||||
tx_pin: GPIO4
|
||||
rx_pin: GPIO5
|
||||
baud_rate: 38400
|
||||
# Specifically added for testing debug with no options at all.
|
||||
debug:
|
||||
|
||||
modbus:
|
||||
uart_id: uart1
|
||||
|
Loading…
Reference in New Issue
Block a user