[api] Sync uses_password field_ifdef optimization from aioesphomeapi (#9756)

This commit is contained in:
J. Nick Koston 2025-07-20 18:59:48 -10:00 committed by GitHub
parent fc286c8bf4
commit 305667b06d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 9 additions and 3 deletions

View File

@ -203,7 +203,7 @@ message DeviceInfoResponse {
option (id) = 10;
option (source) = SOURCE_SERVER;
bool uses_password = 1;
bool uses_password = 1 [(field_ifdef) = "USE_API_PASSWORD"];
// The name of the node, given by "App.set_name()"
string name = 2;

View File

@ -1432,8 +1432,6 @@ DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) {
DeviceInfoResponse resp{};
#ifdef USE_API_PASSWORD
resp.uses_password = true;
#else
resp.uses_password = false;
#endif
resp.name = App.get_name();
resp.friendly_name = App.get_friendly_name();

View File

@ -80,7 +80,9 @@ void DeviceInfo::calculate_size(uint32_t &total_size) const {
}
#endif
void DeviceInfoResponse::encode(ProtoWriteBuffer buffer) const {
#ifdef USE_API_PASSWORD
buffer.encode_bool(1, this->uses_password);
#endif
buffer.encode_string(2, this->name);
buffer.encode_string(3, this->mac_address);
buffer.encode_string(4, this->esphome_version);
@ -130,7 +132,9 @@ void DeviceInfoResponse::encode(ProtoWriteBuffer buffer) const {
#endif
}
void DeviceInfoResponse::calculate_size(uint32_t &total_size) const {
#ifdef USE_API_PASSWORD
ProtoSize::add_bool_field(total_size, 1, this->uses_password);
#endif
ProtoSize::add_string_field(total_size, 1, this->name);
ProtoSize::add_string_field(total_size, 1, this->mac_address);
ProtoSize::add_string_field(total_size, 1, this->esphome_version);

View File

@ -474,7 +474,9 @@ class DeviceInfoResponse : public ProtoMessage {
#ifdef HAS_PROTO_MESSAGE_DUMP
const char *message_name() const override { return "device_info_response"; }
#endif
#ifdef USE_API_PASSWORD
bool uses_password{false};
#endif
std::string name{};
std::string mac_address{};
std::string esphome_version{};

View File

@ -647,10 +647,12 @@ void DeviceInfo::dump_to(std::string &out) const {
void DeviceInfoResponse::dump_to(std::string &out) const {
__attribute__((unused)) char buffer[64];
out.append("DeviceInfoResponse {\n");
#ifdef USE_API_PASSWORD
out.append(" uses_password: ");
out.append(YESNO(this->uses_password));
out.append("\n");
#endif
out.append(" name: ");
out.append("'").append(this->name).append("'");
out.append("\n");