mirror of
https://github.com/esphome/esphome.git
synced 2026-02-25 12:55:30 -07:00
Merge branch 'dev' into posix_tz
This commit is contained in:
@@ -689,6 +689,14 @@ class MessageType(TypeInfo):
|
||||
def encode_func(self) -> str:
|
||||
return "encode_message"
|
||||
|
||||
@property
|
||||
def encode_content(self) -> str:
|
||||
# Singular message fields pass force=false (skip empty messages)
|
||||
# The default for encode_nested_message is force=true (for repeated fields)
|
||||
return (
|
||||
f"buffer.{self.encode_func}({self.number}, this->{self.field_name}, false);"
|
||||
)
|
||||
|
||||
@property
|
||||
def decode_length(self) -> str:
|
||||
# Override to return None for message types because we can't use template-based
|
||||
@@ -2186,7 +2194,7 @@ def build_message_type(
|
||||
|
||||
# Only generate encode method if this message needs encoding and has fields
|
||||
if needs_encode and encode:
|
||||
o = f"void {desc.name}::encode(ProtoWriteBuffer buffer) const {{"
|
||||
o = f"void {desc.name}::encode(ProtoWriteBuffer &buffer) const {{"
|
||||
if len(encode) == 1 and len(encode[0]) + len(o) + 3 < 120:
|
||||
o += f" {encode[0]} }}\n"
|
||||
else:
|
||||
@@ -2194,7 +2202,7 @@ def build_message_type(
|
||||
o += indent("\n".join(encode)) + "\n"
|
||||
o += "}\n"
|
||||
cpp += o
|
||||
prot = "void encode(ProtoWriteBuffer buffer) const override;"
|
||||
prot = "void encode(ProtoWriteBuffer &buffer) const override;"
|
||||
public_content.append(prot)
|
||||
# If no fields to encode or message doesn't need encoding, the default implementation in ProtoMessage will be used
|
||||
|
||||
|
||||
@@ -369,7 +369,7 @@ def get_logger_tags():
|
||||
"api.service",
|
||||
]
|
||||
for file in CORE_COMPONENTS_PATH.rglob("*.cpp"):
|
||||
data = file.read_text()
|
||||
data = file.read_text(encoding="utf-8")
|
||||
match = pattern.search(data)
|
||||
if match:
|
||||
tags.append(match.group(1))
|
||||
|
||||
@@ -301,7 +301,7 @@ def highlight(s):
|
||||
],
|
||||
)
|
||||
def lint_no_defines(fname, match):
|
||||
s = highlight(f"static const uint8_t {match.group(1)} = {match.group(2)};")
|
||||
s = highlight(f"static constexpr uint8_t {match.group(1)} = {match.group(2)};")
|
||||
return (
|
||||
"#define macros for integer constants are not allowed, please use "
|
||||
f"{s} style instead (replace uint8_t with the appropriate "
|
||||
@@ -494,6 +494,22 @@ def lint_no_byte_datatype(fname, match):
|
||||
)
|
||||
|
||||
|
||||
@lint_re_check(
|
||||
r"(?:std\s*::\s*string_view|#include\s*<string_view>)" + CPP_RE_EOL,
|
||||
include=cpp_include,
|
||||
)
|
||||
def lint_no_std_string_view(fname, match):
|
||||
return (
|
||||
f"{highlight('std::string_view')} is not allowed in ESPHome. "
|
||||
f"It pulls in significant STL template machinery that bloats flash on "
|
||||
f"resource-constrained embedded targets, does not work well with ArduinoJson, "
|
||||
f"and duplicates functionality already provided by {highlight('StringRef')}.\n"
|
||||
f"Please use {highlight('StringRef')} from {highlight('esphome/core/string_ref.h')} "
|
||||
f"for non-owning string references, or {highlight('const char *')} for simple cases.\n"
|
||||
f"(If strictly necessary, add `{highlight('// NOLINT')}` to the end of the line)"
|
||||
)
|
||||
|
||||
|
||||
@lint_post_check
|
||||
def lint_constants_usage():
|
||||
errs = []
|
||||
@@ -825,6 +841,39 @@ def lint_no_scanf(fname, match):
|
||||
)
|
||||
|
||||
|
||||
LOG_MULTILINE_RE = re.compile(r"ESP_LOG\w+\s*\(.*?;", re.DOTALL)
|
||||
LOG_BAD_CONTINUATION_RE = re.compile(r'\\n(?:[^ \\"\r\n\t]|"\s*\n\s*"[^ \\])')
|
||||
LOG_PERCENT_S_CONTINUATION_RE = re.compile(r'\\n(?:%s|"\s*\n\s*"%s)')
|
||||
|
||||
|
||||
@lint_content_check(include=cpp_include)
|
||||
def lint_log_multiline_continuation(fname, content):
|
||||
errs = []
|
||||
for log_match in LOG_MULTILINE_RE.finditer(content):
|
||||
log_text = log_match.group(0)
|
||||
for bad_match in LOG_BAD_CONTINUATION_RE.finditer(log_text):
|
||||
# %s may expand to a whitespace prefix at runtime, skip those
|
||||
if LOG_PERCENT_S_CONTINUATION_RE.match(log_text, bad_match.start()):
|
||||
continue
|
||||
# Calculate line number from position in full content
|
||||
abs_pos = log_match.start() + bad_match.start()
|
||||
lineno = content.count("\n", 0, abs_pos) + 1
|
||||
col = abs_pos - content.rfind("\n", 0, abs_pos)
|
||||
errs.append(
|
||||
(
|
||||
lineno,
|
||||
col,
|
||||
"Multi-line log message has a continuation line that does "
|
||||
"not start with a space. The log viewer uses leading "
|
||||
"whitespace to detect continuation lines and re-add the "
|
||||
f"log tag prefix (e.g. {highlight('[C][component:042]:')}).\n"
|
||||
"Either start the continuation with a space/indent, or "
|
||||
"split into separate ESP_LOG* calls.",
|
||||
)
|
||||
)
|
||||
return errs
|
||||
|
||||
|
||||
@lint_content_find_check(
|
||||
"ESP_LOG",
|
||||
include=["*.h", "*.tcc"],
|
||||
|
||||
@@ -43,10 +43,14 @@ def get_boards():
|
||||
name = board_info["name"]
|
||||
board = fname.stem
|
||||
variant = mcu.upper()
|
||||
boards[board] = {
|
||||
chip_variant = board_info["build"].get("chip_variant", "")
|
||||
entry = {
|
||||
"name": name,
|
||||
"variant": f"VARIANT_{variant}",
|
||||
}
|
||||
if chip_variant.endswith("_es"):
|
||||
entry["engineering_sample"] = True
|
||||
boards[board] = entry
|
||||
return boards
|
||||
|
||||
|
||||
@@ -55,6 +59,12 @@ TEMPLATE = """ "%s": {
|
||||
"variant": %s,
|
||||
},"""
|
||||
|
||||
TEMPLATE_ES = """ "%s": {
|
||||
"name": "%s",
|
||||
"variant": %s,
|
||||
"engineering_sample": True,
|
||||
},"""
|
||||
|
||||
|
||||
def main(check: bool):
|
||||
boards = get_boards()
|
||||
@@ -66,7 +76,8 @@ def main(check: bool):
|
||||
if line == "BOARDS = {":
|
||||
parts.append(line)
|
||||
parts.extend(
|
||||
TEMPLATE % (board, info["name"], info["variant"])
|
||||
(TEMPLATE_ES if info.get("engineering_sample") else TEMPLATE)
|
||||
% (board, info["name"], info["variant"])
|
||||
for board, info in sorted(boards.items())
|
||||
)
|
||||
parts.append("}")
|
||||
|
||||
Reference in New Issue
Block a user