1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-01 10:52:19 +01:00

[api] Simplify generated authentication check code (#9806)

This commit is contained in:
J. Nick Koston
2025-07-23 17:18:01 -10:00
committed by GitHub
parent 04d9698681
commit f863189f96
2 changed files with 18 additions and 31 deletions

View File

@@ -2261,19 +2261,16 @@ static const char *const TAG = "api.service";
else:
check_func = "this->check_connection_setup_()"
body = f"if ({check_func}) {{\n"
# Add the actual handler code, indented
handler_body = ""
if is_void:
handler_body = f"this->{func}(msg);\n"
# For void methods, just wrap with auth check
body = f"if ({check_func}) {{\n"
body += f" this->{func}(msg);\n"
body += "}\n"
else:
handler_body = f"if (!this->send_{func}_response(msg)) {{\n"
handler_body += " this->on_fatal_error();\n"
handler_body += "}\n"
body += indent(handler_body) + "\n"
body += "}\n"
# For non-void methods, combine auth check and send response check
body = f"if ({check_func} && !this->send_{func}_response(msg)) {{\n"
body += " this->on_fatal_error();\n"
body += "}\n"
else:
# No auth check needed, just call the handler
body = ""