Merge remote-tracking branch 'upstream/dev' into api-proto-max-length

# Conflicts:
#	esphome/components/api/api_pb2.cpp
This commit is contained in:
J. Nick Koston
2026-04-06 14:48:45 -10:00
16 changed files with 256 additions and 193 deletions
+3
View File
@@ -3,6 +3,9 @@ name: PR Title Check
on:
pull_request:
types: [opened, edited, synchronize, reopened]
branches-ignore:
- release
- beta
permissions:
contents: read
+59 -71
View File
@@ -87,7 +87,7 @@ uint8_t *SerialProxyInfo::encode(ProtoWriteBuffer &buffer PROTO_ENCODE_DEBUG_PAR
uint32_t SerialProxyInfo::calculate_size() const {
uint32_t size = 0;
size += ProtoSize::calc_length(1, this->name.size());
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->port_type));
size += this->port_type ? 2 : 0;
return size;
}
#endif
@@ -244,7 +244,7 @@ uint32_t ListEntitiesBinarySensorResponse::calculate_size() const {
#ifdef USE_ENTITY_ICON
size += !this->icon.empty() ? 2 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
#endif
@@ -305,7 +305,7 @@ uint32_t ListEntitiesCoverResponse::calculate_size() const {
#ifdef USE_ENTITY_ICON
size += !this->icon.empty() ? 2 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
size += ProtoSize::calc_bool(1, this->supports_stop);
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
@@ -328,7 +328,7 @@ uint32_t CoverStateResponse::calculate_size() const {
size += 5;
size += ProtoSize::calc_float(1, this->position);
size += ProtoSize::calc_float(1, this->tilt);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->current_operation));
size += this->current_operation ? 2 : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
#endif
@@ -408,7 +408,7 @@ uint32_t ListEntitiesFanResponse::calculate_size() const {
#ifdef USE_ENTITY_ICON
size += !this->icon.empty() ? 2 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
if (!this->supported_preset_modes->empty()) {
for (const char *it : *this->supported_preset_modes) {
size += ProtoSize::calc_length_force(1, strlen(it));
@@ -437,7 +437,7 @@ uint32_t FanStateResponse::calculate_size() const {
size += 5;
size += ProtoSize::calc_bool(1, this->state);
size += ProtoSize::calc_bool(1, this->oscillating);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->direction));
size += this->direction ? 2 : 0;
size += ProtoSize::calc_int32(1, this->speed_level);
size += ProtoSize::calc_length(1, this->preset_mode.size());
#ifdef USE_DEVICES
@@ -536,9 +536,7 @@ uint32_t ListEntitiesLightResponse::calculate_size() const {
size += 5;
size += 2 + this->name.size();
if (!this->supported_color_modes->empty()) {
for (const auto &it : *this->supported_color_modes) {
size += ProtoSize::calc_uint32_force(1, static_cast<uint32_t>(it));
}
size += this->supported_color_modes->size() * 2;
}
size += ProtoSize::calc_float(1, this->min_mireds);
size += ProtoSize::calc_float(1, this->max_mireds);
@@ -551,7 +549,7 @@ uint32_t ListEntitiesLightResponse::calculate_size() const {
#ifdef USE_ENTITY_ICON
size += !this->icon.empty() ? 2 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(2, this->device_id);
#endif
@@ -582,7 +580,7 @@ uint32_t LightStateResponse::calculate_size() const {
size += 5;
size += ProtoSize::calc_bool(1, this->state);
size += ProtoSize::calc_float(1, this->brightness);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->color_mode));
size += this->color_mode ? 2 : 0;
size += ProtoSize::calc_float(1, this->color_brightness);
size += ProtoSize::calc_float(1, this->red);
size += ProtoSize::calc_float(1, this->green);
@@ -739,9 +737,9 @@ uint32_t ListEntitiesSensorResponse::calculate_size() const {
size += ProtoSize::calc_int32(1, this->accuracy_decimals);
size += ProtoSize::calc_bool(1, this->force_update);
size += !this->device_class.empty() ? 2 + this->device_class.size() : 0;
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->state_class));
size += this->state_class ? 2 : 0;
size += ProtoSize::calc_bool(1, this->disabled_by_default);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
#endif
@@ -796,7 +794,7 @@ uint32_t ListEntitiesSwitchResponse::calculate_size() const {
#endif
size += ProtoSize::calc_bool(1, this->assumed_state);
size += ProtoSize::calc_bool(1, this->disabled_by_default);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
size += !this->device_class.empty() ? 2 + this->device_class.size() : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
@@ -873,7 +871,7 @@ uint32_t ListEntitiesTextSensorResponse::calculate_size() const {
size += !this->icon.empty() ? 2 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_bool(1, this->disabled_by_default);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
size += !this->device_class.empty() ? 2 + this->device_class.size() : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
@@ -922,7 +920,7 @@ uint8_t *SubscribeLogsResponse::encode(ProtoWriteBuffer &buffer PROTO_ENCODE_DEB
}
uint32_t SubscribeLogsResponse::calculate_size() const {
uint32_t size = 0;
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->level));
size += this->level ? 2 : 0;
size += ProtoSize::calc_length(1, this->message_len_);
return size;
}
@@ -1171,7 +1169,7 @@ uint8_t *ListEntitiesServicesArgument::encode(ProtoWriteBuffer &buffer PROTO_ENC
uint32_t ListEntitiesServicesArgument::calculate_size() const {
uint32_t size = 0;
size += ProtoSize::calc_length(1, this->name.size());
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->type));
size += this->type ? 2 : 0;
return size;
}
uint8_t *ListEntitiesServicesResponse::encode(ProtoWriteBuffer &buffer PROTO_ENCODE_DEBUG_PARAM) const {
@@ -1193,7 +1191,7 @@ uint32_t ListEntitiesServicesResponse::calculate_size() const {
size += ProtoSize::calc_message_force(1, it.calculate_size());
}
}
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->supports_response));
size += this->supports_response ? 2 : 0;
return size;
}
bool ExecuteServiceArgument::decode_varint(uint32_t field_id, proto_varint_value_t value) {
@@ -1347,7 +1345,7 @@ uint32_t ListEntitiesCameraResponse::calculate_size() const {
#ifdef USE_ENTITY_ICON
size += !this->icon.empty() ? 2 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
#endif
@@ -1441,23 +1439,17 @@ uint32_t ListEntitiesClimateResponse::calculate_size() const {
size += ProtoSize::calc_bool(1, this->supports_current_temperature);
size += ProtoSize::calc_bool(1, this->supports_two_point_target_temperature);
if (!this->supported_modes->empty()) {
for (const auto &it : *this->supported_modes) {
size += ProtoSize::calc_uint32_force(1, static_cast<uint32_t>(it));
}
size += this->supported_modes->size() * 2;
}
size += ProtoSize::calc_float(1, this->visual_min_temperature);
size += ProtoSize::calc_float(1, this->visual_max_temperature);
size += ProtoSize::calc_float(1, this->visual_target_temperature_step);
size += ProtoSize::calc_bool(1, this->supports_action);
if (!this->supported_fan_modes->empty()) {
for (const auto &it : *this->supported_fan_modes) {
size += ProtoSize::calc_uint32_force(1, static_cast<uint32_t>(it));
}
size += this->supported_fan_modes->size() * 2;
}
if (!this->supported_swing_modes->empty()) {
for (const auto &it : *this->supported_swing_modes) {
size += ProtoSize::calc_uint32_force(1, static_cast<uint32_t>(it));
}
size += this->supported_swing_modes->size() * 2;
}
if (!this->supported_custom_fan_modes->empty()) {
for (const char *it : *this->supported_custom_fan_modes) {
@@ -1465,9 +1457,7 @@ uint32_t ListEntitiesClimateResponse::calculate_size() const {
}
}
if (!this->supported_presets->empty()) {
for (const auto &it : *this->supported_presets) {
size += ProtoSize::calc_uint32_force(2, static_cast<uint32_t>(it));
}
size += this->supported_presets->size() * 3;
}
if (!this->supported_custom_presets->empty()) {
for (const char *it : *this->supported_custom_presets) {
@@ -1478,7 +1468,7 @@ uint32_t ListEntitiesClimateResponse::calculate_size() const {
#ifdef USE_ENTITY_ICON
size += !this->icon.empty() ? 3 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_uint32(2, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 3 : 0;
size += ProtoSize::calc_float(2, this->visual_current_temperature_step);
size += ProtoSize::calc_bool(2, this->supports_current_humidity);
size += ProtoSize::calc_bool(2, this->supports_target_humidity);
@@ -1514,16 +1504,16 @@ uint8_t *ClimateStateResponse::encode(ProtoWriteBuffer &buffer PROTO_ENCODE_DEBU
uint32_t ClimateStateResponse::calculate_size() const {
uint32_t size = 0;
size += 5;
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->mode));
size += this->mode ? 2 : 0;
size += ProtoSize::calc_float(1, this->current_temperature);
size += ProtoSize::calc_float(1, this->target_temperature);
size += ProtoSize::calc_float(1, this->target_temperature_low);
size += ProtoSize::calc_float(1, this->target_temperature_high);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->action));
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->fan_mode));
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->swing_mode));
size += this->action ? 2 : 0;
size += this->fan_mode ? 2 : 0;
size += this->swing_mode ? 2 : 0;
size += ProtoSize::calc_length(1, this->custom_fan_mode.size());
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->preset));
size += this->preset ? 2 : 0;
size += ProtoSize::calc_length(1, this->custom_preset.size());
size += ProtoSize::calc_float(1, this->current_humidity);
size += ProtoSize::calc_float(1, this->target_humidity);
@@ -1656,7 +1646,7 @@ uint32_t ListEntitiesWaterHeaterResponse::calculate_size() const {
size += !this->icon.empty() ? 2 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_bool(1, this->disabled_by_default);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
#endif
@@ -1664,9 +1654,7 @@ uint32_t ListEntitiesWaterHeaterResponse::calculate_size() const {
size += ProtoSize::calc_float(1, this->max_temperature);
size += ProtoSize::calc_float(1, this->target_temperature_step);
if (!this->supported_modes->empty()) {
for (const auto &it : *this->supported_modes) {
size += ProtoSize::calc_uint32_force(1, static_cast<uint32_t>(it));
}
size += this->supported_modes->size() * 2;
}
size += ProtoSize::calc_uint32(1, this->supported_features);
return size;
@@ -1690,7 +1678,7 @@ uint32_t WaterHeaterStateResponse::calculate_size() const {
size += 5;
size += ProtoSize::calc_float(1, this->current_temperature);
size += ProtoSize::calc_float(1, this->target_temperature);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->mode));
size += this->mode ? 2 : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
#endif
@@ -1774,9 +1762,9 @@ uint32_t ListEntitiesNumberResponse::calculate_size() const {
size += ProtoSize::calc_float(1, this->max_value);
size += ProtoSize::calc_float(1, this->step);
size += ProtoSize::calc_bool(1, this->disabled_by_default);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
size += !this->unit_of_measurement.empty() ? 2 + this->unit_of_measurement.size() : 0;
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->mode));
size += this->mode ? 2 : 0;
size += !this->device_class.empty() ? 2 + this->device_class.size() : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
@@ -1862,7 +1850,7 @@ uint32_t ListEntitiesSelectResponse::calculate_size() const {
}
}
size += ProtoSize::calc_bool(1, this->disabled_by_default);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
#endif
@@ -1959,7 +1947,7 @@ uint32_t ListEntitiesSirenResponse::calculate_size() const {
}
size += ProtoSize::calc_bool(1, this->supports_duration);
size += ProtoSize::calc_bool(1, this->supports_volume);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
#endif
@@ -2067,7 +2055,7 @@ uint32_t ListEntitiesLockResponse::calculate_size() const {
size += !this->icon.empty() ? 2 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_bool(1, this->disabled_by_default);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
size += ProtoSize::calc_bool(1, this->assumed_state);
size += ProtoSize::calc_bool(1, this->supports_open);
size += ProtoSize::calc_bool(1, this->requires_code);
@@ -2089,7 +2077,7 @@ uint8_t *LockStateResponse::encode(ProtoWriteBuffer &buffer PROTO_ENCODE_DEBUG_P
uint32_t LockStateResponse::calculate_size() const {
uint32_t size = 0;
size += 5;
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->state));
size += this->state ? 2 : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
#endif
@@ -2161,7 +2149,7 @@ uint32_t ListEntitiesButtonResponse::calculate_size() const {
size += !this->icon.empty() ? 2 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_bool(1, this->disabled_by_default);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
size += !this->device_class.empty() ? 2 + this->device_class.size() : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
@@ -2206,7 +2194,7 @@ uint32_t MediaPlayerSupportedFormat::calculate_size() const {
size += ProtoSize::calc_length(1, this->format.size());
size += ProtoSize::calc_uint32(1, this->sample_rate);
size += ProtoSize::calc_uint32(1, this->num_channels);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->purpose));
size += this->purpose ? 2 : 0;
size += ProtoSize::calc_uint32(1, this->sample_bytes);
return size;
}
@@ -2239,7 +2227,7 @@ uint32_t ListEntitiesMediaPlayerResponse::calculate_size() const {
size += !this->icon.empty() ? 2 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_bool(1, this->disabled_by_default);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
size += ProtoSize::calc_bool(1, this->supports_pause);
if (!this->supported_formats.empty()) {
for (const auto &it : this->supported_formats) {
@@ -2266,7 +2254,7 @@ uint8_t *MediaPlayerStateResponse::encode(ProtoWriteBuffer &buffer PROTO_ENCODE_
uint32_t MediaPlayerStateResponse::calculate_size() const {
uint32_t size = 0;
size += 5;
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->state));
size += this->state ? 2 : 0;
size += ProtoSize::calc_float(1, this->volume);
size += ProtoSize::calc_bool(1, this->muted);
#ifdef USE_DEVICES
@@ -2348,7 +2336,7 @@ uint8_t *BluetoothLERawAdvertisement::encode(ProtoWriteBuffer &buffer PROTO_ENCO
ProtoEncode::encode_varint_raw_short(pos PROTO_ENCODE_DEBUG_ARG, encode_zigzag32(this->rssi));
if (this->address_type) {
ProtoEncode::write_raw_byte(pos PROTO_ENCODE_DEBUG_ARG, 24);
ProtoEncode::write_raw_byte(pos PROTO_ENCODE_DEBUG_ARG, static_cast<uint8_t>(this->address_type));
ProtoEncode::encode_varint_raw(pos PROTO_ENCODE_DEBUG_ARG, this->address_type);
}
ProtoEncode::write_raw_byte(pos PROTO_ENCODE_DEBUG_ARG, 34);
ProtoEncode::write_raw_byte(pos PROTO_ENCODE_DEBUG_ARG, static_cast<uint8_t>(this->data_len));
@@ -2762,9 +2750,9 @@ uint8_t *BluetoothScannerStateResponse::encode(ProtoWriteBuffer &buffer PROTO_EN
}
uint32_t BluetoothScannerStateResponse::calculate_size() const {
uint32_t size = 0;
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->state));
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->mode));
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->configured_mode));
size += this->state ? 2 : 0;
size += this->mode ? 2 : 0;
size += this->configured_mode ? 2 : 0;
return size;
}
bool BluetoothScannerSetModeRequest::decode_varint(uint32_t field_id, proto_varint_value_t value) {
@@ -3116,7 +3104,7 @@ uint32_t ListEntitiesAlarmControlPanelResponse::calculate_size() const {
size += !this->icon.empty() ? 2 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_bool(1, this->disabled_by_default);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
size += ProtoSize::calc_uint32(1, this->supported_features);
size += ProtoSize::calc_bool(1, this->requires_code);
size += ProtoSize::calc_bool(1, this->requires_code_to_arm);
@@ -3137,7 +3125,7 @@ uint8_t *AlarmControlPanelStateResponse::encode(ProtoWriteBuffer &buffer PROTO_E
uint32_t AlarmControlPanelStateResponse::calculate_size() const {
uint32_t size = 0;
size += 5;
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->state));
size += this->state ? 2 : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
#endif
@@ -3209,11 +3197,11 @@ uint32_t ListEntitiesTextResponse::calculate_size() const {
size += !this->icon.empty() ? 2 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_bool(1, this->disabled_by_default);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
size += ProtoSize::calc_uint32(1, this->min_length);
size += ProtoSize::calc_uint32(1, this->max_length);
size += ProtoSize::calc_length(1, this->pattern.size());
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->mode));
size += this->mode ? 2 : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
#endif
@@ -3298,7 +3286,7 @@ uint32_t ListEntitiesDateResponse::calculate_size() const {
size += !this->icon.empty() ? 2 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_bool(1, this->disabled_by_default);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
#endif
@@ -3385,7 +3373,7 @@ uint32_t ListEntitiesTimeResponse::calculate_size() const {
size += !this->icon.empty() ? 2 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_bool(1, this->disabled_by_default);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
#endif
@@ -3476,7 +3464,7 @@ uint32_t ListEntitiesEventResponse::calculate_size() const {
size += !this->icon.empty() ? 2 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_bool(1, this->disabled_by_default);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
size += !this->device_class.empty() ? 2 + this->device_class.size() : 0;
if (!this->event_types->empty()) {
for (const char *it : *this->event_types) {
@@ -3536,7 +3524,7 @@ uint32_t ListEntitiesValveResponse::calculate_size() const {
size += !this->icon.empty() ? 2 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_bool(1, this->disabled_by_default);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
size += !this->device_class.empty() ? 2 + this->device_class.size() : 0;
size += ProtoSize::calc_bool(1, this->assumed_state);
size += ProtoSize::calc_bool(1, this->supports_position);
@@ -3560,7 +3548,7 @@ uint32_t ValveStateResponse::calculate_size() const {
uint32_t size = 0;
size += 5;
size += ProtoSize::calc_float(1, this->position);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->current_operation));
size += this->current_operation ? 2 : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
#endif
@@ -3623,7 +3611,7 @@ uint32_t ListEntitiesDateTimeResponse::calculate_size() const {
size += !this->icon.empty() ? 2 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_bool(1, this->disabled_by_default);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
#endif
@@ -3701,7 +3689,7 @@ uint32_t ListEntitiesUpdateResponse::calculate_size() const {
size += !this->icon.empty() ? 2 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_bool(1, this->disabled_by_default);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
size += !this->device_class.empty() ? 2 + this->device_class.size() : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
@@ -3821,7 +3809,7 @@ uint8_t *ZWaveProxyRequest::encode(ProtoWriteBuffer &buffer PROTO_ENCODE_DEBUG_P
}
uint32_t ZWaveProxyRequest::calculate_size() const {
uint32_t size = 0;
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->type));
size += this->type ? 2 : 0;
size += ProtoSize::calc_length(1, this->data_len);
return size;
}
@@ -3853,7 +3841,7 @@ uint32_t ListEntitiesInfraredResponse::calculate_size() const {
size += !this->icon.empty() ? 2 + this->icon.size() : 0;
#endif
size += ProtoSize::calc_bool(1, this->disabled_by_default);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->entity_category));
size += this->entity_category ? 2 : 0;
#ifdef USE_DEVICES
size += ProtoSize::calc_uint32(1, this->device_id);
#endif
@@ -4048,8 +4036,8 @@ uint8_t *SerialProxyRequestResponse::encode(ProtoWriteBuffer &buffer PROTO_ENCOD
uint32_t SerialProxyRequestResponse::calculate_size() const {
uint32_t size = 0;
size += ProtoSize::calc_uint32(1, this->instance);
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->type));
size += ProtoSize::calc_uint32(1, static_cast<uint32_t>(this->status));
size += this->type ? 2 : 0;
size += this->status ? 2 : 0;
size += ProtoSize::calc_length(1, this->error_message.size());
return size;
}
+18 -9
View File
@@ -25,6 +25,19 @@ constexpr uint8_t WIRE_TYPE_LENGTH_DELIMITED = 2; // string, bytes, embedded me
constexpr uint8_t WIRE_TYPE_FIXED32 = 5; // fixed32, sfixed32, float
constexpr uint8_t WIRE_TYPE_MASK = 0b111; // Mask to extract wire type from tag
// Reinterpret float bits as uint32_t without floating-point comparison.
// Used by both encode_float() and calc_float() to ensure identical zero checks.
// Uses union type-punning which is a GCC/Clang extension (not standard C++),
// but bit_cast/memcpy don't optimize to a no-op on xtensa-gcc (ESP8266).
inline uint32_t float_to_raw(float value) {
union {
float f;
uint32_t u;
} v;
v.f = value;
return v.u;
}
// Helper functions for ZigZag encoding/decoding
inline constexpr uint32_t encode_zigzag32(int32_t value) {
return (static_cast<uint32_t>(value) << 1) ^ (static_cast<uint32_t>(value >> 31));
@@ -445,14 +458,10 @@ class ProtoEncode {
// is needed in the future, the necessary encoding/decoding functions must be added.
static inline void encode_float(uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint32_t field_id, float value,
bool force = false) {
if (value == 0.0f && !force)
uint32_t raw = float_to_raw(value);
if (raw == 0 && !force)
return;
union {
float value;
uint32_t raw;
} val{};
val.value = value;
encode_fixed32(pos PROTO_ENCODE_DEBUG_ARG, field_id, val.raw);
encode_fixed32(pos PROTO_ENCODE_DEBUG_ARG, field_id, raw);
}
static inline void encode_int32(uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint32_t field_id, int32_t value,
bool force = false) {
@@ -764,8 +773,8 @@ class ProtoSize {
}
static constexpr uint32_t calc_bool(uint32_t field_id_size, bool value) { return value ? field_id_size + 1 : 0; }
static constexpr uint32_t calc_bool_force(uint32_t field_id_size) { return field_id_size + 1; }
static constexpr uint32_t calc_float(uint32_t field_id_size, float value) {
return value != 0.0f ? field_id_size + 4 : 0;
static uint32_t calc_float(uint32_t field_id_size, float value) {
return float_to_raw(value) != 0 ? field_id_size + 4 : 0;
}
static constexpr uint32_t calc_fixed32(uint32_t field_id_size, uint32_t value) {
return value ? field_id_size + 4 : 0;
+1 -1
View File
@@ -89,6 +89,6 @@ async def to_code(config):
)
await cg.register_component(var, conf)
if restore_value := config.get(CONF_RESTORE_VALUE):
if restore_value := conf.get(CONF_RESTORE_VALUE):
cg.add(var.set_restore_value(restore_value))
cg.add(getattr(bl0940, setter_method)(var))
+1 -1
View File
@@ -245,7 +245,7 @@ async def send_action(
data = config.get(CONF_DATA, [])
if isinstance(data, str):
data = [cg.RawExpression(f"'{c}'") for c in data]
data = list(data.encode())
templ = await cg.templatable(data, args, byte_vector, byte_vector)
cg.add(var.set_data(templ))
+15 -5
View File
@@ -2,7 +2,7 @@ import importlib
from pathlib import Path
import pkgutil
from esphome.automation import build_automation, validate_automation
from esphome.automation import Trigger, build_automation, validate_automation
import esphome.codegen as cg
from esphome.components.const import (
CONF_BYTE_ORDER,
@@ -34,7 +34,6 @@ from esphome.const import (
CONF_ID,
CONF_LAMBDA,
CONF_LOG_LEVEL,
CONF_ON_BOOT,
CONF_ON_IDLE,
CONF_PAGES,
CONF_ROTATION,
@@ -59,7 +58,7 @@ from .encoders import (
from .gradient import GRADIENT_SCHEMA, gradients_to_code
from .keypads import KEYPADS_CONFIG, keypads_to_code
from .lv_validation import lv_bool, lv_images_used
from .lvcode import LvContext, LvglComponent, lvgl_static
from .lvcode import LvContext, LvglComponent, lv_event_t_ptr, lvgl_static
from .schemas import (
DISP_BG_SCHEMA,
FULL_STYLE_SCHEMA,
@@ -71,7 +70,7 @@ from .schemas import (
)
from .styles import styles_to_code, theme_to_code
from .touchscreens import touchscreen_schema, touchscreens_to_code
from .trigger import add_on_boot_triggers, generate_align_tos, generate_triggers
from .trigger import generate_align_tos, generate_triggers
from .types import (
IdleTrigger,
PlainTrigger,
@@ -79,6 +78,7 @@ from .types import (
lv_font_t,
lv_group_t,
lv_lambda_t,
lv_obj_t_ptr,
lv_style_t,
lvgl_ns,
)
@@ -398,7 +398,6 @@ async def to_code(configs):
f"set_{trigger_name.removeprefix('on_')}_trigger",
)(trigger_var)
)
await add_on_boot_triggers(config.get(CONF_ON_BOOT, ()))
# This must be done after all widgets are created
for comp in helpers.lvgl_components_required:
@@ -502,6 +501,17 @@ LVGL_SCHEMA = cv.All(
cv.polling_component_schema("1s")
.extend(
{
**{
cv.Optional(event): validate_automation(
{
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
Trigger.template(lv_obj_t_ptr, lv_event_t_ptr)
),
}
)
for event in df.LV_SCREEN_EVENT_TRIGGERS
+ df.LV_DISPLAY_EVENT_TRIGGERS
},
cv.GenerateID(CONF_ID): cv.declare_id(LvglComponent),
cv.GenerateID(CONF_ALIGN_TO_LAMBDA_ID): cv.declare_id(lv_lambda_t),
cv.GenerateID(df.CONF_DISPLAYS): display_schema,
+22 -14
View File
@@ -276,10 +276,6 @@ LV_EVENT_MAP = {
"DRAW_POST_BEGIN": "DRAW_POST_BEGIN",
"DRAW_POST_END": "DRAW_POST_END",
"DRAW_TASK_ADD": "DRAW_TASK_ADDED",
"FLUSH_FINISH": "FLUSH_FINISH",
"FLUSH_START": "FLUSH_START",
"FLUSH_WAIT_FINISH": "FLUSH_WAIT_FINISH",
"FLUSH_WAIT_START": "FLUSH_WAIT_START",
"FOCUS": "FOCUSED",
"GESTURE": "GESTURE",
"GET_SELF_SIZE": "GET_SELF_SIZE",
@@ -300,18 +296,8 @@ LV_EVENT_MAP = {
"READY": "READY",
"REFRESH": "REFRESH",
"REFR_EXT_DRAW_SIZE": "REFR_EXT_DRAW_SIZE",
"REFR_READY": "REFR_READY",
"REFR_REQUEST": "REFR_REQUEST",
"REFR_START": "REFR_START",
"RELEASE": "RELEASED",
"RENDER_READY": "RENDER_READY",
"RENDER_START": "RENDER_START",
"RESOLUTION_CHANGE": "RESOLUTION_CHANGED",
"ROTARY": "ROTARY",
"SCREEN_LOAD": "SCREEN_LOADED",
"SCREEN_LOAD_START": "SCREEN_LOAD_START",
"SCREEN_UNLOAD": "SCREEN_UNLOADED",
"SCREEN_UNLOAD_START": "SCREEN_UNLOAD_START",
"SCROLL": "SCROLL",
"SCROLL_BEGIN": "SCROLL_BEGIN",
"SCROLL_END": "SCROLL_END",
@@ -322,12 +308,34 @@ LV_EVENT_MAP = {
"STATE_CHANGE": "STATE_CHANGED",
"STYLE_CHANGE": "STYLE_CHANGED",
"TRIPLE_CLICK": "TRIPLE_CLICKED",
}
LV_SCREEN_EVENT_MAP = {
"SCREEN_LOAD": "SCREEN_LOADED",
"SCREEN_LOAD_START": "SCREEN_LOAD_START",
"SCREEN_UNLOAD": "SCREEN_UNLOADED",
"SCREEN_UNLOAD_START": "SCREEN_UNLOAD_START",
}
LV_DISPLAY_EVENT_MAP = {
"FLUSH_FINISH": "FLUSH_FINISH",
"FLUSH_START": "FLUSH_START",
"FLUSH_WAIT_FINISH": "FLUSH_WAIT_FINISH",
"FLUSH_WAIT_START": "FLUSH_WAIT_START",
"REFR_READY": "REFR_READY",
"REFR_REQUEST": "REFR_REQUEST",
"REFR_START": "REFR_START",
"RENDER_READY": "RENDER_READY",
"RENDER_START": "RENDER_START",
"RESOLUTION_CHANGE": "RESOLUTION_CHANGED",
"UPDATE_LAYOUT_COMPLETE": "UPDATE_LAYOUT_COMPLETED",
"VSYNC": "VSYNC",
"VSYNC_REQUEST": "VSYNC_REQUEST",
}
LV_EVENT_TRIGGERS = tuple(f"on_{x.lower()}" for x in LV_EVENT_MAP)
LV_DISPLAY_EVENT_TRIGGERS = tuple(f"on_{x.lower()}" for x in LV_DISPLAY_EVENT_MAP)
LV_SCREEN_EVENT_TRIGGERS = tuple(f"on_{x.lower()}" for x in LV_SCREEN_EVENT_MAP)
SWIPE_TRIGGERS = tuple(
f"on_swipe_{x.lower()}" for x in DIRECTIONS.choices + ("up", "down")
)
+39 -15
View File
@@ -8,16 +8,21 @@ from esphome.const import (
CONF_X,
CONF_Y,
)
from esphome.cpp_generator import new_Pvariable
from esphome.cpp_generator import MockObj, new_Pvariable
from esphome.cpp_helpers import register_component
from esphome.cpp_types import nullptr
from .defines import (
CONF_ALIGN,
CONF_ALIGN_TO,
CONF_ALIGN_TO_LAMBDA_ID,
DIRECTIONS,
LV_DISPLAY_EVENT_MAP,
LV_DISPLAY_EVENT_TRIGGERS,
LV_EVENT_MAP,
LV_EVENT_TRIGGERS,
LV_SCREEN_EVENT_MAP,
LV_SCREEN_EVENT_TRIGGERS,
SWIPE_TRIGGERS,
literal,
)
@@ -30,6 +35,7 @@ from .lvcode import (
lv,
lv_add,
lv_event_t_ptr,
lv_expr,
lvgl_static,
)
from .types import LV_EVENT
@@ -49,25 +55,24 @@ async def generate_triggers():
Must be done after all widgets completed
"""
all_triggers = (
LV_EVENT_TRIGGERS + LV_DISPLAY_EVENT_TRIGGERS + LV_SCREEN_EVENT_TRIGGERS
)
for w in widget_map.values():
config = w.config
if isinstance(w.type, LvScrActType):
w = get_screen_active(w.var)
if w.config:
if config:
for event, conf in {
event: conf
for event, conf in w.config.items()
if event in LV_EVENT_TRIGGERS
event: conf for event, conf in config.items() if event in all_triggers
}.items():
conf = conf[0]
w.add_flag("LV_OBJ_FLAG_CLICKABLE")
event = literal("LV_EVENT_" + LV_EVENT_MAP[event[3:].upper()])
await add_trigger(conf, w, event)
for event, conf in {
event: conf
for event, conf in w.config.items()
if event in SWIPE_TRIGGERS
event: conf for event, conf in config.items() if event in SWIPE_TRIGGERS
}.items():
conf = conf[0]
dir = event[9:].upper()
@@ -77,11 +82,9 @@ async def generate_triggers():
selected = literal(
f"lv_indev_get_gesture_dir(lv_indev_active()) == {dir}"
)
await add_trigger(
conf, w, literal("LV_EVENT_GESTURE"), is_selected=selected
)
await add_trigger(conf, w, "GESTURE", is_selected=selected)
for conf in w.config.get(CONF_ON_VALUE, ()):
for conf in config.get(CONF_ON_VALUE, ()):
await add_trigger(
conf,
w,
@@ -90,7 +93,7 @@ async def generate_triggers():
UPDATE_EVENT,
)
await add_on_boot_triggers(w.config.get(CONF_ON_BOOT, ()))
await add_on_boot_triggers(config.get(CONF_ON_BOOT, ()))
async def generate_align_tos(config: dict):
@@ -119,6 +122,17 @@ async def generate_align_tos(config: dict):
await register_component(var, {})
TRIGGER_MAP = LV_EVENT_MAP | LV_DISPLAY_EVENT_MAP | LV_SCREEN_EVENT_MAP
DISPLAY_TRIGGERS = set(LV_DISPLAY_EVENT_TRIGGERS)
def _get_event_literal(trigger: str | MockObj) -> MockObj:
if isinstance(trigger, MockObj):
return trigger
trigger = trigger.removeprefix("on_")
return literal("LV_EVENT_" + TRIGGER_MAP[trigger.upper()])
async def add_trigger(conf, w, *events, is_selected=None):
is_selected = is_selected or w.is_selected()
tid = conf[CONF_TRIGGER_ID]
@@ -129,4 +143,14 @@ async def add_trigger(conf, w, *events, is_selected=None):
async with LambdaContext(EVENT_ARG, where=tid) as context:
with LvConditional(is_selected):
lv_add(trigger.trigger(*value, literal("event")))
lv_add(lvgl_static.add_event_cb(w.obj, await context.get_lambda(), *events))
callback = await context.get_lambda()
event_literals = [_get_event_literal(event) for event in events]
if isinstance(events[0], str) and events[0] in DISPLAY_TRIGGERS:
assert len(events) == 1
lv.display_add_event_cb(
lv_expr.obj_get_display(w.obj), callback, event_literals[0], nullptr
)
else:
lv_add(
lvgl_static.add_event_cb(w.obj, await context.get_lambda(), *event_literals)
)
+1 -1
View File
@@ -344,7 +344,7 @@ def _spi_extra_validate(config):
if CORE.is_esp32:
return
if config[CONF_DATA_PIN] != 13 and config[CONF_CLOCK_PIN] != 14:
if config[CONF_DATA_PIN] != 13 or config[CONF_CLOCK_PIN] != 14:
raise cv.Invalid(
"SPI only supports pins GPIO13 for data and GPIO14 for clock on ESP8266"
)
+3 -2
View File
@@ -185,7 +185,7 @@ def validate_update_interval(value):
return value
CONFIG_SCHEMA = (
CONFIG_SCHEMA = cv.All(
cv.Schema(
{
cv.GenerateID(): cv.declare_id(PMSX003Component),
@@ -290,7 +290,8 @@ CONFIG_SCHEMA = (
}
)
.extend(cv.COMPONENT_SCHEMA)
.extend(uart.UART_DEVICE_SCHEMA)
.extend(uart.UART_DEVICE_SCHEMA),
validate_pmsx003_sensors,
)
+8 -6
View File
@@ -10,12 +10,14 @@ AUTO_LOAD = ["web_server_base"]
prometheus_ns = cg.esphome_ns.namespace("prometheus")
PrometheusHandler = prometheus_ns.class_("PrometheusHandler", cg.Component)
CUSTOMIZED_ENTITY = cv.Schema(
{
cv.Optional(CONF_ID): cv.string_strict,
cv.Optional(CONF_NAME): cv.string_strict,
},
cv.has_at_least_one_key,
CUSTOMIZED_ENTITY = cv.All(
cv.Schema(
{
cv.Optional(CONF_ID): cv.string_strict,
cv.Optional(CONF_NAME): cv.string_strict,
},
),
cv.has_at_least_one_key(CONF_ID, CONF_NAME),
)
CONFIG_SCHEMA = cv.Schema(
+6 -6
View File
@@ -470,7 +470,7 @@ CANALSATLD_SCHEMA = cv.Schema(
)
@register_binary_sensor("canalsatld", CanalSatLDBinarySensor, CANALSAT_SCHEMA)
@register_binary_sensor("canalsatld", CanalSatLDBinarySensor, CANALSATLD_SCHEMA)
def canalsatld_binary_sensor(var, config):
cg.add(
var.set_data(
@@ -1130,7 +1130,7 @@ def sony_dumper(var, config):
async def sony_action(var, config, args):
template_ = await cg.templatable(config[CONF_DATA], args, cg.uint32)
cg.add(var.set_data(template_))
template_ = await cg.templatable(config[CONF_NBITS], args, cg.uint32)
template_ = await cg.templatable(config[CONF_NBITS], args, cg.uint8)
cg.add(var.set_nbits(template_))
@@ -1174,7 +1174,7 @@ def symphony_dumper(var, config):
async def symphony_action(var, config, args):
template_ = await cg.templatable(config[CONF_DATA], args, cg.uint32)
cg.add(var.set_data(template_))
template_ = await cg.templatable(config[CONF_NBITS], args, cg.uint32)
template_ = await cg.templatable(config[CONF_NBITS], args, cg.uint8)
cg.add(var.set_nbits(template_))
template_ = await cg.templatable(config[CONF_COMMAND_REPEATS], args, cg.uint8)
cg.add(var.set_repeats(template_))
@@ -1188,7 +1188,7 @@ def validate_raw_alternating(value):
this_negative = val < 0
if i != 0 and this_negative == last_negative:
raise cv.Invalid(
f"Values must alternate between being positive and negative, please see index {i} and {i + 1}",
f"Values must alternate between being positive and negative, please see index {i - 1} and {i}",
[i],
)
last_negative = this_negative
@@ -2105,12 +2105,12 @@ async def abbwelcome_action(var, config, args):
)
cg.add(
var.set_source_address(
await cg.templatable(config[CONF_SOURCE_ADDRESS], args, cg.uint16)
await cg.templatable(config[CONF_SOURCE_ADDRESS], args, cg.uint32)
)
)
cg.add(
var.set_destination_address(
await cg.templatable(config[CONF_DESTINATION_ADDRESS], args, cg.uint16)
await cg.templatable(config[CONF_DESTINATION_ADDRESS], args, cg.uint32)
)
)
cg.add(
+1 -1
View File
@@ -1667,7 +1667,7 @@ def dimensions(value):
match = re.match(r"\s*([0-9]+)\s*[xX]\s*([0-9]+)\s*", value)
if not match:
raise Invalid(
"Invalid value '{}' for dimensions. Only WIDTHxHEIGHT is allowed."
f"Invalid value '{value}' for dimensions. Only WIDTHxHEIGHT is allowed."
)
return dimensions([match.group(1), match.group(2)])
+39 -23
View File
@@ -56,6 +56,10 @@ FILE_HEADER = """// This file was automatically generated with a tool.
// See script/api_protobuf/api_protobuf.py
"""
# Populated by main() before any TypeInfo creation.
# Maps enum type name (e.g. ".BluetoothDeviceRequestType") to max enum value.
_enum_max_values: dict[str, int] = {}
def indent_list(text: str, padding: str = " ") -> list[str]:
"""Indent each line of the given text with the specified padding."""
@@ -245,12 +249,6 @@ class TypeInfo(ABC):
"encode_bool": "ProtoEncode::write_raw_byte(pos, {value} ? 0x01 : 0x00);",
}
# When max_value < 128, the varint is always 1 byte — use a direct byte write
RAW_ENCODE_SMALL_MAP: dict[str, str] = {
"encode_uint32": "ProtoEncode::write_raw_byte(pos, static_cast<uint8_t>({value}));",
"encode_uint64": "ProtoEncode::write_raw_byte(pos, static_cast<uint8_t>({value}));",
}
def _encode_with_precomputed_tag(self, value_expr: str) -> str | None:
"""Try to emit a precomputed-tag encode for a field.
@@ -260,19 +258,14 @@ class TypeInfo(ABC):
Returns the raw encode string if the tag is a single byte and the
encode_func has a known raw equivalent, or None otherwise.
When max_value < 128, uses direct byte write instead of varint encoding.
"""
tag = self.calculate_tag()
if tag >= 128:
return None
max_val = self.max_value
# Only use RAW_ENCODE_MAP for forced fields or fields with max_value
raw_expr = None
if max_val is not None and max_val < 128:
raw_expr = self.RAW_ENCODE_SMALL_MAP.get(self.encode_func)
if raw_expr is None:
# Only use RAW_ENCODE_MAP for forced fields or fields with max_value
if not self.force and max_val is None:
return None
if self.force or max_val is not None:
raw_expr = self.RAW_ENCODE_MAP.get(self.encode_func)
if raw_expr is None:
return None
@@ -1347,19 +1340,24 @@ class EnumType(TypeInfo):
default_value = ""
wire_type = WireType.VARINT # Uses wire type 0
@property
def max_value(self) -> int | None:
"""Get max_value from explicit annotation or auto-derive from enum definition."""
explicit = super().max_value
if explicit is not None:
return explicit
return _enum_max_values.get(self._field.type_name)
@property
def encode_func(self) -> str:
return "encode_uint32"
@property
def encode_content(self) -> str:
if result := self._encode_with_precomputed_tag(
f"static_cast<uint32_t>(this->{self.field_name})"
):
return result
value_expr = f"static_cast<uint32_t>(this->{self.field_name})"
if self.force:
return f"ProtoEncode::{self.encode_func}(pos, {self.number}, static_cast<uint32_t>(this->{self.field_name}), true);"
return f"ProtoEncode::{self.encode_func}(pos, {self.number}, static_cast<uint32_t>(this->{self.field_name}));"
return f"ProtoEncode::{self.encode_func}(pos, {self.number}, {value_expr}, true);"
return f"ProtoEncode::{self.encode_func}(pos, {self.number}, {value_expr});"
def dump(self, name: str) -> str:
return f"out.append_p(proto_enum_to_string<{self.cpp_type}>({name}));"
@@ -1369,6 +1367,9 @@ class EnumType(TypeInfo):
return f"static_cast<{self.cpp_type}>({value})"
def get_size_calculation(self, name: str, force: bool = False) -> str:
max_val = self.max_value
if max_val is not None and max_val < 128:
return self._get_single_byte_varint_size(name, force)
return self._get_simple_size_calculation(
name, force, "uint32", f"static_cast<uint32_t>({name})"
)
@@ -1931,17 +1932,27 @@ class RepeatedTypeInfo(TypeInfo):
size_expr = f"{name}->size()" if self._use_pointer else f"{name}.size()"
o += f" size += {size_expr} * {bytes_per_element};\n"
else:
# Other types need the actual value
# Check if inner type produces a constant size (doesn't depend on value)
inner_size = self._ti.get_size_calculation("it", True)
if "it" not in inner_size:
# Constant size per element — use multiply instead of loop
# Extract the constant from "size += N;"
const_val = (
inner_size.strip().removeprefix("size += ").removesuffix(";")
)
size_expr = f"{name}->size()" if self._use_pointer else f"{name}.size()"
o += f" size += {size_expr} * {const_val};\n"
# Special handling for const char* elements
if self._use_pointer and "const char" in self._container_no_template:
elif self._use_pointer and "const char" in self._container_no_template:
field_id_size = self.calculate_field_id_size()
o += f" for (const char *it : {container_ref}) {{\n"
o += f" size += ProtoSize::calc_length_force({field_id_size}, strlen(it));\n"
o += " }\n"
else:
auto_ref = "" if self._ti_is_bool else "&"
o += f" for (const auto {auto_ref}it : {container_ref}) {{\n"
o += f" {self._ti.get_size_calculation('it', True)}\n"
o += " }\n"
o += f" {inner_size}\n"
o += " }\n"
o += "}"
return o
@@ -2814,6 +2825,11 @@ def main() -> None:
file = d.file[0]
# Build enum max value map so EnumType can auto-derive max_value
for enum in file.enum_type:
if not enum.options.deprecated and enum.value:
_enum_max_values[f".{enum.name}"] = max(v.number for v in enum.value)
# Build dynamic ifdef mappings early so we can emit USE_API_VARINT64 before includes
enum_ifdef_map, message_ifdef_map, message_source_map, used_messages = (
build_type_usage_map(file)
+2
View File
@@ -29,6 +29,8 @@ espnow:
data: !lambda 'return {0x01, 0x02, 0x03, 0x04, 0x05};'
- espnow.broadcast:
data: "Hello, World!"
- espnow.broadcast:
data: "it's a test"
- espnow.broadcast:
data: [0x01, 0x02, 0x03, 0x04, 0x05]
- espnow.broadcast:
+38 -38
View File
@@ -49,6 +49,44 @@ lvgl:
id: meter_arc_indicator
start_value: 0
end_value: 180
on_invalidate_area:
logger.log: Invalidate area
on_resolution_change:
logger.log: Resolution changed
on_color_format_change:
logger.log: Color format changed
on_refr_request:
logger.log: Refresh request
on_refr_start:
logger.log: Refresh start
on_refr_ready:
logger.log: Refresh ready
on_render_start:
logger.log: Render start
on_render_ready:
logger.log: Render ready
on_flush_start:
logger.log: Flush start
on_flush_finish:
logger.log: Flush finish
on_flush_wait_start:
logger.log: Flush wait start
on_flush_wait_finish:
logger.log: Flush wait finish
on_update_layout_complete:
logger.log: Update layout complete
on_vsync:
logger.log: Vsync
on_vsync_request:
logger.log: Vsync request
on_screen_load_start:
logger.log: Screen load start
on_screen_load:
logger.log: Screen loaded
on_screen_unload:
logger.log: Screen unloaded
on_screen_unload_start:
logger.log: Screen unload start
bg_color: light_blue
bottom_layer:
widgets:
@@ -660,14 +698,6 @@ lvgl:
logger.log: Child created
on_child_delete:
logger.log: Child deleted
on_screen_unload_start:
logger.log: Screen unload start
on_screen_load_start:
logger.log: Screen load start
on_screen_load:
logger.log: Screen loaded
on_screen_unload:
logger.log: Screen unloaded
on_size_change:
logger.log: Size changed
on_style_change:
@@ -676,36 +706,6 @@ lvgl:
logger.log: Layout changed
on_get_self_size:
logger.log: Get self size
on_invalidate_area:
logger.log: Invalidate area
on_resolution_change:
logger.log: Resolution changed
on_color_format_change:
logger.log: Color format changed
on_refr_request:
logger.log: Refresh request
on_refr_start:
logger.log: Refresh start
on_refr_ready:
logger.log: Refresh ready
on_render_start:
logger.log: Render start
on_render_ready:
logger.log: Render ready
on_flush_start:
logger.log: Flush start
on_flush_finish:
logger.log: Flush finish
on_flush_wait_start:
logger.log: Flush wait start
on_flush_wait_finish:
logger.log: Flush wait finish
on_update_layout_complete:
logger.log: Update layout complete
on_vsync:
logger.log: Vsync
on_vsync_request:
logger.log: Vsync request
- led:
id: lv_led
color: 0x00FF00