mirror of
https://github.com/esphome/esphome.git
synced 2025-09-13 08:42:18 +01:00
Merge branch 'reduce_duplicate_gen_code_api' into integration
This commit is contained in:
@@ -17,25 +17,6 @@ class APIServerConnectionBase : public ProtoService {
|
||||
public:
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool check_connection_setup_() {
|
||||
if (!this->is_connection_setup()) {
|
||||
this->on_no_setup_connection();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool check_authenticated_() {
|
||||
if (!this->check_connection_setup_()) {
|
||||
return false;
|
||||
}
|
||||
if (!this->is_authenticated()) {
|
||||
this->on_unauthenticated_access();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public:
|
||||
template<typename T> bool send_message(const T &msg) {
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
|
@@ -379,6 +379,26 @@ class ProtoService {
|
||||
// Send the buffer
|
||||
return this->send_buffer(buffer, message_type);
|
||||
}
|
||||
|
||||
// Authentication helper methods
|
||||
bool check_connection_setup_() {
|
||||
if (!this->is_connection_setup()) {
|
||||
this->on_no_setup_connection();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_authenticated_() {
|
||||
if (!this->check_connection_setup_()) {
|
||||
return false;
|
||||
}
|
||||
if (!this->is_authenticated()) {
|
||||
this->on_unauthenticated_access();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
|
@@ -1352,26 +1352,7 @@ def main() -> None:
|
||||
hpp += " public:\n"
|
||||
hpp += "#endif\n\n"
|
||||
|
||||
# Add authentication check helper methods
|
||||
hpp += " protected:\n"
|
||||
hpp += " bool check_connection_setup_() {\n"
|
||||
hpp += " if (!this->is_connection_setup()) {\n"
|
||||
hpp += " this->on_no_setup_connection();\n"
|
||||
hpp += " return false;\n"
|
||||
hpp += " }\n"
|
||||
hpp += " return true;\n"
|
||||
hpp += " }\n"
|
||||
hpp += " bool check_authenticated_() {\n"
|
||||
hpp += " if (!this->check_connection_setup_()) {\n"
|
||||
hpp += " return false;\n"
|
||||
hpp += " }\n"
|
||||
hpp += " if (!this->is_authenticated()) {\n"
|
||||
hpp += " this->on_unauthenticated_access();\n"
|
||||
hpp += " return false;\n"
|
||||
hpp += " }\n"
|
||||
hpp += " return true;\n"
|
||||
hpp += " }\n"
|
||||
hpp += " public:\n\n"
|
||||
hpp += " public:\n"
|
||||
|
||||
# Add generic send_message method
|
||||
hpp += " template<typename T>\n"
|
||||
|
Reference in New Issue
Block a user