1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-06 05:12:21 +01:00
This commit is contained in:
J. Nick Koston
2025-07-21 19:39:23 -10:00
parent 97525cfe87
commit 72fd984d4b
3 changed files with 142 additions and 623 deletions

View File

@@ -575,13 +575,7 @@ class StringType(TypeInfo):
# For SOURCE_SERVER, always use StringRef
if not self._needs_decode:
return (
f"if (!this->{self.field_name}_ref_.empty()) {{"
f' out.append("\'").append(this->{self.field_name}_ref_.c_str()).append("\'");'
f"}} else {{"
f' out.append("\'").append("").append("\'");'
f"}}"
)
return f"append_quoted_string(out, this->{self.field_name}_ref_);"
# For SOURCE_BOTH, check if StringRef is set (sending) or use string (received)
return (
@@ -1868,6 +1862,15 @@ namespace api {
namespace esphome {
namespace api {
// Helper function to append a quoted string, handling empty StringRef
static inline void append_quoted_string(std::string &out, const StringRef &ref) {
out.append("'");
if (!ref.empty()) {
out.append(ref.c_str());
}
out.append("'");
}
"""
content += "namespace enums {\n\n"