esphome 2025.7.0b1__py3-none-any.whl → 2025.7.0b3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. esphome/components/api/__init__.py +19 -5
  2. esphome/components/api/api_connection.cpp +53 -175
  3. esphome/components/api/api_connection.h +28 -25
  4. esphome/components/api/api_frame_helper.cpp +2 -3
  5. esphome/components/api/api_frame_helper.h +7 -9
  6. esphome/components/api/api_pb2.cpp +1862 -5133
  7. esphome/components/api/api_pb2.h +291 -533
  8. esphome/components/api/api_pb2_dump.cpp +99 -0
  9. esphome/components/api/api_pb2_service.cpp +4 -0
  10. esphome/components/api/api_pb2_service.h +6 -0
  11. esphome/components/api/api_server.cpp +2 -9
  12. esphome/components/api/api_server.h +7 -33
  13. esphome/components/api/custom_api_device.h +8 -0
  14. esphome/components/api/list_entities.cpp +2 -0
  15. esphome/components/api/list_entities.h +3 -1
  16. esphome/components/api/proto.h +506 -23
  17. esphome/components/api/user_services.h +2 -0
  18. esphome/components/debug/debug_esp32.cpp +2 -0
  19. esphome/components/esp32/__init__.py +1 -0
  20. esphome/components/esp32_camera/__init__.py +1 -1
  21. esphome/components/esp32_touch/esp32_touch_v1.cpp +12 -10
  22. esphome/components/esp8266/__init__.py +1 -0
  23. esphome/components/esp_ldo/__init__.py +10 -8
  24. esphome/components/esp_ldo/esp_ldo.h +3 -0
  25. esphome/components/gpio/binary_sensor/__init__.py +24 -3
  26. esphome/components/host/__init__.py +1 -0
  27. esphome/components/i2s_audio/speaker/__init__.py +1 -1
  28. esphome/components/ld2410/ld2410.cpp +12 -28
  29. esphome/components/ld2420/binary_sensor/ld2420_binary_sensor.cpp +2 -2
  30. esphome/components/ld2420/button/reconfig_buttons.cpp +1 -1
  31. esphome/components/ld2420/ld2420.cpp +66 -57
  32. esphome/components/ld2420/ld2420.h +9 -11
  33. esphome/components/ld2420/number/gate_config_number.cpp +1 -1
  34. esphome/components/ld2420/select/operating_mode_select.cpp +1 -1
  35. esphome/components/ld2420/sensor/ld2420_sensor.cpp +2 -2
  36. esphome/components/ld2420/text_sensor/text_sensor.cpp +2 -2
  37. esphome/components/libretiny/__init__.py +1 -0
  38. esphome/components/lvgl/widgets/meter.py +20 -13
  39. esphome/components/mqtt/mqtt_backend_esp32.cpp +6 -2
  40. esphome/components/packet_transport/packet_transport.cpp +3 -0
  41. esphome/components/rp2040/__init__.py +1 -0
  42. esphome/components/substitutions/__init__.py +5 -2
  43. esphome/components/sx126x/__init__.py +3 -3
  44. esphome/components/sx127x/__init__.py +2 -2
  45. esphome/components/usb_host/usb_host_client.cpp +10 -10
  46. esphome/components/usb_uart/cp210x.cpp +1 -1
  47. esphome/components/usb_uart/usb_uart.cpp +41 -44
  48. esphome/components/usb_uart/usb_uart.h +4 -3
  49. esphome/const.py +1 -1
  50. esphome/core/component.cpp +8 -8
  51. esphome/core/component_iterator.cpp +4 -2
  52. esphome/core/component_iterator.h +3 -3
  53. esphome/core/defines.h +1 -1
  54. esphome/core/entity_helpers.py +6 -0
  55. esphome/core/helpers.h +1 -1
  56. esphome/core/scheduler.cpp +9 -12
  57. esphome/core/scheduler.h +0 -3
  58. esphome/wizard.py +1 -1
  59. {esphome-2025.7.0b1.dist-info → esphome-2025.7.0b3.dist-info}/METADATA +2 -2
  60. {esphome-2025.7.0b1.dist-info → esphome-2025.7.0b3.dist-info}/RECORD +64 -65
  61. esphome/components/api/api_pb2_size.h +0 -359
  62. {esphome-2025.7.0b1.dist-info → esphome-2025.7.0b3.dist-info}/WHEEL +0 -0
  63. {esphome-2025.7.0b1.dist-info → esphome-2025.7.0b3.dist-info}/entry_points.txt +0 -0
  64. {esphome-2025.7.0b1.dist-info → esphome-2025.7.0b3.dist-info}/licenses/LICENSE +0 -0
  65. {esphome-2025.7.0b1.dist-info → esphome-2025.7.0b3.dist-info}/top_level.txt +0 -0
