mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Merge branch 'integration' into memory_api
This commit is contained in:
		| @@ -57,6 +57,7 @@ void ConnectResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_bool | |||||||
| void ConnectResponse::calculate_size(uint32_t &total_size) const { | void ConnectResponse::calculate_size(uint32_t &total_size) const { | ||||||
|   ProtoSize::add_bool_field(total_size, 1, this->invalid_password); |   ProtoSize::add_bool_field(total_size, 1, this->invalid_password); | ||||||
| } | } | ||||||
|  | #ifdef USE_AREAS | ||||||
| void AreaInfo::encode(ProtoWriteBuffer buffer) const { | void AreaInfo::encode(ProtoWriteBuffer buffer) const { | ||||||
|   buffer.encode_uint32(1, this->area_id); |   buffer.encode_uint32(1, this->area_id); | ||||||
|   buffer.encode_string(2, this->name); |   buffer.encode_string(2, this->name); | ||||||
| @@ -65,6 +66,8 @@ void AreaInfo::calculate_size(uint32_t &total_size) const { | |||||||
|   ProtoSize::add_uint32_field(total_size, 1, this->area_id); |   ProtoSize::add_uint32_field(total_size, 1, this->area_id); | ||||||
|   ProtoSize::add_string_field(total_size, 1, this->name); |   ProtoSize::add_string_field(total_size, 1, this->name); | ||||||
| } | } | ||||||
|  | #endif | ||||||
|  | #ifdef USE_DEVICES | ||||||
| void DeviceInfo::encode(ProtoWriteBuffer buffer) const { | void DeviceInfo::encode(ProtoWriteBuffer buffer) const { | ||||||
|   buffer.encode_uint32(1, this->device_id); |   buffer.encode_uint32(1, this->device_id); | ||||||
|   buffer.encode_string(2, this->name); |   buffer.encode_string(2, this->name); | ||||||
| @@ -75,6 +78,7 @@ void DeviceInfo::calculate_size(uint32_t &total_size) const { | |||||||
|   ProtoSize::add_string_field(total_size, 1, this->name); |   ProtoSize::add_string_field(total_size, 1, this->name); | ||||||
|   ProtoSize::add_uint32_field(total_size, 1, this->area_id); |   ProtoSize::add_uint32_field(total_size, 1, this->area_id); | ||||||
| } | } | ||||||
|  | #endif | ||||||
| void DeviceInfoResponse::encode(ProtoWriteBuffer buffer) const { | void DeviceInfoResponse::encode(ProtoWriteBuffer buffer) const { | ||||||
|   buffer.encode_bool(1, this->uses_password); |   buffer.encode_bool(1, this->uses_password); | ||||||
|   buffer.encode_string(2, this->name); |   buffer.encode_string(2, this->name); | ||||||
|   | |||||||
| @@ -438,6 +438,7 @@ class DeviceInfoRequest : public ProtoDecodableMessage { | |||||||
|  |  | ||||||
|  protected: |  protected: | ||||||
| }; | }; | ||||||
|  | #ifdef USE_AREAS | ||||||
| class AreaInfo : public ProtoMessage { | class AreaInfo : public ProtoMessage { | ||||||
|  public: |  public: | ||||||
|   uint32_t area_id{0}; |   uint32_t area_id{0}; | ||||||
| @@ -450,6 +451,8 @@ class AreaInfo : public ProtoMessage { | |||||||
|  |  | ||||||
|  protected: |  protected: | ||||||
| }; | }; | ||||||
|  | #endif | ||||||
|  | #ifdef USE_DEVICES | ||||||
| class DeviceInfo : public ProtoMessage { | class DeviceInfo : public ProtoMessage { | ||||||
|  public: |  public: | ||||||
|   uint32_t device_id{0}; |   uint32_t device_id{0}; | ||||||
| @@ -463,6 +466,7 @@ class DeviceInfo : public ProtoMessage { | |||||||
|  |  | ||||||
|  protected: |  protected: | ||||||
| }; | }; | ||||||
|  | #endif | ||||||
| class DeviceInfoResponse : public ProtoMessage { | class DeviceInfoResponse : public ProtoMessage { | ||||||
|  public: |  public: | ||||||
|   static constexpr uint8_t MESSAGE_TYPE = 10; |   static constexpr uint8_t MESSAGE_TYPE = 10; | ||||||
|   | |||||||
| @@ -609,6 +609,7 @@ void DisconnectResponse::dump_to(std::string &out) const { out.append("Disconnec | |||||||
| void PingRequest::dump_to(std::string &out) const { out.append("PingRequest {}"); } | void PingRequest::dump_to(std::string &out) const { out.append("PingRequest {}"); } | ||||||
| void PingResponse::dump_to(std::string &out) const { out.append("PingResponse {}"); } | void PingResponse::dump_to(std::string &out) const { out.append("PingResponse {}"); } | ||||||
| void DeviceInfoRequest::dump_to(std::string &out) const { out.append("DeviceInfoRequest {}"); } | void DeviceInfoRequest::dump_to(std::string &out) const { out.append("DeviceInfoRequest {}"); } | ||||||
|  | #ifdef USE_AREAS | ||||||
| void AreaInfo::dump_to(std::string &out) const { | void AreaInfo::dump_to(std::string &out) const { | ||||||
|   __attribute__((unused)) char buffer[64]; |   __attribute__((unused)) char buffer[64]; | ||||||
|   out.append("AreaInfo {\n"); |   out.append("AreaInfo {\n"); | ||||||
| @@ -622,6 +623,8 @@ void AreaInfo::dump_to(std::string &out) const { | |||||||
|   out.append("\n"); |   out.append("\n"); | ||||||
|   out.append("}"); |   out.append("}"); | ||||||
| } | } | ||||||
|  | #endif | ||||||
|  | #ifdef USE_DEVICES | ||||||
| void DeviceInfo::dump_to(std::string &out) const { | void DeviceInfo::dump_to(std::string &out) const { | ||||||
|   __attribute__((unused)) char buffer[64]; |   __attribute__((unused)) char buffer[64]; | ||||||
|   out.append("DeviceInfo {\n"); |   out.append("DeviceInfo {\n"); | ||||||
| @@ -640,6 +643,7 @@ void DeviceInfo::dump_to(std::string &out) const { | |||||||
|   out.append("\n"); |   out.append("\n"); | ||||||
|   out.append("}"); |   out.append("}"); | ||||||
| } | } | ||||||
|  | #endif | ||||||
| void DeviceInfoResponse::dump_to(std::string &out) const { | void DeviceInfoResponse::dump_to(std::string &out) const { | ||||||
|   __attribute__((unused)) char buffer[64]; |   __attribute__((unused)) char buffer[64]; | ||||||
|   out.append("DeviceInfoResponse {\n"); |   out.append("DeviceInfoResponse {\n"); | ||||||
|   | |||||||
| @@ -996,6 +996,11 @@ def build_type_usage_map( | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     # Analyze field usage |     # Analyze field usage | ||||||
|  |     # Also track field_ifdef for message types | ||||||
|  |     message_field_ifdefs: dict[ | ||||||
|  |         str, set[str | None] | ||||||
|  |     ] = {}  # message_name -> set of field_ifdefs that use it | ||||||
|  |  | ||||||
|     for message in file_desc.message_type: |     for message in file_desc.message_type: | ||||||
|         # Skip deprecated messages entirely |         # Skip deprecated messages entirely | ||||||
|         if message.options.deprecated: |         if message.options.deprecated: | ||||||
| @@ -1017,6 +1022,9 @@ def build_type_usage_map( | |||||||
|             elif field.type == 11:  # TYPE_MESSAGE |             elif field.type == 11:  # TYPE_MESSAGE | ||||||
|                 message_usage.setdefault(type_name, set()).add(message.name) |                 message_usage.setdefault(type_name, set()).add(message.name) | ||||||
|                 used_messages.add(type_name) |                 used_messages.add(type_name) | ||||||
|  |                 # Also track the field_ifdef if present | ||||||
|  |                 field_ifdef = get_field_opt(field, pb.field_ifdef) | ||||||
|  |                 message_field_ifdefs.setdefault(type_name, set()).add(field_ifdef) | ||||||
|  |  | ||||||
|     # Helper to get unique ifdef from a set of messages |     # Helper to get unique ifdef from a set of messages | ||||||
|     def get_unique_ifdef(message_names: set[str]) -> str | None: |     def get_unique_ifdef(message_names: set[str]) -> str | None: | ||||||
| @@ -1042,11 +1050,18 @@ def build_type_usage_map( | |||||||
|             message_ifdef_map[message.name] = explicit_ifdef |             message_ifdef_map[message.name] = explicit_ifdef | ||||||
|         elif message.name in message_usage: |         elif message.name in message_usage: | ||||||
|             # Inherit ifdef if all parent messages have the same one |             # Inherit ifdef if all parent messages have the same one | ||||||
|             message_ifdef_map[message.name] = get_unique_ifdef( |             if parent_ifdef := get_unique_ifdef(message_usage[message.name]): | ||||||
|                 message_usage[message.name] |                 message_ifdef_map[message.name] = parent_ifdef | ||||||
|  |             elif message.name in message_field_ifdefs: | ||||||
|  |                 # If no parent message ifdef, check if all fields using this message have the same field_ifdef | ||||||
|  |                 field_ifdefs = message_field_ifdefs[message.name] - {None} | ||||||
|  |                 message_ifdef_map[message.name] = ( | ||||||
|  |                     field_ifdefs.pop() if len(field_ifdefs) == 1 else None | ||||||
|                 ) |                 ) | ||||||
|             else: |             else: | ||||||
|                 message_ifdef_map[message.name] = None |                 message_ifdef_map[message.name] = None | ||||||
|  |         else: | ||||||
|  |             message_ifdef_map[message.name] = None | ||||||
|  |  | ||||||
|     # Second pass: propagate ifdefs recursively |     # Second pass: propagate ifdefs recursively | ||||||
|     # Keep iterating until no more changes are made |     # Keep iterating until no more changes are made | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user