@@ -1,359 +0,0 @@
1
- #pragma once
2
-
3
- #include "proto.h"
4
- #include <cstdint>
5
- #include <string>
6
-
7
- namespace esphome {
8
- namespace api {
9
-
10
- class ProtoSize {
11
- public:
12
- /**
13
- * @brief ProtoSize class for Protocol Buffer serialization size calculation
14
- *
15
- * This class provides static methods to calculate the exact byte counts needed
16
- * for encoding various Protocol Buffer field types. All methods are designed to be
17
- * efficient for the common case where many fields have default values.
18
- *
19
- * Implements Protocol Buffer encoding size calculation according to:
20
- * https://protobuf.dev/programming-guides/encoding/
21
- *
22
- * Key features:
23
- * - Early-return optimization for zero/default values
24
- * - Direct total_size updates to avoid unnecessary additions
25
- * - Specialized handling for different field types according to protobuf spec
26
- * - Templated helpers for repeated fields and messages
27
- */
28
-
29
- /**
30
- * @brief Calculates the size in bytes needed to encode a uint32_t value as a varint
31
- *
32
- * @param value The uint32_t value to calculate size for
33
- * @return The number of bytes needed to encode the value
34
- */
35
- static inline uint32_t varint(uint32_t value) {
36
- // Optimized varint size calculation using leading zeros
37
- // Each 7 bits requires one byte in the varint encoding
38
- if (value < 128)
39
- return 1; // 7 bits, common case for small values
40
-
41
- // For larger values, count bytes needed based on the position of the highest bit set
42
- if (value < 16384) {
43
- return 2; // 14 bits
44
- } else if (value < 2097152) {
45
- return 3; // 21 bits
46
- } else if (value < 268435456) {
47
- return 4; // 28 bits
48
- } else {
49
- return 5; // 32 bits (maximum for uint32_t)
50
- }
51
- }
52
-
53
- /**
54
- * @brief Calculates the size in bytes needed to encode a uint64_t value as a varint
55
- *
56
- * @param value The uint64_t value to calculate size for
57
- * @return The number of bytes needed to encode the value
58
- */
59
- static inline uint32_t varint(uint64_t value) {
60
- // Handle common case of values fitting in uint32_t (vast majority of use cases)
61
- if (value <= UINT32_MAX) {
62
- return varint(static_cast<uint32_t>(value));
63
- }
64
-
65
- // For larger values, determine size based on highest bit position
66
- if (value < (1ULL << 35)) {
67
- return 5; // 35 bits
68
- } else if (value < (1ULL << 42)) {
69
- return 6; // 42 bits
70
- } else if (value < (1ULL << 49)) {
71
- return 7; // 49 bits
72
- } else if (value < (1ULL << 56)) {
73
- return 8; // 56 bits
74
- } else if (value < (1ULL << 63)) {
75
- return 9; // 63 bits
76
- } else {
77
- return 10; // 64 bits (maximum for uint64_t)
78
- }
79
- }
80
-
81
- /**
82
- * @brief Calculates the size in bytes needed to encode an int32_t value as a varint
83
- *
84
- * Special handling is needed for negative values, which are sign-extended to 64 bits
85
- * in Protocol Buffers, resulting in a 10-byte varint.
86
- *
87
- * @param value The int32_t value to calculate size for
88
- * @return The number of bytes needed to encode the value
89
- */
90
- static inline uint32_t varint(int32_t value) {
91
- // Negative values are sign-extended to 64 bits in protocol buffers,
92
- // which always results in a 10-byte varint for negative int32
93
- if (value < 0) {
94
- return 10; // Negative int32 is always 10 bytes long
95
- }
96
- // For non-negative values, use the uint32_t implementation
97
- return varint(static_cast<uint32_t>(value));
98
- }
99
-
100
- /**
101
- * @brief Calculates the size in bytes needed to encode an int64_t value as a varint
102
- *
103
- * @param value The int64_t value to calculate size for
104
- * @return The number of bytes needed to encode the value
105
- */
106
- static inline uint32_t varint(int64_t value) {
107
- // For int64_t, we convert to uint64_t and calculate the size
108
- // This works because the bit pattern determines the encoding size,
109
- // and we've handled negative int32 values as a special case above
110
- return varint(static_cast<uint64_t>(value));
111
- }
112
-
113
- /**
114
- * @brief Calculates the size in bytes needed to encode a field ID and wire type
115
- *
116
- * @param field_id The field identifier
117
- * @param type The wire type value (from the WireType enum in the protobuf spec)
118
- * @return The number of bytes needed to encode the field ID and wire type
119
- */
120
- static inline uint32_t field(uint32_t field_id, uint32_t type) {
121
- uint32_t tag = (field_id << 3) | (type & 0b111);
122
- return varint(tag);
123
- }
124
-
125
- /**
126
- * @brief Common parameters for all add_*_field methods
127
- *
128
- * All add_*_field methods follow these common patterns:
129
- *
130
- * @param total_size Reference to the total message size to update
131
- * @param field_id_size Pre-calculated size of the field ID in bytes
132
- * @param value The value to calculate size for (type varies)
133
- * @param force Whether to calculate size even if the value is default/zero/empty
134
- *
135
- * Each method follows this implementation pattern:
136
- * 1. Skip calculation if value is default (0, false, empty) and not forced
137
- * 2. Calculate the size based on the field's encoding rules
138
- * 3. Add the field_id_size + calculated value size to total_size
139
- */
140
-
141
- /**
142
- * @brief Calculates and adds the size of an int32 field to the total message size
143
- */
144
- static inline void add_int32_field(uint32_t &total_size, uint32_t field_id_size, int32_t value, bool force = false) {
145
- // Skip calculation if value is zero and not forced
146
- if (value == 0 && !force) {
147
- return; // No need to update total_size
148
- }
149
-
150
- // Calculate and directly add to total_size
151
- if (value < 0) {
152
- // Negative values are encoded as 10-byte varints in protobuf
153
- total_size += field_id_size + 10;
154
- } else {
155
- // For non-negative values, use the standard varint size
156
- total_size += field_id_size + varint(static_cast<uint32_t>(value));
157
- }
158
- }
159
-
160
- /**
161
- * @brief Calculates and adds the size of a uint32 field to the total message size
162
- */
163
- static inline void add_uint32_field(uint32_t &total_size, uint32_t field_id_size, uint32_t value,
164
- bool force = false) {
165
- // Skip calculation if value is zero and not forced
166
- if (value == 0 && !force) {
167
- return; // No need to update total_size
168
- }
169
-
170
- // Calculate and directly add to total_size
171
- total_size += field_id_size + varint(value);
172
- }
173
-
174
- /**
175
- * @brief Calculates and adds the size of a boolean field to the total message size
176
- */
177
- static inline void add_bool_field(uint32_t &total_size, uint32_t field_id_size, bool value, bool force = false) {
178
- // Skip calculation if value is false and not forced
179
- if (!value && !force) {
180
- return; // No need to update total_size
181
- }
182
-
183
- // Boolean fields always use 1 byte when true
184
- total_size += field_id_size + 1;
185
- }
186
-
187
- /**
188
- * @brief Calculates and adds the size of a fixed field to the total message size
189
- *
190
- * Fixed fields always take exactly N bytes (4 for fixed32/float, 8 for fixed64/double).
191
- *
192
- * @tparam NumBytes The number of bytes for this fixed field (4 or 8)
193
- * @param is_nonzero Whether the value is non-zero
194
- */
195
- template<uint32_t NumBytes>
196
- static inline void add_fixed_field(uint32_t &total_size, uint32_t field_id_size, bool is_nonzero,
197
- bool force = false) {
198
- // Skip calculation if value is zero and not forced
199
- if (!is_nonzero && !force) {
200
- return; // No need to update total_size
201
- }
202
-
203
- // Fixed fields always take exactly NumBytes
204
- total_size += field_id_size + NumBytes;
205
- }
206
-
207
- /**
208
- * @brief Calculates and adds the size of an enum field to the total message size
209
- *
210
- * Enum fields are encoded as uint32 varints.
211
- */
212
- static inline void add_enum_field(uint32_t &total_size, uint32_t field_id_size, uint32_t value, bool force = false) {
213
- // Skip calculation if value is zero and not forced
214
- if (value == 0 && !force) {
215
- return; // No need to update total_size
216
- }
217
-
218
- // Enums are encoded as uint32
219
- total_size += field_id_size + varint(value);
220
- }
221
-
222
- /**
223
- * @brief Calculates and adds the size of a sint32 field to the total message size
224
- *
225
- * Sint32 fields use ZigZag encoding, which is more efficient for negative values.
226
- */
227
- static inline void add_sint32_field(uint32_t &total_size, uint32_t field_id_size, int32_t value, bool force = false) {
228
- // Skip calculation if value is zero and not forced
229
- if (value == 0 && !force) {
230
- return; // No need to update total_size
231
- }
232
-
233
- // ZigZag encoding for sint32: (n << 1) ^ (n >> 31)
234
- uint32_t zigzag = (static_cast<uint32_t>(value) << 1) ^ (static_cast<uint32_t>(value >> 31));
235
- total_size += field_id_size + varint(zigzag);
236
- }
237
-
238
- /**
239
- * @brief Calculates and adds the size of an int64 field to the total message size
240
- */
241
- static inline void add_int64_field(uint32_t &total_size, uint32_t field_id_size, int64_t value, bool force = false) {
242
- // Skip calculation if value is zero and not forced
243
- if (value == 0 && !force) {
244
- return; // No need to update total_size
245
- }
246
-
247
- // Calculate and directly add to total_size
248
- total_size += field_id_size + varint(value);
249
- }
250
-
251
- /**
252
- * @brief Calculates and adds the size of a uint64 field to the total message size
253
- */
254
- static inline void add_uint64_field(uint32_t &total_size, uint32_t field_id_size, uint64_t value,
255
- bool force = false) {
256
- // Skip calculation if value is zero and not forced
257
- if (value == 0 && !force) {
258
- return; // No need to update total_size
259
- }
260
-
261
- // Calculate and directly add to total_size
262
- total_size += field_id_size + varint(value);
263
- }
264
-
265
- /**
266
- * @brief Calculates and adds the size of a sint64 field to the total message size
267
- *
268
- * Sint64 fields use ZigZag encoding, which is more efficient for negative values.
269
- */
270
- static inline void add_sint64_field(uint32_t &total_size, uint32_t field_id_size, int64_t value, bool force = false) {
271
- // Skip calculation if value is zero and not forced
272
- if (value == 0 && !force) {
273
- return; // No need to update total_size
274
- }
275
-
276
- // ZigZag encoding for sint64: (n << 1) ^ (n >> 63)
277
- uint64_t zigzag = (static_cast<uint64_t>(value) << 1) ^ (static_cast<uint64_t>(value >> 63));
278
- total_size += field_id_size + varint(zigzag);
279
- }
280
-
281
- /**
282
- * @brief Calculates and adds the size of a string/bytes field to the total message size
283
- */
284
- static inline void add_string_field(uint32_t &total_size, uint32_t field_id_size, const std::string &str,
285
- bool force = false) {
286
- // Skip calculation if string is empty and not forced
287
- if (str.empty() && !force) {
288
- return; // No need to update total_size
289
- }
290
-
291
- // Calculate and directly add to total_size
292
- const uint32_t str_size = static_cast<uint32_t>(str.size());
293
- total_size += field_id_size + varint(str_size) + str_size;
294
- }
295
-
296
- /**
297
- * @brief Calculates and adds the size of a nested message field to the total message size
298
- *
299
- * This helper function directly updates the total_size reference if the nested size
300
- * is greater than zero or force is true.
301
- *
302
- * @param nested_size The pre-calculated size of the nested message
303
- */
304
- static inline void add_message_field(uint32_t &total_size, uint32_t field_id_size, uint32_t nested_size,
305
- bool force = false) {
306
- // Skip calculation if nested message is empty and not forced
307
- if (nested_size == 0 && !force) {
308
- return; // No need to update total_size
309
- }
310
-
311
- // Calculate and directly add to total_size
312
- // Field ID + length varint + nested message content
313
- total_size += field_id_size + varint(nested_size) + nested_size;
314
- }
315
-
316
- /**
317
- * @brief Calculates and adds the size of a nested message field to the total message size
318
- *
319
- * This version takes a ProtoMessage object, calculates its size internally,
320
- * and updates the total_size reference. This eliminates the need for a temporary variable
321
- * at the call site.
322
- *
323
- * @param message The nested message object
324
- */
325
- static inline void add_message_object(uint32_t &total_size, uint32_t field_id_size, const ProtoMessage &message,
326
- bool force = false) {
327
- uint32_t nested_size = 0;
328
- message.calculate_size(nested_size);
329
-
330
- // Use the base implementation with the calculated nested_size
331
- add_message_field(total_size, field_id_size, nested_size, force);
332
- }
333
-
334
- /**
335
- * @brief Calculates and adds the sizes of all messages in a repeated field to the total message size
336
- *
337
- * This helper processes a vector of message objects, calculating the size for each message
338
- * and adding it to the total size.
339
- *
340
- * @tparam MessageType The type of the nested messages in the vector
341
- * @param messages Vector of message objects
342
- */
343
- template<typename MessageType>
344
- static inline void add_repeated_message(uint32_t &total_size, uint32_t field_id_size,
345
- const std::vector<MessageType> &messages) {
346
- // Skip if the vector is empty
347
- if (messages.empty()) {
348
- return;
349
- }
350
-
351
- // For repeated fields, always use force=true
352
- for (const auto &message : messages) {
353
- add_message_object(total_size, field_id_size, message, true);
354
- }
355
- }
356
- };
357
-
358
- } // namespace api
359
- } // namespace esphome