diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index d7022ea22f..c8d1dd8aec 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -248,8 +248,8 @@ void APIConnection::loop() { if (state_subs_at_ < static_cast(subs.size())) { auto &it = subs[state_subs_at_]; SubscribeHomeAssistantStateResponse resp; - resp.set_entity_id(it.entity_id.c_str(), it.entity_id.length()); - resp.set_attribute(it.attribute.value().c_str(), it.attribute.value().length()); + resp.set_entity_id(StringRef(it.entity_id)); + resp.set_attribute(StringRef(it.attribute.value())); resp.once = it.once; if (this->send_message(resp, SubscribeHomeAssistantStateResponse::MESSAGE_TYPE)) { state_subs_at_++; @@ -344,8 +344,7 @@ uint16_t APIConnection::try_send_binary_sensor_info(EntityBase *entity, APIConne bool is_single) { auto *binary_sensor = static_cast(entity); ListEntitiesBinarySensorResponse msg; - const std::string &device_class = binary_sensor->get_device_class(); - msg.set_device_class(device_class.c_str(), device_class.length()); + msg.set_device_class(StringRef(binary_sensor->get_device_class())); msg.is_status_binary_sensor = binary_sensor->is_status_binary_sensor(); return fill_and_encode_entity_info(binary_sensor, msg, ListEntitiesBinarySensorResponse::MESSAGE_TYPE, conn, remaining_size, is_single); @@ -377,8 +376,7 @@ uint16_t APIConnection::try_send_cover_info(EntityBase *entity, APIConnection *c msg.supports_position = traits.get_supports_position(); msg.supports_tilt = traits.get_supports_tilt(); msg.supports_stop = traits.get_supports_stop(); - const std::string &device_class = cover->get_device_class(); - msg.set_device_class(device_class.c_str(), device_class.length()); + msg.set_device_class(StringRef(cover->get_device_class())); return fill_and_encode_entity_info(cover, msg, ListEntitiesCoverResponse::MESSAGE_TYPE, conn, remaining_size, is_single); } @@ -413,7 +411,7 @@ uint16_t APIConnection::try_send_fan_state(EntityBase *entity, APIConnection *co if (traits.supports_direction()) msg.direction = static_cast(fan->direction); if (traits.supports_preset_modes()) - msg.set_preset_mode(fan->preset_mode.c_str(), fan->preset_mode.length()); + msg.set_preset_mode(StringRef(fan->preset_mode)); return fill_and_encode_entity_state(fan, msg, FanStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single); } uint16_t APIConnection::try_send_fan_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size, @@ -471,8 +469,7 @@ uint16_t APIConnection::try_send_light_state(EntityBase *entity, APIConnection * resp.cold_white = values.get_cold_white(); resp.warm_white = values.get_warm_white(); if (light->supports_effects()) { - const std::string &effect_name = light->get_effect_name(); - resp.set_effect(effect_name.c_str(), effect_name.length()); + resp.set_effect(StringRef(light->get_effect_name())); } return fill_and_encode_entity_state(light, resp, LightStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single); } @@ -549,12 +546,10 @@ uint16_t APIConnection::try_send_sensor_info(EntityBase *entity, APIConnection * bool is_single) { auto *sensor = static_cast(entity); ListEntitiesSensorResponse msg; - const std::string &unit = sensor->get_unit_of_measurement(); - msg.set_unit_of_measurement(unit.c_str(), unit.length()); + msg.set_unit_of_measurement(StringRef(sensor->get_unit_of_measurement())); msg.accuracy_decimals = sensor->get_accuracy_decimals(); msg.force_update = sensor->get_force_update(); - const std::string &device_class = sensor->get_device_class(); - msg.set_device_class(device_class.c_str(), device_class.length()); + msg.set_device_class(StringRef(sensor->get_device_class())); msg.state_class = static_cast(sensor->get_state_class()); return fill_and_encode_entity_info(sensor, msg, ListEntitiesSensorResponse::MESSAGE_TYPE, conn, remaining_size, is_single); @@ -581,8 +576,7 @@ uint16_t APIConnection::try_send_switch_info(EntityBase *entity, APIConnection * auto *a_switch = static_cast(entity); ListEntitiesSwitchResponse msg; msg.assumed_state = a_switch->assumed_state(); - const std::string &device_class = a_switch->get_device_class(); - msg.set_device_class(device_class.c_str(), device_class.length()); + msg.set_device_class(StringRef(a_switch->get_device_class())); return fill_and_encode_entity_info(a_switch, msg, ListEntitiesSwitchResponse::MESSAGE_TYPE, conn, remaining_size, is_single); } @@ -607,7 +601,7 @@ uint16_t APIConnection::try_send_text_sensor_state(EntityBase *entity, APIConnec bool is_single) { auto *text_sensor = static_cast(entity); TextSensorStateResponse resp; - resp.set_state(text_sensor->state.c_str(), text_sensor->state.length()); + resp.set_state(StringRef(text_sensor->state)); resp.missing_state = !text_sensor->has_state(); return fill_and_encode_entity_state(text_sensor, resp, TextSensorStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single); @@ -616,8 +610,7 @@ uint16_t APIConnection::try_send_text_sensor_info(EntityBase *entity, APIConnect bool is_single) { auto *text_sensor = static_cast(entity); ListEntitiesTextSensorResponse msg; - const std::string &device_class = text_sensor->get_device_class(); - msg.set_device_class(device_class.c_str(), device_class.length()); + msg.set_device_class(StringRef(text_sensor->get_device_class())); return fill_and_encode_entity_info(text_sensor, msg, ListEntitiesTextSensorResponse::MESSAGE_TYPE, conn, remaining_size, is_single); } @@ -646,15 +639,13 @@ uint16_t APIConnection::try_send_climate_state(EntityBase *entity, APIConnection if (traits.get_supports_fan_modes() && climate->fan_mode.has_value()) resp.fan_mode = static_cast(climate->fan_mode.value()); if (!traits.get_supported_custom_fan_modes().empty() && climate->custom_fan_mode.has_value()) { - const std::string &custom_fan = climate->custom_fan_mode.value(); - resp.set_custom_fan_mode(custom_fan.c_str(), custom_fan.length()); + resp.set_custom_fan_mode(StringRef(climate->custom_fan_mode.value())); } if (traits.get_supports_presets() && climate->preset.has_value()) { resp.preset = static_cast(climate->preset.value()); } if (!traits.get_supported_custom_presets().empty() && climate->custom_preset.has_value()) { - const std::string &custom_preset = climate->custom_preset.value(); - resp.set_custom_preset(custom_preset.c_str(), custom_preset.length()); + resp.set_custom_preset(StringRef(climate->custom_preset.value())); } if (traits.get_supports_swing_modes()) resp.swing_mode = static_cast(climate->swing_mode); @@ -741,11 +732,9 @@ uint16_t APIConnection::try_send_number_info(EntityBase *entity, APIConnection * bool is_single) { auto *number = static_cast(entity); ListEntitiesNumberResponse msg; - const std::string &unit = number->traits.get_unit_of_measurement(); - msg.set_unit_of_measurement(unit.c_str(), unit.length()); + msg.set_unit_of_measurement(StringRef(number->traits.get_unit_of_measurement())); msg.mode = static_cast(number->traits.get_mode()); - const std::string &device_class = number->traits.get_device_class(); - msg.set_device_class(device_class.c_str(), device_class.length()); + msg.set_device_class(StringRef(number->traits.get_device_class())); msg.min_value = number->traits.get_min_value(); msg.max_value = number->traits.get_max_value(); msg.step = number->traits.get_step(); @@ -858,7 +847,7 @@ uint16_t APIConnection::try_send_text_state(EntityBase *entity, APIConnection *c bool is_single) { auto *text = static_cast(entity); TextStateResponse resp; - resp.set_state(text->state.c_str(), text->state.length()); + resp.set_state(StringRef(text->state)); resp.missing_state = !text->has_state(); return fill_and_encode_entity_state(text, resp, TextStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single); } @@ -870,8 +859,7 @@ uint16_t APIConnection::try_send_text_info(EntityBase *entity, APIConnection *co msg.mode = static_cast(text->traits.get_mode()); msg.min_length = text->traits.get_min_length(); msg.max_length = text->traits.get_max_length(); - const std::string &pattern = text->traits.get_pattern(); - msg.set_pattern(pattern.c_str(), pattern.length()); + msg.set_pattern(StringRef(text->traits.get_pattern())); return fill_and_encode_entity_info(text, msg, ListEntitiesTextResponse::MESSAGE_TYPE, conn, remaining_size, is_single); } @@ -892,7 +880,7 @@ uint16_t APIConnection::try_send_select_state(EntityBase *entity, APIConnection bool is_single) { auto *select = static_cast(entity); SelectStateResponse resp; - resp.set_state(select->state.c_str(), select->state.length()); + resp.set_state(StringRef(select->state)); resp.missing_state = !select->has_state(); return fill_and_encode_entity_state(select, resp, SelectStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single); } @@ -918,8 +906,7 @@ uint16_t APIConnection::try_send_button_info(EntityBase *entity, APIConnection * bool is_single) { auto *button = static_cast(entity); ListEntitiesButtonResponse msg; - const std::string &device_class = button->get_device_class(); - msg.set_device_class(device_class.c_str(), device_class.length()); + msg.set_device_class(StringRef(button->get_device_class())); return fill_and_encode_entity_info(button, msg, ListEntitiesButtonResponse::MESSAGE_TYPE, conn, remaining_size, is_single); } @@ -988,8 +975,7 @@ uint16_t APIConnection::try_send_valve_info(EntityBase *entity, APIConnection *c auto *valve = static_cast(entity); ListEntitiesValveResponse msg; auto traits = valve->get_traits(); - const std::string &device_class = valve->get_device_class(); - msg.set_device_class(device_class.c_str(), device_class.length()); + msg.set_device_class(StringRef(valve->get_device_class())); msg.assumed_state = traits.get_is_assumed_state(); msg.supports_position = traits.get_supports_position(); msg.supports_stop = traits.get_supports_stop(); @@ -1290,7 +1276,7 @@ void APIConnection::send_event(event::Event *event, const std::string &event_typ uint16_t APIConnection::try_send_event_response(event::Event *event, const std::string &event_type, APIConnection *conn, uint32_t remaining_size, bool is_single) { EventResponse resp; - resp.set_event_type(event_type.c_str(), event_type.length()); + resp.set_event_type(StringRef(event_type)); return fill_and_encode_entity_state(event, resp, EventResponse::MESSAGE_TYPE, conn, remaining_size, is_single); } @@ -1298,8 +1284,7 @@ uint16_t APIConnection::try_send_event_info(EntityBase *entity, APIConnection *c bool is_single) { auto *event = static_cast(entity); ListEntitiesEventResponse msg; - const std::string &device_class = event->get_device_class(); - msg.set_device_class(device_class.c_str(), device_class.length()); + msg.set_device_class(StringRef(event->get_device_class())); for (const auto &event_type : event->get_event_types()) msg.event_types.push_back(event_type); return fill_and_encode_entity_info(event, msg, ListEntitiesEventResponse::MESSAGE_TYPE, conn, remaining_size, @@ -1323,11 +1308,11 @@ uint16_t APIConnection::try_send_update_state(EntityBase *entity, APIConnection resp.has_progress = true; resp.progress = update->update_info.progress; } - resp.set_current_version(update->update_info.current_version.c_str(), update->update_info.current_version.length()); - resp.set_latest_version(update->update_info.latest_version.c_str(), update->update_info.latest_version.length()); - resp.set_title(update->update_info.title.c_str(), update->update_info.title.length()); - resp.set_release_summary(update->update_info.summary.c_str(), update->update_info.summary.length()); - resp.set_release_url(update->update_info.release_url.c_str(), update->update_info.release_url.length()); + resp.set_current_version(StringRef(update->update_info.current_version)); + resp.set_latest_version(StringRef(update->update_info.latest_version)); + resp.set_title(StringRef(update->update_info.title)); + resp.set_release_summary(StringRef(update->update_info.summary)); + resp.set_release_url(StringRef(update->update_info.release_url)); } return fill_and_encode_entity_state(update, resp, UpdateStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single); } @@ -1335,8 +1320,7 @@ uint16_t APIConnection::try_send_update_info(EntityBase *entity, APIConnection * bool is_single) { auto *update = static_cast(entity); ListEntitiesUpdateResponse msg; - const std::string &device_class = update->get_device_class(); - msg.set_device_class(device_class.c_str(), device_class.length()); + msg.set_device_class(StringRef(update->get_device_class())); return fill_and_encode_entity_info(update, msg, ListEntitiesUpdateResponse::MESSAGE_TYPE, conn, remaining_size, is_single); } @@ -1397,9 +1381,8 @@ HelloResponse APIConnection::hello(const HelloRequest &msg) { resp.api_version_major = 1; resp.api_version_minor = 10; std::string server_info = App.get_name() + " (esphome v" ESPHOME_VERSION ")"; - resp.set_server_info(server_info.c_str(), server_info.length()); - const std::string &name = App.get_name(); - resp.set_name(name.c_str(), name.length()); + resp.set_server_info(StringRef(server_info)); + resp.set_name(StringRef(App.get_name())); #ifdef USE_API_PASSWORD // Password required - wait for authentication @@ -1430,39 +1413,35 @@ DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) { #ifdef USE_API_PASSWORD resp.uses_password = true; #endif - const std::string &name = App.get_name(); - resp.set_name(name.c_str(), name.length()); - const std::string &friendly_name = App.get_friendly_name(); - resp.set_friendly_name(friendly_name.c_str(), friendly_name.length()); + resp.set_name(StringRef(App.get_name())); + resp.set_friendly_name(StringRef(App.get_friendly_name())); #ifdef USE_AREAS - const std::string &area = App.get_area(); - resp.set_suggested_area(area.c_str(), area.length()); + resp.set_suggested_area(StringRef(App.get_area())); #endif std::string mac = get_mac_address_pretty(); - resp.set_mac_address(mac.c_str(), mac.length()); - resp.set_esphome_version(ESPHOME_VERSION, strlen(ESPHOME_VERSION)); - const std::string &compilation_time = App.get_compilation_time(); - resp.set_compilation_time(compilation_time.c_str(), compilation_time.length()); + resp.set_mac_address(StringRef(mac)); + resp.set_esphome_version(StringRef(ESPHOME_VERSION)); + resp.set_compilation_time(StringRef(App.get_compilation_time())); #if defined(USE_ESP8266) || defined(USE_ESP32) - resp.set_manufacturer("Espressif", 9); + resp.set_manufacturer(StringRef("Espressif")); #elif defined(USE_RP2040) - resp.set_manufacturer("Raspberry Pi", 12); + resp.set_manufacturer(StringRef("Raspberry Pi")); #elif defined(USE_BK72XX) - resp.set_manufacturer("Beken", 5); + resp.set_manufacturer(StringRef("Beken")); #elif defined(USE_LN882X) - resp.set_manufacturer("Lightning", 9); + resp.set_manufacturer(StringRef("Lightning")); #elif defined(USE_RTL87XX) - resp.set_manufacturer("Realtek", 7); + resp.set_manufacturer(StringRef("Realtek")); #elif defined(USE_HOST) - resp.set_manufacturer("Host", 4); + resp.set_manufacturer(StringRef("Host")); #endif - resp.set_model(ESPHOME_BOARD, strlen(ESPHOME_BOARD)); + resp.set_model(StringRef(ESPHOME_BOARD)); #ifdef USE_DEEP_SLEEP resp.has_deep_sleep = deep_sleep::global_has_deep_sleep; #endif #ifdef ESPHOME_PROJECT_NAME - resp.set_project_name(ESPHOME_PROJECT_NAME, strlen(ESPHOME_PROJECT_NAME)); - resp.set_project_version(ESPHOME_PROJECT_VERSION, strlen(ESPHOME_PROJECT_VERSION)); + resp.set_project_name(StringRef(ESPHOME_PROJECT_NAME)); + resp.set_project_version(StringRef(ESPHOME_PROJECT_VERSION)); #endif #ifdef USE_WEBSERVER resp.webserver_port = USE_WEBSERVER_PORT; @@ -1470,7 +1449,7 @@ DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) { #ifdef USE_BLUETOOTH_PROXY resp.bluetooth_proxy_feature_flags = bluetooth_proxy::global_bluetooth_proxy->get_feature_flags(); std::string bt_mac = bluetooth_proxy::global_bluetooth_proxy->get_bluetooth_mac_address_pretty(); - resp.set_bluetooth_mac_address(bt_mac.c_str(), bt_mac.length()); + resp.set_bluetooth_mac_address(StringRef(bt_mac)); #endif #ifdef USE_VOICE_ASSISTANT resp.voice_assistant_feature_flags = voice_assistant::global_voice_assistant->get_feature_flags(); @@ -1483,8 +1462,7 @@ DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) { resp.devices.emplace_back(); auto &device_info = resp.devices.back(); device_info.device_id = device->get_device_id(); - const std::string &device_name = device->get_name(); - device_info.set_name(device_name.c_str(), device_name.length()); + device_info.set_name(StringRef(device->get_name())); device_info.area_id = device->get_area_id(); } #endif @@ -1493,8 +1471,7 @@ DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) { resp.areas.emplace_back(); auto &area_info = resp.areas.back(); area_info.area_id = area->get_area_id(); - const std::string &area_name = area->get_name(); - area_info.set_name(area_name.c_str(), area_name.length()); + area_info.set_name(StringRef(area->get_name())); } #endif return resp; diff --git a/esphome/components/api/api_connection.h b/esphome/components/api/api_connection.h index ceb9e1b5e9..a37735bea8 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -313,18 +313,15 @@ class APIConnection : public APIServerConnection { APIConnection *conn, uint32_t remaining_size, bool is_single) { // Set common fields that are shared by all entity types msg.key = entity->get_object_id_hash(); - const std::string &object_id = entity->get_object_id(); - msg.set_object_id(object_id.c_str(), object_id.length()); + msg.set_object_id(StringRef(entity->get_object_id())); if (entity->has_own_name()) { - const std::string &name = entity->get_name(); - msg.set_name(name.c_str(), name.length()); + msg.set_name(StringRef(entity->get_name())); } // Set common EntityBase properties #ifdef USE_ENTITY_ICON - const std::string &icon = entity->get_icon(); - msg.set_icon(icon.c_str(), icon.length()); + msg.set_icon(StringRef(entity->get_icon())); #endif msg.disabled_by_default = entity->is_disabled_by_default(); msg.entity_category = static_cast(entity->get_entity_category()); diff --git a/esphome/components/api/api_pb2.cpp b/esphome/components/api/api_pb2.cpp index 39bc0611fe..92efb6f0d8 100644 --- a/esphome/components/api/api_pb2.cpp +++ b/esphome/components/api/api_pb2.cpp @@ -34,14 +34,14 @@ bool HelloRequest::decode_length(uint32_t field_id, ProtoLengthDelimited value) void HelloResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(1, this->api_version_major); buffer.encode_uint32(2, this->api_version_minor); - buffer.encode_string(3, this->server_info_ptr_, this->server_info_len_); - buffer.encode_string(4, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->server_info_ref_); + buffer.encode_string(4, this->name_ref_); } void HelloResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_uint32_field(total_size, 1, this->api_version_major); ProtoSize::add_uint32_field(total_size, 1, this->api_version_minor); - ProtoSize::add_string_field(total_size, 1, this->server_info_len_); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->server_info_ref_.size()); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); } bool ConnectRequest::decode_length(uint32_t field_id, ProtoLengthDelimited value) { switch (field_id) { @@ -60,22 +60,22 @@ void ConnectResponse::calculate_size(uint32_t &total_size) const { #ifdef USE_AREAS void AreaInfo::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(1, this->area_id); - buffer.encode_string(2, this->name_ptr_, this->name_len_); + buffer.encode_string(2, this->name_ref_); } void AreaInfo::calculate_size(uint32_t &total_size) const { ProtoSize::add_uint32_field(total_size, 1, this->area_id); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); } #endif #ifdef USE_DEVICES void DeviceInfo::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(1, this->device_id); - buffer.encode_string(2, this->name_ptr_, this->name_len_); + buffer.encode_string(2, this->name_ref_); buffer.encode_uint32(3, this->area_id); } void DeviceInfo::calculate_size(uint32_t &total_size) const { ProtoSize::add_uint32_field(total_size, 1, this->device_id); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); ProtoSize::add_uint32_field(total_size, 1, this->area_id); } #endif @@ -83,19 +83,19 @@ void DeviceInfoResponse::encode(ProtoWriteBuffer buffer) const { #ifdef USE_API_PASSWORD buffer.encode_bool(1, this->uses_password); #endif - buffer.encode_string(2, this->name_ptr_, this->name_len_); - buffer.encode_string(3, this->mac_address_ptr_, this->mac_address_len_); - buffer.encode_string(4, this->esphome_version_ptr_, this->esphome_version_len_); - buffer.encode_string(5, this->compilation_time_ptr_, this->compilation_time_len_); - buffer.encode_string(6, this->model_ptr_, this->model_len_); + buffer.encode_string(2, this->name_ref_); + buffer.encode_string(3, this->mac_address_ref_); + buffer.encode_string(4, this->esphome_version_ref_); + buffer.encode_string(5, this->compilation_time_ref_); + buffer.encode_string(6, this->model_ref_); #ifdef USE_DEEP_SLEEP buffer.encode_bool(7, this->has_deep_sleep); #endif #ifdef ESPHOME_PROJECT_NAME - buffer.encode_string(8, this->project_name_ptr_, this->project_name_len_); + buffer.encode_string(8, this->project_name_ref_); #endif #ifdef ESPHOME_PROJECT_NAME - buffer.encode_string(9, this->project_version_ptr_, this->project_version_len_); + buffer.encode_string(9, this->project_version_ref_); #endif #ifdef USE_WEBSERVER buffer.encode_uint32(10, this->webserver_port); @@ -103,16 +103,16 @@ void DeviceInfoResponse::encode(ProtoWriteBuffer buffer) const { #ifdef USE_BLUETOOTH_PROXY buffer.encode_uint32(15, this->bluetooth_proxy_feature_flags); #endif - buffer.encode_string(12, this->manufacturer_ptr_, this->manufacturer_len_); - buffer.encode_string(13, this->friendly_name_ptr_, this->friendly_name_len_); + buffer.encode_string(12, this->manufacturer_ref_); + buffer.encode_string(13, this->friendly_name_ref_); #ifdef USE_VOICE_ASSISTANT buffer.encode_uint32(17, this->voice_assistant_feature_flags); #endif #ifdef USE_AREAS - buffer.encode_string(16, this->suggested_area_ptr_, this->suggested_area_len_); + buffer.encode_string(16, this->suggested_area_ref_); #endif #ifdef USE_BLUETOOTH_PROXY - buffer.encode_string(18, this->bluetooth_mac_address_ptr_, this->bluetooth_mac_address_len_); + buffer.encode_string(18, this->bluetooth_mac_address_ref_); #endif #ifdef USE_API_NOISE buffer.encode_bool(19, this->api_encryption_supported); @@ -135,19 +135,19 @@ 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_len_); - ProtoSize::add_string_field(total_size, 1, this->mac_address_len_); - ProtoSize::add_string_field(total_size, 1, this->esphome_version_len_); - ProtoSize::add_string_field(total_size, 1, this->compilation_time_len_); - ProtoSize::add_string_field(total_size, 1, this->model_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); + ProtoSize::add_string_field(total_size, 1, this->mac_address_ref_.size()); + ProtoSize::add_string_field(total_size, 1, this->esphome_version_ref_.size()); + ProtoSize::add_string_field(total_size, 1, this->compilation_time_ref_.size()); + ProtoSize::add_string_field(total_size, 1, this->model_ref_.size()); #ifdef USE_DEEP_SLEEP ProtoSize::add_bool_field(total_size, 1, this->has_deep_sleep); #endif #ifdef ESPHOME_PROJECT_NAME - ProtoSize::add_string_field(total_size, 1, this->project_name_len_); + ProtoSize::add_string_field(total_size, 1, this->project_name_ref_.size()); #endif #ifdef ESPHOME_PROJECT_NAME - ProtoSize::add_string_field(total_size, 1, this->project_version_len_); + ProtoSize::add_string_field(total_size, 1, this->project_version_ref_.size()); #endif #ifdef USE_WEBSERVER ProtoSize::add_uint32_field(total_size, 1, this->webserver_port); @@ -155,16 +155,16 @@ void DeviceInfoResponse::calculate_size(uint32_t &total_size) const { #ifdef USE_BLUETOOTH_PROXY ProtoSize::add_uint32_field(total_size, 1, this->bluetooth_proxy_feature_flags); #endif - ProtoSize::add_string_field(total_size, 1, this->manufacturer_len_); - ProtoSize::add_string_field(total_size, 1, this->friendly_name_len_); + ProtoSize::add_string_field(total_size, 1, this->manufacturer_ref_.size()); + ProtoSize::add_string_field(total_size, 1, this->friendly_name_ref_.size()); #ifdef USE_VOICE_ASSISTANT ProtoSize::add_uint32_field(total_size, 2, this->voice_assistant_feature_flags); #endif #ifdef USE_AREAS - ProtoSize::add_string_field(total_size, 2, this->suggested_area_len_); + ProtoSize::add_string_field(total_size, 2, this->suggested_area_ref_.size()); #endif #ifdef USE_BLUETOOTH_PROXY - ProtoSize::add_string_field(total_size, 2, this->bluetooth_mac_address_len_); + ProtoSize::add_string_field(total_size, 2, this->bluetooth_mac_address_ref_.size()); #endif #ifdef USE_API_NOISE ProtoSize::add_bool_field(total_size, 2, this->api_encryption_supported); @@ -181,14 +181,14 @@ void DeviceInfoResponse::calculate_size(uint32_t &total_size) const { } #ifdef USE_BINARY_SENSOR void ListEntitiesBinarySensorResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); - buffer.encode_string(5, this->device_class_ptr_, this->device_class_len_); + buffer.encode_string(3, this->name_ref_); + buffer.encode_string(5, this->device_class_ref_); buffer.encode_bool(6, this->is_status_binary_sensor); buffer.encode_bool(7, this->disabled_by_default); #ifdef USE_ENTITY_ICON - buffer.encode_string(8, this->icon_ptr_, this->icon_len_); + buffer.encode_string(8, this->icon_ref_); #endif buffer.encode_uint32(9, static_cast(this->entity_category)); #ifdef USE_DEVICES @@ -196,14 +196,14 @@ void ListEntitiesBinarySensorResponse::encode(ProtoWriteBuffer buffer) const { #endif } void ListEntitiesBinarySensorResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); - ProtoSize::add_string_field(total_size, 1, this->device_class_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); + ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); ProtoSize::add_bool_field(total_size, 1, this->is_status_binary_sensor); ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); #ifdef USE_DEVICES @@ -229,16 +229,16 @@ void BinarySensorStateResponse::calculate_size(uint32_t &total_size) const { #endif #ifdef USE_COVER void ListEntitiesCoverResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); buffer.encode_bool(5, this->assumed_state); buffer.encode_bool(6, this->supports_position); buffer.encode_bool(7, this->supports_tilt); - buffer.encode_string(8, this->device_class_ptr_, this->device_class_len_); + buffer.encode_string(8, this->device_class_ref_); buffer.encode_bool(9, this->disabled_by_default); #ifdef USE_ENTITY_ICON - buffer.encode_string(10, this->icon_ptr_, this->icon_len_); + buffer.encode_string(10, this->icon_ref_); #endif buffer.encode_uint32(11, static_cast(this->entity_category)); buffer.encode_bool(12, this->supports_stop); @@ -247,16 +247,16 @@ void ListEntitiesCoverResponse::encode(ProtoWriteBuffer buffer) const { #endif } void ListEntitiesCoverResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); ProtoSize::add_bool_field(total_size, 1, this->assumed_state); ProtoSize::add_bool_field(total_size, 1, this->supports_position); ProtoSize::add_bool_field(total_size, 1, this->supports_tilt); - ProtoSize::add_string_field(total_size, 1, this->device_class_len_); + ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); ProtoSize::add_bool_field(total_size, 1, this->supports_stop); @@ -322,16 +322,16 @@ bool CoverCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { #endif #ifdef USE_FAN void ListEntitiesFanResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); buffer.encode_bool(5, this->supports_oscillation); buffer.encode_bool(6, this->supports_speed); buffer.encode_bool(7, this->supports_direction); buffer.encode_int32(8, this->supported_speed_count); buffer.encode_bool(9, this->disabled_by_default); #ifdef USE_ENTITY_ICON - buffer.encode_string(10, this->icon_ptr_, this->icon_len_); + buffer.encode_string(10, this->icon_ref_); #endif buffer.encode_uint32(11, static_cast(this->entity_category)); for (auto &it : this->supported_preset_modes) { @@ -342,16 +342,16 @@ void ListEntitiesFanResponse::encode(ProtoWriteBuffer buffer) const { #endif } void ListEntitiesFanResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); ProtoSize::add_bool_field(total_size, 1, this->supports_oscillation); ProtoSize::add_bool_field(total_size, 1, this->supports_speed); ProtoSize::add_bool_field(total_size, 1, this->supports_direction); ProtoSize::add_int32_field(total_size, 1, this->supported_speed_count); ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); if (!this->supported_preset_modes.empty()) { @@ -369,7 +369,7 @@ void FanStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_bool(3, this->oscillating); buffer.encode_uint32(5, static_cast(this->direction)); buffer.encode_int32(6, this->speed_level); - buffer.encode_string(7, this->preset_mode_ptr_, this->preset_mode_len_); + buffer.encode_string(7, this->preset_mode_ref_); #ifdef USE_DEVICES buffer.encode_uint32(8, this->device_id); #endif @@ -380,7 +380,7 @@ void FanStateResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_bool_field(total_size, 1, this->oscillating); ProtoSize::add_enum_field(total_size, 1, static_cast(this->direction)); ProtoSize::add_int32_field(total_size, 1, this->speed_level); - ProtoSize::add_string_field(total_size, 1, this->preset_mode_len_); + ProtoSize::add_string_field(total_size, 1, this->preset_mode_ref_.size()); #ifdef USE_DEVICES ProtoSize::add_uint32_field(total_size, 1, this->device_id); #endif @@ -447,9 +447,9 @@ bool FanCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { #endif #ifdef USE_LIGHT void ListEntitiesLightResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); for (auto &it : this->supported_color_modes) { buffer.encode_uint32(12, static_cast(it), true); } @@ -460,7 +460,7 @@ void ListEntitiesLightResponse::encode(ProtoWriteBuffer buffer) const { } buffer.encode_bool(13, this->disabled_by_default); #ifdef USE_ENTITY_ICON - buffer.encode_string(14, this->icon_ptr_, this->icon_len_); + buffer.encode_string(14, this->icon_ref_); #endif buffer.encode_uint32(15, static_cast(this->entity_category)); #ifdef USE_DEVICES @@ -468,9 +468,9 @@ void ListEntitiesLightResponse::encode(ProtoWriteBuffer buffer) const { #endif } void ListEntitiesLightResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); if (!this->supported_color_modes.empty()) { for (const auto &it : this->supported_color_modes) { ProtoSize::add_enum_field_repeated(total_size, 1, static_cast(it)); @@ -485,7 +485,7 @@ void ListEntitiesLightResponse::calculate_size(uint32_t &total_size) const { } ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); #ifdef USE_DEVICES @@ -505,7 +505,7 @@ void LightStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_float(8, this->color_temperature); buffer.encode_float(12, this->cold_white); buffer.encode_float(13, this->warm_white); - buffer.encode_string(9, this->effect_ptr_, this->effect_len_); + buffer.encode_string(9, this->effect_ref_); #ifdef USE_DEVICES buffer.encode_uint32(14, this->device_id); #endif @@ -523,7 +523,7 @@ void LightStateResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_float_field(total_size, 1, this->color_temperature); ProtoSize::add_float_field(total_size, 1, this->cold_white); ProtoSize::add_float_field(total_size, 1, this->warm_white); - ProtoSize::add_string_field(total_size, 1, this->effect_len_); + ProtoSize::add_string_field(total_size, 1, this->effect_ref_.size()); #ifdef USE_DEVICES ProtoSize::add_uint32_field(total_size, 1, this->device_id); #endif @@ -638,16 +638,16 @@ bool LightCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { #endif #ifdef USE_SENSOR void ListEntitiesSensorResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); #ifdef USE_ENTITY_ICON - buffer.encode_string(5, this->icon_ptr_, this->icon_len_); + buffer.encode_string(5, this->icon_ref_); #endif - buffer.encode_string(6, this->unit_of_measurement_ptr_, this->unit_of_measurement_len_); + buffer.encode_string(6, this->unit_of_measurement_ref_); buffer.encode_int32(7, this->accuracy_decimals); buffer.encode_bool(8, this->force_update); - buffer.encode_string(9, this->device_class_ptr_, this->device_class_len_); + buffer.encode_string(9, this->device_class_ref_); buffer.encode_uint32(10, static_cast(this->state_class)); buffer.encode_bool(12, this->disabled_by_default); buffer.encode_uint32(13, static_cast(this->entity_category)); @@ -656,16 +656,16 @@ void ListEntitiesSensorResponse::encode(ProtoWriteBuffer buffer) const { #endif } void ListEntitiesSensorResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif - ProtoSize::add_string_field(total_size, 1, this->unit_of_measurement_len_); + ProtoSize::add_string_field(total_size, 1, this->unit_of_measurement_ref_.size()); ProtoSize::add_int32_field(total_size, 1, this->accuracy_decimals); ProtoSize::add_bool_field(total_size, 1, this->force_update); - ProtoSize::add_string_field(total_size, 1, this->device_class_len_); + ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); ProtoSize::add_enum_field(total_size, 1, static_cast(this->state_class)); ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); @@ -692,31 +692,31 @@ void SensorStateResponse::calculate_size(uint32_t &total_size) const { #endif #ifdef USE_SWITCH void ListEntitiesSwitchResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); #ifdef USE_ENTITY_ICON - buffer.encode_string(5, this->icon_ptr_, this->icon_len_); + buffer.encode_string(5, this->icon_ref_); #endif buffer.encode_bool(6, this->assumed_state); buffer.encode_bool(7, this->disabled_by_default); buffer.encode_uint32(8, static_cast(this->entity_category)); - buffer.encode_string(9, this->device_class_ptr_, this->device_class_len_); + buffer.encode_string(9, this->device_class_ref_); #ifdef USE_DEVICES buffer.encode_uint32(10, this->device_id); #endif } void ListEntitiesSwitchResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_bool_field(total_size, 1, this->assumed_state); ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); - ProtoSize::add_string_field(total_size, 1, this->device_class_len_); + ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); #ifdef USE_DEVICES ProtoSize::add_uint32_field(total_size, 1, this->device_id); #endif @@ -763,36 +763,36 @@ bool SwitchCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { #endif #ifdef USE_TEXT_SENSOR void ListEntitiesTextSensorResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); #ifdef USE_ENTITY_ICON - buffer.encode_string(5, this->icon_ptr_, this->icon_len_); + buffer.encode_string(5, this->icon_ref_); #endif buffer.encode_bool(6, this->disabled_by_default); buffer.encode_uint32(7, static_cast(this->entity_category)); - buffer.encode_string(8, this->device_class_ptr_, this->device_class_len_); + buffer.encode_string(8, this->device_class_ref_); #ifdef USE_DEVICES buffer.encode_uint32(9, this->device_id); #endif } void ListEntitiesTextSensorResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); - ProtoSize::add_string_field(total_size, 1, this->device_class_len_); + ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); #ifdef USE_DEVICES ProtoSize::add_uint32_field(total_size, 1, this->device_id); #endif } void TextSensorStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); - buffer.encode_string(2, this->state_ptr_, this->state_len_); + buffer.encode_string(2, this->state_ref_); buffer.encode_bool(3, this->missing_state); #ifdef USE_DEVICES buffer.encode_uint32(4, this->device_id); @@ -800,7 +800,7 @@ void TextSensorStateResponse::encode(ProtoWriteBuffer buffer) const { } void TextSensorStateResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->state_len_); + ProtoSize::add_string_field(total_size, 1, this->state_ref_.size()); ProtoSize::add_bool_field(total_size, 1, this->missing_state); #ifdef USE_DEVICES ProtoSize::add_uint32_field(total_size, 1, this->device_id); @@ -845,15 +845,15 @@ void NoiseEncryptionSetKeyResponse::calculate_size(uint32_t &total_size) const { } #endif void HomeassistantServiceMap::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->key_ptr_, this->key_len_); - buffer.encode_string(2, this->value_ptr_, this->value_len_); + buffer.encode_string(1, this->key_ref_); + buffer.encode_string(2, this->value_ref_); } void HomeassistantServiceMap::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->key_len_); - ProtoSize::add_string_field(total_size, 1, this->value_len_); + ProtoSize::add_string_field(total_size, 1, this->key_ref_.size()); + ProtoSize::add_string_field(total_size, 1, this->value_ref_.size()); } void HomeassistantServiceResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->service_ptr_, this->service_len_); + buffer.encode_string(1, this->service_ref_); for (auto &it : this->data) { buffer.encode_message(2, it, true); } @@ -866,20 +866,20 @@ void HomeassistantServiceResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_bool(5, this->is_event); } void HomeassistantServiceResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->service_len_); + ProtoSize::add_string_field(total_size, 1, this->service_ref_.size()); ProtoSize::add_repeated_message(total_size, 1, this->data); ProtoSize::add_repeated_message(total_size, 1, this->data_template); ProtoSize::add_repeated_message(total_size, 1, this->variables); ProtoSize::add_bool_field(total_size, 1, this->is_event); } void SubscribeHomeAssistantStateResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->entity_id_ptr_, this->entity_id_len_); - buffer.encode_string(2, this->attribute_ptr_, this->attribute_len_); + buffer.encode_string(1, this->entity_id_ref_); + buffer.encode_string(2, this->attribute_ref_); buffer.encode_bool(3, this->once); } void SubscribeHomeAssistantStateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->entity_id_len_); - ProtoSize::add_string_field(total_size, 1, this->attribute_len_); + ProtoSize::add_string_field(total_size, 1, this->entity_id_ref_.size()); + ProtoSize::add_string_field(total_size, 1, this->attribute_ref_.size()); ProtoSize::add_bool_field(total_size, 1, this->once); } bool HomeAssistantStateResponse::decode_length(uint32_t field_id, ProtoLengthDelimited value) { @@ -914,22 +914,22 @@ void GetTimeResponse::calculate_size(uint32_t &total_size) const { } #ifdef USE_API_SERVICES void ListEntitiesServicesArgument::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->name_ptr_, this->name_len_); + buffer.encode_string(1, this->name_ref_); buffer.encode_uint32(2, static_cast(this->type)); } void ListEntitiesServicesArgument::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); ProtoSize::add_enum_field(total_size, 1, static_cast(this->type)); } void ListEntitiesServicesResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->name_ptr_, this->name_len_); + buffer.encode_string(1, this->name_ref_); buffer.encode_fixed32(2, this->key); for (auto &it : this->args) { buffer.encode_message(3, it, true); } } void ListEntitiesServicesResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); ProtoSize::add_repeated_message(total_size, 1, this->args); } @@ -1005,12 +1005,12 @@ bool ExecuteServiceRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { #endif #ifdef USE_CAMERA void ListEntitiesCameraResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); buffer.encode_bool(5, this->disabled_by_default); #ifdef USE_ENTITY_ICON - buffer.encode_string(6, this->icon_ptr_, this->icon_len_); + buffer.encode_string(6, this->icon_ref_); #endif buffer.encode_uint32(7, static_cast(this->entity_category)); #ifdef USE_DEVICES @@ -1018,12 +1018,12 @@ void ListEntitiesCameraResponse::encode(ProtoWriteBuffer buffer) const { #endif } void ListEntitiesCameraResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); #ifdef USE_DEVICES @@ -1062,9 +1062,9 @@ bool CameraImageRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { #endif #ifdef USE_CLIMATE void ListEntitiesClimateResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); buffer.encode_bool(5, this->supports_current_temperature); buffer.encode_bool(6, this->supports_two_point_target_temperature); for (auto &it : this->supported_modes) { @@ -1091,7 +1091,7 @@ void ListEntitiesClimateResponse::encode(ProtoWriteBuffer buffer) const { } buffer.encode_bool(18, this->disabled_by_default); #ifdef USE_ENTITY_ICON - buffer.encode_string(19, this->icon_ptr_, this->icon_len_); + buffer.encode_string(19, this->icon_ref_); #endif buffer.encode_uint32(20, static_cast(this->entity_category)); buffer.encode_float(21, this->visual_current_temperature_step); @@ -1104,9 +1104,9 @@ void ListEntitiesClimateResponse::encode(ProtoWriteBuffer buffer) const { #endif } void ListEntitiesClimateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); ProtoSize::add_bool_field(total_size, 1, this->supports_current_temperature); ProtoSize::add_bool_field(total_size, 1, this->supports_two_point_target_temperature); if (!this->supported_modes.empty()) { @@ -1145,7 +1145,7 @@ void ListEntitiesClimateResponse::calculate_size(uint32_t &total_size) const { } ProtoSize::add_bool_field(total_size, 2, this->disabled_by_default); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 2, this->icon_len_); + ProtoSize::add_string_field(total_size, 2, this->icon_ref_.size()); #endif ProtoSize::add_enum_field(total_size, 2, static_cast(this->entity_category)); ProtoSize::add_float_field(total_size, 2, this->visual_current_temperature_step); @@ -1167,9 +1167,9 @@ void ClimateStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_uint32(8, static_cast(this->action)); buffer.encode_uint32(9, static_cast(this->fan_mode)); buffer.encode_uint32(10, static_cast(this->swing_mode)); - buffer.encode_string(11, this->custom_fan_mode_ptr_, this->custom_fan_mode_len_); + buffer.encode_string(11, this->custom_fan_mode_ref_); buffer.encode_uint32(12, static_cast(this->preset)); - buffer.encode_string(13, this->custom_preset_ptr_, this->custom_preset_len_); + buffer.encode_string(13, this->custom_preset_ref_); buffer.encode_float(14, this->current_humidity); buffer.encode_float(15, this->target_humidity); #ifdef USE_DEVICES @@ -1186,9 +1186,9 @@ void ClimateStateResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_enum_field(total_size, 1, static_cast(this->action)); ProtoSize::add_enum_field(total_size, 1, static_cast(this->fan_mode)); ProtoSize::add_enum_field(total_size, 1, static_cast(this->swing_mode)); - ProtoSize::add_string_field(total_size, 1, this->custom_fan_mode_len_); + ProtoSize::add_string_field(total_size, 1, this->custom_fan_mode_ref_.size()); ProtoSize::add_enum_field(total_size, 1, static_cast(this->preset)); - ProtoSize::add_string_field(total_size, 1, this->custom_preset_len_); + ProtoSize::add_string_field(total_size, 1, this->custom_preset_ref_.size()); ProtoSize::add_float_field(total_size, 1, this->current_humidity); ProtoSize::add_float_field(total_size, 1, this->target_humidity); #ifdef USE_DEVICES @@ -1287,39 +1287,39 @@ bool ClimateCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { #endif #ifdef USE_NUMBER void ListEntitiesNumberResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); #ifdef USE_ENTITY_ICON - buffer.encode_string(5, this->icon_ptr_, this->icon_len_); + buffer.encode_string(5, this->icon_ref_); #endif buffer.encode_float(6, this->min_value); buffer.encode_float(7, this->max_value); buffer.encode_float(8, this->step); buffer.encode_bool(9, this->disabled_by_default); buffer.encode_uint32(10, static_cast(this->entity_category)); - buffer.encode_string(11, this->unit_of_measurement_ptr_, this->unit_of_measurement_len_); + buffer.encode_string(11, this->unit_of_measurement_ref_); buffer.encode_uint32(12, static_cast(this->mode)); - buffer.encode_string(13, this->device_class_ptr_, this->device_class_len_); + buffer.encode_string(13, this->device_class_ref_); #ifdef USE_DEVICES buffer.encode_uint32(14, this->device_id); #endif } void ListEntitiesNumberResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_float_field(total_size, 1, this->min_value); ProtoSize::add_float_field(total_size, 1, this->max_value); ProtoSize::add_float_field(total_size, 1, this->step); ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); - ProtoSize::add_string_field(total_size, 1, this->unit_of_measurement_len_); + ProtoSize::add_string_field(total_size, 1, this->unit_of_measurement_ref_.size()); ProtoSize::add_enum_field(total_size, 1, static_cast(this->mode)); - ProtoSize::add_string_field(total_size, 1, this->device_class_len_); + ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); #ifdef USE_DEVICES ProtoSize::add_uint32_field(total_size, 1, this->device_id); #endif @@ -1368,11 +1368,11 @@ bool NumberCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { #endif #ifdef USE_SELECT void ListEntitiesSelectResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); #ifdef USE_ENTITY_ICON - buffer.encode_string(5, this->icon_ptr_, this->icon_len_); + buffer.encode_string(5, this->icon_ref_); #endif for (auto &it : this->options) { buffer.encode_string(6, it, true); @@ -1384,11 +1384,11 @@ void ListEntitiesSelectResponse::encode(ProtoWriteBuffer buffer) const { #endif } void ListEntitiesSelectResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif if (!this->options.empty()) { for (const auto &it : this->options) { @@ -1403,7 +1403,7 @@ void ListEntitiesSelectResponse::calculate_size(uint32_t &total_size) const { } void SelectStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); - buffer.encode_string(2, this->state_ptr_, this->state_len_); + buffer.encode_string(2, this->state_ref_); buffer.encode_bool(3, this->missing_state); #ifdef USE_DEVICES buffer.encode_uint32(4, this->device_id); @@ -1411,7 +1411,7 @@ void SelectStateResponse::encode(ProtoWriteBuffer buffer) const { } void SelectStateResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->state_len_); + ProtoSize::add_string_field(total_size, 1, this->state_ref_.size()); ProtoSize::add_bool_field(total_size, 1, this->missing_state); #ifdef USE_DEVICES ProtoSize::add_uint32_field(total_size, 1, this->device_id); @@ -1452,11 +1452,11 @@ bool SelectCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { #endif #ifdef USE_SIREN void ListEntitiesSirenResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); #ifdef USE_ENTITY_ICON - buffer.encode_string(5, this->icon_ptr_, this->icon_len_); + buffer.encode_string(5, this->icon_ref_); #endif buffer.encode_bool(6, this->disabled_by_default); for (auto &it : this->tones) { @@ -1470,11 +1470,11 @@ void ListEntitiesSirenResponse::encode(ProtoWriteBuffer buffer) const { #endif } void ListEntitiesSirenResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); if (!this->tones.empty()) { @@ -1559,35 +1559,35 @@ bool SirenCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { #endif #ifdef USE_LOCK void ListEntitiesLockResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); #ifdef USE_ENTITY_ICON - buffer.encode_string(5, this->icon_ptr_, this->icon_len_); + buffer.encode_string(5, this->icon_ref_); #endif buffer.encode_bool(6, this->disabled_by_default); buffer.encode_uint32(7, static_cast(this->entity_category)); buffer.encode_bool(8, this->assumed_state); buffer.encode_bool(9, this->supports_open); buffer.encode_bool(10, this->requires_code); - buffer.encode_string(11, this->code_format_ptr_, this->code_format_len_); + buffer.encode_string(11, this->code_format_ref_); #ifdef USE_DEVICES buffer.encode_uint32(12, this->device_id); #endif } void ListEntitiesLockResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); ProtoSize::add_bool_field(total_size, 1, this->assumed_state); ProtoSize::add_bool_field(total_size, 1, this->supports_open); ProtoSize::add_bool_field(total_size, 1, this->requires_code); - ProtoSize::add_string_field(total_size, 1, this->code_format_len_); + ProtoSize::add_string_field(total_size, 1, this->code_format_ref_.size()); #ifdef USE_DEVICES ProtoSize::add_uint32_field(total_size, 1, this->device_id); #endif @@ -1647,29 +1647,29 @@ bool LockCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { #endif #ifdef USE_BUTTON void ListEntitiesButtonResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); #ifdef USE_ENTITY_ICON - buffer.encode_string(5, this->icon_ptr_, this->icon_len_); + buffer.encode_string(5, this->icon_ref_); #endif buffer.encode_bool(6, this->disabled_by_default); buffer.encode_uint32(7, static_cast(this->entity_category)); - buffer.encode_string(8, this->device_class_ptr_, this->device_class_len_); + buffer.encode_string(8, this->device_class_ref_); #ifdef USE_DEVICES buffer.encode_uint32(9, this->device_id); #endif } void ListEntitiesButtonResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); - ProtoSize::add_string_field(total_size, 1, this->device_class_len_); + ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); #ifdef USE_DEVICES ProtoSize::add_uint32_field(total_size, 1, this->device_id); #endif @@ -1699,25 +1699,25 @@ bool ButtonCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { #endif #ifdef USE_MEDIA_PLAYER void MediaPlayerSupportedFormat::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->format_ptr_, this->format_len_); + buffer.encode_string(1, this->format_ref_); buffer.encode_uint32(2, this->sample_rate); buffer.encode_uint32(3, this->num_channels); buffer.encode_uint32(4, static_cast(this->purpose)); buffer.encode_uint32(5, this->sample_bytes); } void MediaPlayerSupportedFormat::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->format_len_); + ProtoSize::add_string_field(total_size, 1, this->format_ref_.size()); ProtoSize::add_uint32_field(total_size, 1, this->sample_rate); ProtoSize::add_uint32_field(total_size, 1, this->num_channels); ProtoSize::add_enum_field(total_size, 1, static_cast(this->purpose)); ProtoSize::add_uint32_field(total_size, 1, this->sample_bytes); } void ListEntitiesMediaPlayerResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); #ifdef USE_ENTITY_ICON - buffer.encode_string(5, this->icon_ptr_, this->icon_len_); + buffer.encode_string(5, this->icon_ref_); #endif buffer.encode_bool(6, this->disabled_by_default); buffer.encode_uint32(7, static_cast(this->entity_category)); @@ -1730,11 +1730,11 @@ void ListEntitiesMediaPlayerResponse::encode(ProtoWriteBuffer buffer) const { #endif } void ListEntitiesMediaPlayerResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); @@ -2186,17 +2186,17 @@ void VoiceAssistantAudioSettings::calculate_size(uint32_t &total_size) const { } void VoiceAssistantRequest::encode(ProtoWriteBuffer buffer) const { buffer.encode_bool(1, this->start); - buffer.encode_string(2, this->conversation_id_ptr_, this->conversation_id_len_); + buffer.encode_string(2, this->conversation_id_ref_); buffer.encode_uint32(3, this->flags); buffer.encode_message(4, this->audio_settings); - buffer.encode_string(5, this->wake_word_phrase_ptr_, this->wake_word_phrase_len_); + buffer.encode_string(5, this->wake_word_phrase_ref_); } void VoiceAssistantRequest::calculate_size(uint32_t &total_size) const { ProtoSize::add_bool_field(total_size, 1, this->start); - ProtoSize::add_string_field(total_size, 1, this->conversation_id_len_); + ProtoSize::add_string_field(total_size, 1, this->conversation_id_ref_.size()); ProtoSize::add_uint32_field(total_size, 1, this->flags); ProtoSize::add_message_object(total_size, 1, this->audio_settings); - ProtoSize::add_string_field(total_size, 1, this->wake_word_phrase_len_); + ProtoSize::add_string_field(total_size, 1, this->wake_word_phrase_ref_.size()); } bool VoiceAssistantResponse::decode_varint(uint32_t field_id, ProtoVarInt value) { switch (field_id) { @@ -2336,15 +2336,15 @@ void VoiceAssistantAnnounceFinished::calculate_size(uint32_t &total_size) const ProtoSize::add_bool_field(total_size, 1, this->success); } void VoiceAssistantWakeWord::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->id_ptr_, this->id_len_); - buffer.encode_string(2, this->wake_word_ptr_, this->wake_word_len_); + buffer.encode_string(1, this->id_ref_); + buffer.encode_string(2, this->wake_word_ref_); for (auto &it : this->trained_languages) { buffer.encode_string(3, it, true); } } void VoiceAssistantWakeWord::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->id_len_); - ProtoSize::add_string_field(total_size, 1, this->wake_word_len_); + ProtoSize::add_string_field(total_size, 1, this->id_ref_.size()); + ProtoSize::add_string_field(total_size, 1, this->wake_word_ref_.size()); if (!this->trained_languages.empty()) { for (const auto &it : this->trained_languages) { ProtoSize::add_string_field(total_size, 1, it.length()); @@ -2382,11 +2382,11 @@ bool VoiceAssistantSetConfiguration::decode_length(uint32_t field_id, ProtoLengt #endif #ifdef USE_ALARM_CONTROL_PANEL void ListEntitiesAlarmControlPanelResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); #ifdef USE_ENTITY_ICON - buffer.encode_string(5, this->icon_ptr_, this->icon_len_); + buffer.encode_string(5, this->icon_ref_); #endif buffer.encode_bool(6, this->disabled_by_default); buffer.encode_uint32(7, static_cast(this->entity_category)); @@ -2398,11 +2398,11 @@ void ListEntitiesAlarmControlPanelResponse::encode(ProtoWriteBuffer buffer) cons #endif } void ListEntitiesAlarmControlPanelResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); @@ -2465,34 +2465,34 @@ bool AlarmControlPanelCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit #endif #ifdef USE_TEXT void ListEntitiesTextResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); #ifdef USE_ENTITY_ICON - buffer.encode_string(5, this->icon_ptr_, this->icon_len_); + buffer.encode_string(5, this->icon_ref_); #endif buffer.encode_bool(6, this->disabled_by_default); buffer.encode_uint32(7, static_cast(this->entity_category)); buffer.encode_uint32(8, this->min_length); buffer.encode_uint32(9, this->max_length); - buffer.encode_string(10, this->pattern_ptr_, this->pattern_len_); + buffer.encode_string(10, this->pattern_ref_); buffer.encode_uint32(11, static_cast(this->mode)); #ifdef USE_DEVICES buffer.encode_uint32(12, this->device_id); #endif } void ListEntitiesTextResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); ProtoSize::add_uint32_field(total_size, 1, this->min_length); ProtoSize::add_uint32_field(total_size, 1, this->max_length); - ProtoSize::add_string_field(total_size, 1, this->pattern_len_); + ProtoSize::add_string_field(total_size, 1, this->pattern_ref_.size()); ProtoSize::add_enum_field(total_size, 1, static_cast(this->mode)); #ifdef USE_DEVICES ProtoSize::add_uint32_field(total_size, 1, this->device_id); @@ -2500,7 +2500,7 @@ void ListEntitiesTextResponse::calculate_size(uint32_t &total_size) const { } void TextStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); - buffer.encode_string(2, this->state_ptr_, this->state_len_); + buffer.encode_string(2, this->state_ref_); buffer.encode_bool(3, this->missing_state); #ifdef USE_DEVICES buffer.encode_uint32(4, this->device_id); @@ -2508,7 +2508,7 @@ void TextStateResponse::encode(ProtoWriteBuffer buffer) const { } void TextStateResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->state_len_); + ProtoSize::add_string_field(total_size, 1, this->state_ref_.size()); ProtoSize::add_bool_field(total_size, 1, this->missing_state); #ifdef USE_DEVICES ProtoSize::add_uint32_field(total_size, 1, this->device_id); @@ -2549,11 +2549,11 @@ bool TextCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { #endif #ifdef USE_DATETIME_DATE void ListEntitiesDateResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); #ifdef USE_ENTITY_ICON - buffer.encode_string(5, this->icon_ptr_, this->icon_len_); + buffer.encode_string(5, this->icon_ref_); #endif buffer.encode_bool(6, this->disabled_by_default); buffer.encode_uint32(7, static_cast(this->entity_category)); @@ -2562,11 +2562,11 @@ void ListEntitiesDateResponse::encode(ProtoWriteBuffer buffer) const { #endif } void ListEntitiesDateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); @@ -2628,11 +2628,11 @@ bool DateCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { #endif #ifdef USE_DATETIME_TIME void ListEntitiesTimeResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); #ifdef USE_ENTITY_ICON - buffer.encode_string(5, this->icon_ptr_, this->icon_len_); + buffer.encode_string(5, this->icon_ref_); #endif buffer.encode_bool(6, this->disabled_by_default); buffer.encode_uint32(7, static_cast(this->entity_category)); @@ -2641,11 +2641,11 @@ void ListEntitiesTimeResponse::encode(ProtoWriteBuffer buffer) const { #endif } void ListEntitiesTimeResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); @@ -2707,15 +2707,15 @@ bool TimeCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { #endif #ifdef USE_EVENT void ListEntitiesEventResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); #ifdef USE_ENTITY_ICON - buffer.encode_string(5, this->icon_ptr_, this->icon_len_); + buffer.encode_string(5, this->icon_ref_); #endif buffer.encode_bool(6, this->disabled_by_default); buffer.encode_uint32(7, static_cast(this->entity_category)); - buffer.encode_string(8, this->device_class_ptr_, this->device_class_len_); + buffer.encode_string(8, this->device_class_ref_); for (auto &it : this->event_types) { buffer.encode_string(9, it, true); } @@ -2724,15 +2724,15 @@ void ListEntitiesEventResponse::encode(ProtoWriteBuffer buffer) const { #endif } void ListEntitiesEventResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); - ProtoSize::add_string_field(total_size, 1, this->device_class_len_); + ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); if (!this->event_types.empty()) { for (const auto &it : this->event_types) { ProtoSize::add_string_field(total_size, 1, it.length()); @@ -2744,14 +2744,14 @@ void ListEntitiesEventResponse::calculate_size(uint32_t &total_size) const { } void EventResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_fixed32(1, this->key); - buffer.encode_string(2, this->event_type_ptr_, this->event_type_len_); + buffer.encode_string(2, this->event_type_ref_); #ifdef USE_DEVICES buffer.encode_uint32(3, this->device_id); #endif } void EventResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->event_type_len_); + ProtoSize::add_string_field(total_size, 1, this->event_type_ref_.size()); #ifdef USE_DEVICES ProtoSize::add_uint32_field(total_size, 1, this->device_id); #endif @@ -2759,15 +2759,15 @@ void EventResponse::calculate_size(uint32_t &total_size) const { #endif #ifdef USE_VALVE void ListEntitiesValveResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); #ifdef USE_ENTITY_ICON - buffer.encode_string(5, this->icon_ptr_, this->icon_len_); + buffer.encode_string(5, this->icon_ref_); #endif buffer.encode_bool(6, this->disabled_by_default); buffer.encode_uint32(7, static_cast(this->entity_category)); - buffer.encode_string(8, this->device_class_ptr_, this->device_class_len_); + buffer.encode_string(8, this->device_class_ref_); buffer.encode_bool(9, this->assumed_state); buffer.encode_bool(10, this->supports_position); buffer.encode_bool(11, this->supports_stop); @@ -2776,15 +2776,15 @@ void ListEntitiesValveResponse::encode(ProtoWriteBuffer buffer) const { #endif } void ListEntitiesValveResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); - ProtoSize::add_string_field(total_size, 1, this->device_class_len_); + ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); ProtoSize::add_bool_field(total_size, 1, this->assumed_state); ProtoSize::add_bool_field(total_size, 1, this->supports_position); ProtoSize::add_bool_field(total_size, 1, this->supports_stop); @@ -2842,11 +2842,11 @@ bool ValveCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { #endif #ifdef USE_DATETIME_DATETIME void ListEntitiesDateTimeResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); #ifdef USE_ENTITY_ICON - buffer.encode_string(5, this->icon_ptr_, this->icon_len_); + buffer.encode_string(5, this->icon_ref_); #endif buffer.encode_bool(6, this->disabled_by_default); buffer.encode_uint32(7, static_cast(this->entity_category)); @@ -2855,11 +2855,11 @@ void ListEntitiesDateTimeResponse::encode(ProtoWriteBuffer buffer) const { #endif } void ListEntitiesDateTimeResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); @@ -2911,29 +2911,29 @@ bool DateTimeCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { #endif #ifdef USE_UPDATE void ListEntitiesUpdateResponse::encode(ProtoWriteBuffer buffer) const { - buffer.encode_string(1, this->object_id_ptr_, this->object_id_len_); + buffer.encode_string(1, this->object_id_ref_); buffer.encode_fixed32(2, this->key); - buffer.encode_string(3, this->name_ptr_, this->name_len_); + buffer.encode_string(3, this->name_ref_); #ifdef USE_ENTITY_ICON - buffer.encode_string(5, this->icon_ptr_, this->icon_len_); + buffer.encode_string(5, this->icon_ref_); #endif buffer.encode_bool(6, this->disabled_by_default); buffer.encode_uint32(7, static_cast(this->entity_category)); - buffer.encode_string(8, this->device_class_ptr_, this->device_class_len_); + buffer.encode_string(8, this->device_class_ref_); #ifdef USE_DEVICES buffer.encode_uint32(9, this->device_id); #endif } void ListEntitiesUpdateResponse::calculate_size(uint32_t &total_size) const { - ProtoSize::add_string_field(total_size, 1, this->object_id_len_); + ProtoSize::add_string_field(total_size, 1, this->object_id_ref_.size()); ProtoSize::add_fixed32_field(total_size, 1, this->key); - ProtoSize::add_string_field(total_size, 1, this->name_len_); + ProtoSize::add_string_field(total_size, 1, this->name_ref_.size()); #ifdef USE_ENTITY_ICON - ProtoSize::add_string_field(total_size, 1, this->icon_len_); + ProtoSize::add_string_field(total_size, 1, this->icon_ref_.size()); #endif ProtoSize::add_bool_field(total_size, 1, this->disabled_by_default); ProtoSize::add_enum_field(total_size, 1, static_cast(this->entity_category)); - ProtoSize::add_string_field(total_size, 1, this->device_class_len_); + ProtoSize::add_string_field(total_size, 1, this->device_class_ref_.size()); #ifdef USE_DEVICES ProtoSize::add_uint32_field(total_size, 1, this->device_id); #endif @@ -2944,11 +2944,11 @@ void UpdateStateResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_bool(3, this->in_progress); buffer.encode_bool(4, this->has_progress); buffer.encode_float(5, this->progress); - buffer.encode_string(6, this->current_version_ptr_, this->current_version_len_); - buffer.encode_string(7, this->latest_version_ptr_, this->latest_version_len_); - buffer.encode_string(8, this->title_ptr_, this->title_len_); - buffer.encode_string(9, this->release_summary_ptr_, this->release_summary_len_); - buffer.encode_string(10, this->release_url_ptr_, this->release_url_len_); + buffer.encode_string(6, this->current_version_ref_); + buffer.encode_string(7, this->latest_version_ref_); + buffer.encode_string(8, this->title_ref_); + buffer.encode_string(9, this->release_summary_ref_); + buffer.encode_string(10, this->release_url_ref_); #ifdef USE_DEVICES buffer.encode_uint32(11, this->device_id); #endif @@ -2959,11 +2959,11 @@ void UpdateStateResponse::calculate_size(uint32_t &total_size) const { ProtoSize::add_bool_field(total_size, 1, this->in_progress); ProtoSize::add_bool_field(total_size, 1, this->has_progress); ProtoSize::add_float_field(total_size, 1, this->progress); - ProtoSize::add_string_field(total_size, 1, this->current_version_len_); - ProtoSize::add_string_field(total_size, 1, this->latest_version_len_); - ProtoSize::add_string_field(total_size, 1, this->title_len_); - ProtoSize::add_string_field(total_size, 1, this->release_summary_len_); - ProtoSize::add_string_field(total_size, 1, this->release_url_len_); + ProtoSize::add_string_field(total_size, 1, this->current_version_ref_.size()); + ProtoSize::add_string_field(total_size, 1, this->latest_version_ref_.size()); + ProtoSize::add_string_field(total_size, 1, this->title_ref_.size()); + ProtoSize::add_string_field(total_size, 1, this->release_summary_ref_.size()); + ProtoSize::add_string_field(total_size, 1, this->release_url_ref_.size()); #ifdef USE_DEVICES ProtoSize::add_uint32_field(total_size, 1, this->device_id); #endif diff --git a/esphome/components/api/api_pb2.h b/esphome/components/api/api_pb2.h index e41bba4afc..7c432ed14e 100644 --- a/esphome/components/api/api_pb2.h +++ b/esphome/components/api/api_pb2.h @@ -3,6 +3,7 @@ #pragma once #include "esphome/core/defines.h" +#include "esphome/core/string_ref.h" #include "proto.h" @@ -269,27 +270,15 @@ enum UpdateCommand : uint32_t { class InfoResponseProtoMessage : public ProtoMessage { public: ~InfoResponseProtoMessage() override = default; - const char *object_id_ptr_{nullptr}; - size_t object_id_len_{0}; - void set_object_id(const char *data, size_t len) { - this->object_id_ptr_ = data; - this->object_id_len_ = len; - } + StringRef object_id_ref_{}; + void set_object_id(const StringRef &ref) { this->object_id_ref_ = ref; } uint32_t key{0}; - const char *name_ptr_{nullptr}; - size_t name_len_{0}; - void set_name(const char *data, size_t len) { - this->name_ptr_ = data; - this->name_len_ = len; - } + StringRef name_ref_{}; + void set_name(const StringRef &ref) { this->name_ref_ = ref; } bool disabled_by_default{false}; #ifdef USE_ENTITY_ICON - const char *icon_ptr_{nullptr}; - size_t icon_len_{0}; - void set_icon(const char *data, size_t len) { - this->icon_ptr_ = data; - this->icon_len_ = len; - } + StringRef icon_ref_{}; + void set_icon(const StringRef &ref) { this->icon_ref_ = ref; } #endif enums::EntityCategory entity_category{}; #ifdef USE_DEVICES @@ -347,18 +336,10 @@ class HelloResponse : public ProtoMessage { #endif uint32_t api_version_major{0}; uint32_t api_version_minor{0}; - const char *server_info_ptr_{nullptr}; - size_t server_info_len_{0}; - void set_server_info(const char *data, size_t len) { - this->server_info_ptr_ = data; - this->server_info_len_ = len; - } - const char *name_ptr_{nullptr}; - size_t name_len_{0}; - void set_name(const char *data, size_t len) { - this->name_ptr_ = data; - this->name_len_ = len; - } + StringRef server_info_ref_{}; + void set_server_info(const StringRef &ref) { this->server_info_ref_ = ref; } + StringRef name_ref_{}; + void set_name(const StringRef &ref) { this->name_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP @@ -467,12 +448,8 @@ class DeviceInfoRequest : public ProtoDecodableMessage { class AreaInfo : public ProtoMessage { public: uint32_t area_id{0}; - const char *name_ptr_{nullptr}; - size_t name_len_{0}; - void set_name(const char *data, size_t len) { - this->name_ptr_ = data; - this->name_len_ = len; - } + StringRef name_ref_{}; + void set_name(const StringRef &ref) { this->name_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP @@ -486,12 +463,8 @@ class AreaInfo : public ProtoMessage { class DeviceInfo : public ProtoMessage { public: uint32_t device_id{0}; - const char *name_ptr_{nullptr}; - size_t name_len_{0}; - void set_name(const char *data, size_t len) { - this->name_ptr_ = data; - this->name_len_ = len; - } + StringRef name_ref_{}; + void set_name(const StringRef &ref) { this->name_ref_ = ref; } uint32_t area_id{0}; void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; @@ -512,54 +485,26 @@ class DeviceInfoResponse : public ProtoMessage { #ifdef USE_API_PASSWORD bool uses_password{false}; #endif - const char *name_ptr_{nullptr}; - size_t name_len_{0}; - void set_name(const char *data, size_t len) { - this->name_ptr_ = data; - this->name_len_ = len; - } - const char *mac_address_ptr_{nullptr}; - size_t mac_address_len_{0}; - void set_mac_address(const char *data, size_t len) { - this->mac_address_ptr_ = data; - this->mac_address_len_ = len; - } - const char *esphome_version_ptr_{nullptr}; - size_t esphome_version_len_{0}; - void set_esphome_version(const char *data, size_t len) { - this->esphome_version_ptr_ = data; - this->esphome_version_len_ = len; - } - const char *compilation_time_ptr_{nullptr}; - size_t compilation_time_len_{0}; - void set_compilation_time(const char *data, size_t len) { - this->compilation_time_ptr_ = data; - this->compilation_time_len_ = len; - } - const char *model_ptr_{nullptr}; - size_t model_len_{0}; - void set_model(const char *data, size_t len) { - this->model_ptr_ = data; - this->model_len_ = len; - } + StringRef name_ref_{}; + void set_name(const StringRef &ref) { this->name_ref_ = ref; } + StringRef mac_address_ref_{}; + void set_mac_address(const StringRef &ref) { this->mac_address_ref_ = ref; } + StringRef esphome_version_ref_{}; + void set_esphome_version(const StringRef &ref) { this->esphome_version_ref_ = ref; } + StringRef compilation_time_ref_{}; + void set_compilation_time(const StringRef &ref) { this->compilation_time_ref_ = ref; } + StringRef model_ref_{}; + void set_model(const StringRef &ref) { this->model_ref_ = ref; } #ifdef USE_DEEP_SLEEP bool has_deep_sleep{false}; #endif #ifdef ESPHOME_PROJECT_NAME - const char *project_name_ptr_{nullptr}; - size_t project_name_len_{0}; - void set_project_name(const char *data, size_t len) { - this->project_name_ptr_ = data; - this->project_name_len_ = len; - } + StringRef project_name_ref_{}; + void set_project_name(const StringRef &ref) { this->project_name_ref_ = ref; } #endif #ifdef ESPHOME_PROJECT_NAME - const char *project_version_ptr_{nullptr}; - size_t project_version_len_{0}; - void set_project_version(const char *data, size_t len) { - this->project_version_ptr_ = data; - this->project_version_len_ = len; - } + StringRef project_version_ref_{}; + void set_project_version(const StringRef &ref) { this->project_version_ref_ = ref; } #endif #ifdef USE_WEBSERVER uint32_t webserver_port{0}; @@ -567,36 +512,20 @@ class DeviceInfoResponse : public ProtoMessage { #ifdef USE_BLUETOOTH_PROXY uint32_t bluetooth_proxy_feature_flags{0}; #endif - const char *manufacturer_ptr_{nullptr}; - size_t manufacturer_len_{0}; - void set_manufacturer(const char *data, size_t len) { - this->manufacturer_ptr_ = data; - this->manufacturer_len_ = len; - } - const char *friendly_name_ptr_{nullptr}; - size_t friendly_name_len_{0}; - void set_friendly_name(const char *data, size_t len) { - this->friendly_name_ptr_ = data; - this->friendly_name_len_ = len; - } + StringRef manufacturer_ref_{}; + void set_manufacturer(const StringRef &ref) { this->manufacturer_ref_ = ref; } + StringRef friendly_name_ref_{}; + void set_friendly_name(const StringRef &ref) { this->friendly_name_ref_ = ref; } #ifdef USE_VOICE_ASSISTANT uint32_t voice_assistant_feature_flags{0}; #endif #ifdef USE_AREAS - const char *suggested_area_ptr_{nullptr}; - size_t suggested_area_len_{0}; - void set_suggested_area(const char *data, size_t len) { - this->suggested_area_ptr_ = data; - this->suggested_area_len_ = len; - } + StringRef suggested_area_ref_{}; + void set_suggested_area(const StringRef &ref) { this->suggested_area_ref_ = ref; } #endif #ifdef USE_BLUETOOTH_PROXY - const char *bluetooth_mac_address_ptr_{nullptr}; - size_t bluetooth_mac_address_len_{0}; - void set_bluetooth_mac_address(const char *data, size_t len) { - this->bluetooth_mac_address_ptr_ = data; - this->bluetooth_mac_address_len_ = len; - } + StringRef bluetooth_mac_address_ref_{}; + void set_bluetooth_mac_address(const StringRef &ref) { this->bluetooth_mac_address_ref_ = ref; } #endif #ifdef USE_API_NOISE bool api_encryption_supported{false}; @@ -665,12 +594,8 @@ class ListEntitiesBinarySensorResponse : public InfoResponseProtoMessage { #ifdef HAS_PROTO_MESSAGE_DUMP const char *message_name() const override { return "list_entities_binary_sensor_response"; } #endif - const char *device_class_ptr_{nullptr}; - size_t device_class_len_{0}; - void set_device_class(const char *data, size_t len) { - this->device_class_ptr_ = data; - this->device_class_len_ = len; - } + StringRef device_class_ref_{}; + void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } bool is_status_binary_sensor{false}; void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; @@ -709,12 +634,8 @@ class ListEntitiesCoverResponse : public InfoResponseProtoMessage { bool assumed_state{false}; bool supports_position{false}; bool supports_tilt{false}; - const char *device_class_ptr_{nullptr}; - size_t device_class_len_{0}; - void set_device_class(const char *data, size_t len) { - this->device_class_ptr_ = data; - this->device_class_len_ = len; - } + StringRef device_class_ref_{}; + void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } bool supports_stop{false}; void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; @@ -795,12 +716,8 @@ class FanStateResponse : public StateResponseProtoMessage { bool oscillating{false}; enums::FanDirection direction{}; int32_t speed_level{0}; - const char *preset_mode_ptr_{nullptr}; - size_t preset_mode_len_{0}; - void set_preset_mode(const char *data, size_t len) { - this->preset_mode_ptr_ = data; - this->preset_mode_len_ = len; - } + StringRef preset_mode_ref_{}; + void set_preset_mode(const StringRef &ref) { this->preset_mode_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP @@ -874,12 +791,8 @@ class LightStateResponse : public StateResponseProtoMessage { float color_temperature{0.0f}; float cold_white{0.0f}; float warm_white{0.0f}; - const char *effect_ptr_{nullptr}; - size_t effect_len_{0}; - void set_effect(const char *data, size_t len) { - this->effect_ptr_ = data; - this->effect_len_ = len; - } + StringRef effect_ref_{}; + void set_effect(const StringRef &ref) { this->effect_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP @@ -939,20 +852,12 @@ class ListEntitiesSensorResponse : public InfoResponseProtoMessage { #ifdef HAS_PROTO_MESSAGE_DUMP const char *message_name() const override { return "list_entities_sensor_response"; } #endif - const char *unit_of_measurement_ptr_{nullptr}; - size_t unit_of_measurement_len_{0}; - void set_unit_of_measurement(const char *data, size_t len) { - this->unit_of_measurement_ptr_ = data; - this->unit_of_measurement_len_ = len; - } + StringRef unit_of_measurement_ref_{}; + void set_unit_of_measurement(const StringRef &ref) { this->unit_of_measurement_ref_ = ref; } int32_t accuracy_decimals{0}; bool force_update{false}; - const char *device_class_ptr_{nullptr}; - size_t device_class_len_{0}; - void set_device_class(const char *data, size_t len) { - this->device_class_ptr_ = data; - this->device_class_len_ = len; - } + StringRef device_class_ref_{}; + void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } enums::SensorStateClass state_class{}; void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; @@ -989,12 +894,8 @@ class ListEntitiesSwitchResponse : public InfoResponseProtoMessage { const char *message_name() const override { return "list_entities_switch_response"; } #endif bool assumed_state{false}; - const char *device_class_ptr_{nullptr}; - size_t device_class_len_{0}; - void set_device_class(const char *data, size_t len) { - this->device_class_ptr_ = data; - this->device_class_len_ = len; - } + StringRef device_class_ref_{}; + void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP @@ -1044,12 +945,8 @@ class ListEntitiesTextSensorResponse : public InfoResponseProtoMessage { #ifdef HAS_PROTO_MESSAGE_DUMP const char *message_name() const override { return "list_entities_text_sensor_response"; } #endif - const char *device_class_ptr_{nullptr}; - size_t device_class_len_{0}; - void set_device_class(const char *data, size_t len) { - this->device_class_ptr_ = data; - this->device_class_len_ = len; - } + StringRef device_class_ref_{}; + void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP @@ -1065,12 +962,8 @@ class TextSensorStateResponse : public StateResponseProtoMessage { #ifdef HAS_PROTO_MESSAGE_DUMP const char *message_name() const override { return "text_sensor_state_response"; } #endif - const char *state_ptr_{nullptr}; - size_t state_len_{0}; - void set_state(const char *data, size_t len) { - this->state_ptr_ = data; - this->state_len_ = len; - } + StringRef state_ref_{}; + void set_state(const StringRef &ref) { this->state_ref_ = ref; } bool missing_state{false}; void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; @@ -1167,18 +1060,10 @@ class SubscribeHomeassistantServicesRequest : public ProtoDecodableMessage { }; class HomeassistantServiceMap : public ProtoMessage { public: - const char *key_ptr_{nullptr}; - size_t key_len_{0}; - void set_key(const char *data, size_t len) { - this->key_ptr_ = data; - this->key_len_ = len; - } - const char *value_ptr_{nullptr}; - size_t value_len_{0}; - void set_value(const char *data, size_t len) { - this->value_ptr_ = data; - this->value_len_ = len; - } + StringRef key_ref_{}; + void set_key(const StringRef &ref) { this->key_ref_ = ref; } + StringRef value_ref_{}; + void set_value(const StringRef &ref) { this->value_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP @@ -1194,12 +1079,8 @@ class HomeassistantServiceResponse : public ProtoMessage { #ifdef HAS_PROTO_MESSAGE_DUMP const char *message_name() const override { return "homeassistant_service_response"; } #endif - const char *service_ptr_{nullptr}; - size_t service_len_{0}; - void set_service(const char *data, size_t len) { - this->service_ptr_ = data; - this->service_len_ = len; - } + StringRef service_ref_{}; + void set_service(const StringRef &ref) { this->service_ref_ = ref; } std::vector data{}; std::vector data_template{}; std::vector variables{}; @@ -1232,18 +1113,10 @@ class SubscribeHomeAssistantStateResponse : public ProtoMessage { #ifdef HAS_PROTO_MESSAGE_DUMP const char *message_name() const override { return "subscribe_home_assistant_state_response"; } #endif - const char *entity_id_ptr_{nullptr}; - size_t entity_id_len_{0}; - void set_entity_id(const char *data, size_t len) { - this->entity_id_ptr_ = data; - this->entity_id_len_ = len; - } - const char *attribute_ptr_{nullptr}; - size_t attribute_len_{0}; - void set_attribute(const char *data, size_t len) { - this->attribute_ptr_ = data; - this->attribute_len_ = len; - } + StringRef entity_id_ref_{}; + void set_entity_id(const StringRef &ref) { this->entity_id_ref_ = ref; } + StringRef attribute_ref_{}; + void set_attribute(const StringRef &ref) { this->attribute_ref_ = ref; } bool once{false}; void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; @@ -1303,12 +1176,8 @@ class GetTimeResponse : public ProtoDecodableMessage { #ifdef USE_API_SERVICES class ListEntitiesServicesArgument : public ProtoMessage { public: - const char *name_ptr_{nullptr}; - size_t name_len_{0}; - void set_name(const char *data, size_t len) { - this->name_ptr_ = data; - this->name_len_ = len; - } + StringRef name_ref_{}; + void set_name(const StringRef &ref) { this->name_ref_ = ref; } enums::ServiceArgType type{}; void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; @@ -1325,12 +1194,8 @@ class ListEntitiesServicesResponse : public ProtoMessage { #ifdef HAS_PROTO_MESSAGE_DUMP const char *message_name() const override { return "list_entities_services_response"; } #endif - const char *name_ptr_{nullptr}; - size_t name_len_{0}; - void set_name(const char *data, size_t len) { - this->name_ptr_ = data; - this->name_len_ = len; - } + StringRef name_ref_{}; + void set_name(const StringRef &ref) { this->name_ref_ = ref; } uint32_t key{0}; std::vector args{}; void encode(ProtoWriteBuffer buffer) const override; @@ -1482,19 +1347,11 @@ class ClimateStateResponse : public StateResponseProtoMessage { enums::ClimateAction action{}; enums::ClimateFanMode fan_mode{}; enums::ClimateSwingMode swing_mode{}; - const char *custom_fan_mode_ptr_{nullptr}; - size_t custom_fan_mode_len_{0}; - void set_custom_fan_mode(const char *data, size_t len) { - this->custom_fan_mode_ptr_ = data; - this->custom_fan_mode_len_ = len; - } + StringRef custom_fan_mode_ref_{}; + void set_custom_fan_mode(const StringRef &ref) { this->custom_fan_mode_ref_ = ref; } enums::ClimatePreset preset{}; - const char *custom_preset_ptr_{nullptr}; - size_t custom_preset_len_{0}; - void set_custom_preset(const char *data, size_t len) { - this->custom_preset_ptr_ = data; - this->custom_preset_len_ = len; - } + StringRef custom_preset_ref_{}; + void set_custom_preset(const StringRef &ref) { this->custom_preset_ref_ = ref; } float current_humidity{0.0f}; float target_humidity{0.0f}; void encode(ProtoWriteBuffer buffer) const override; @@ -1553,19 +1410,11 @@ class ListEntitiesNumberResponse : public InfoResponseProtoMessage { float min_value{0.0f}; float max_value{0.0f}; float step{0.0f}; - const char *unit_of_measurement_ptr_{nullptr}; - size_t unit_of_measurement_len_{0}; - void set_unit_of_measurement(const char *data, size_t len) { - this->unit_of_measurement_ptr_ = data; - this->unit_of_measurement_len_ = len; - } + StringRef unit_of_measurement_ref_{}; + void set_unit_of_measurement(const StringRef &ref) { this->unit_of_measurement_ref_ = ref; } enums::NumberMode mode{}; - const char *device_class_ptr_{nullptr}; - size_t device_class_len_{0}; - void set_device_class(const char *data, size_t len) { - this->device_class_ptr_ = data; - this->device_class_len_ = len; - } + StringRef device_class_ref_{}; + void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP @@ -1632,12 +1481,8 @@ class SelectStateResponse : public StateResponseProtoMessage { #ifdef HAS_PROTO_MESSAGE_DUMP const char *message_name() const override { return "select_state_response"; } #endif - const char *state_ptr_{nullptr}; - size_t state_len_{0}; - void set_state(const char *data, size_t len) { - this->state_ptr_ = data; - this->state_len_ = len; - } + StringRef state_ref_{}; + void set_state(const StringRef &ref) { this->state_ref_ = ref; } bool missing_state{false}; void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; @@ -1736,12 +1581,8 @@ class ListEntitiesLockResponse : public InfoResponseProtoMessage { bool assumed_state{false}; bool supports_open{false}; bool requires_code{false}; - const char *code_format_ptr_{nullptr}; - size_t code_format_len_{0}; - void set_code_format(const char *data, size_t len) { - this->code_format_ptr_ = data; - this->code_format_len_ = len; - } + StringRef code_format_ref_{}; + void set_code_format(const StringRef &ref) { this->code_format_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP @@ -1794,12 +1635,8 @@ class ListEntitiesButtonResponse : public InfoResponseProtoMessage { #ifdef HAS_PROTO_MESSAGE_DUMP const char *message_name() const override { return "list_entities_button_response"; } #endif - const char *device_class_ptr_{nullptr}; - size_t device_class_len_{0}; - void set_device_class(const char *data, size_t len) { - this->device_class_ptr_ = data; - this->device_class_len_ = len; - } + StringRef device_class_ref_{}; + void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP @@ -1827,12 +1664,8 @@ class ButtonCommandRequest : public CommandProtoMessage { #ifdef USE_MEDIA_PLAYER class MediaPlayerSupportedFormat : public ProtoMessage { public: - const char *format_ptr_{nullptr}; - size_t format_len_{0}; - void set_format(const char *data, size_t len) { - this->format_ptr_ = data; - this->format_len_ = len; - } + StringRef format_ref_{}; + void set_format(const StringRef &ref) { this->format_ref_ = ref; } uint32_t sample_rate{0}; uint32_t num_channels{0}; enums::MediaPlayerFormatPurpose purpose{}; @@ -2429,20 +2262,12 @@ class VoiceAssistantRequest : public ProtoMessage { const char *message_name() const override { return "voice_assistant_request"; } #endif bool start{false}; - const char *conversation_id_ptr_{nullptr}; - size_t conversation_id_len_{0}; - void set_conversation_id(const char *data, size_t len) { - this->conversation_id_ptr_ = data; - this->conversation_id_len_ = len; - } + StringRef conversation_id_ref_{}; + void set_conversation_id(const StringRef &ref) { this->conversation_id_ref_ = ref; } uint32_t flags{0}; VoiceAssistantAudioSettings audio_settings{}; - const char *wake_word_phrase_ptr_{nullptr}; - size_t wake_word_phrase_len_{0}; - void set_wake_word_phrase(const char *data, size_t len) { - this->wake_word_phrase_ptr_ = data; - this->wake_word_phrase_len_ = len; - } + StringRef wake_word_phrase_ref_{}; + void set_wake_word_phrase(const StringRef &ref) { this->wake_word_phrase_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP @@ -2578,18 +2403,10 @@ class VoiceAssistantAnnounceFinished : public ProtoMessage { }; class VoiceAssistantWakeWord : public ProtoMessage { public: - const char *id_ptr_{nullptr}; - size_t id_len_{0}; - void set_id(const char *data, size_t len) { - this->id_ptr_ = data; - this->id_len_ = len; - } - const char *wake_word_ptr_{nullptr}; - size_t wake_word_len_{0}; - void set_wake_word(const char *data, size_t len) { - this->wake_word_ptr_ = data; - this->wake_word_len_ = len; - } + StringRef id_ref_{}; + void set_id(const StringRef &ref) { this->id_ref_ = ref; } + StringRef wake_word_ref_{}; + void set_wake_word(const StringRef &ref) { this->wake_word_ref_ = ref; } std::vector trained_languages{}; void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; @@ -2710,12 +2527,8 @@ class ListEntitiesTextResponse : public InfoResponseProtoMessage { #endif uint32_t min_length{0}; uint32_t max_length{0}; - const char *pattern_ptr_{nullptr}; - size_t pattern_len_{0}; - void set_pattern(const char *data, size_t len) { - this->pattern_ptr_ = data; - this->pattern_len_ = len; - } + StringRef pattern_ref_{}; + void set_pattern(const StringRef &ref) { this->pattern_ref_ = ref; } enums::TextMode mode{}; void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; @@ -2732,12 +2545,8 @@ class TextStateResponse : public StateResponseProtoMessage { #ifdef HAS_PROTO_MESSAGE_DUMP const char *message_name() const override { return "text_state_response"; } #endif - const char *state_ptr_{nullptr}; - size_t state_len_{0}; - void set_state(const char *data, size_t len) { - this->state_ptr_ = data; - this->state_len_ = len; - } + StringRef state_ref_{}; + void set_state(const StringRef &ref) { this->state_ref_ = ref; } bool missing_state{false}; void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; @@ -2881,12 +2690,8 @@ class ListEntitiesEventResponse : public InfoResponseProtoMessage { #ifdef HAS_PROTO_MESSAGE_DUMP const char *message_name() const override { return "list_entities_event_response"; } #endif - const char *device_class_ptr_{nullptr}; - size_t device_class_len_{0}; - void set_device_class(const char *data, size_t len) { - this->device_class_ptr_ = data; - this->device_class_len_ = len; - } + StringRef device_class_ref_{}; + void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } std::vector event_types{}; void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; @@ -2903,12 +2708,8 @@ class EventResponse : public StateResponseProtoMessage { #ifdef HAS_PROTO_MESSAGE_DUMP const char *message_name() const override { return "event_response"; } #endif - const char *event_type_ptr_{nullptr}; - size_t event_type_len_{0}; - void set_event_type(const char *data, size_t len) { - this->event_type_ptr_ = data; - this->event_type_len_ = len; - } + StringRef event_type_ref_{}; + void set_event_type(const StringRef &ref) { this->event_type_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP @@ -2926,12 +2727,8 @@ class ListEntitiesValveResponse : public InfoResponseProtoMessage { #ifdef HAS_PROTO_MESSAGE_DUMP const char *message_name() const override { return "list_entities_valve_response"; } #endif - const char *device_class_ptr_{nullptr}; - size_t device_class_len_{0}; - void set_device_class(const char *data, size_t len) { - this->device_class_ptr_ = data; - this->device_class_len_ = len; - } + StringRef device_class_ref_{}; + void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } bool assumed_state{false}; bool supports_position{false}; bool supports_stop{false}; @@ -3037,12 +2834,8 @@ class ListEntitiesUpdateResponse : public InfoResponseProtoMessage { #ifdef HAS_PROTO_MESSAGE_DUMP const char *message_name() const override { return "list_entities_update_response"; } #endif - const char *device_class_ptr_{nullptr}; - size_t device_class_len_{0}; - void set_device_class(const char *data, size_t len) { - this->device_class_ptr_ = data; - this->device_class_len_ = len; - } + StringRef device_class_ref_{}; + void set_device_class(const StringRef &ref) { this->device_class_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP @@ -3062,36 +2855,16 @@ class UpdateStateResponse : public StateResponseProtoMessage { bool in_progress{false}; bool has_progress{false}; float progress{0.0f}; - const char *current_version_ptr_{nullptr}; - size_t current_version_len_{0}; - void set_current_version(const char *data, size_t len) { - this->current_version_ptr_ = data; - this->current_version_len_ = len; - } - const char *latest_version_ptr_{nullptr}; - size_t latest_version_len_{0}; - void set_latest_version(const char *data, size_t len) { - this->latest_version_ptr_ = data; - this->latest_version_len_ = len; - } - const char *title_ptr_{nullptr}; - size_t title_len_{0}; - void set_title(const char *data, size_t len) { - this->title_ptr_ = data; - this->title_len_ = len; - } - const char *release_summary_ptr_{nullptr}; - size_t release_summary_len_{0}; - void set_release_summary(const char *data, size_t len) { - this->release_summary_ptr_ = data; - this->release_summary_len_ = len; - } - const char *release_url_ptr_{nullptr}; - size_t release_url_len_{0}; - void set_release_url(const char *data, size_t len) { - this->release_url_ptr_ = data; - this->release_url_len_ = len; - } + StringRef current_version_ref_{}; + void set_current_version(const StringRef &ref) { this->current_version_ref_ = ref; } + StringRef latest_version_ref_{}; + void set_latest_version(const StringRef &ref) { this->latest_version_ref_ = ref; } + StringRef title_ref_{}; + void set_title(const StringRef &ref) { this->title_ref_ = ref; } + StringRef release_summary_ref_{}; + void set_release_summary(const StringRef &ref) { this->release_summary_ref_ = ref; } + StringRef release_url_ref_{}; + void set_release_url(const StringRef &ref) { this->release_url_ref_ = ref; } void encode(ProtoWriteBuffer buffer) const override; void calculate_size(uint32_t &total_size) const override; #ifdef HAS_PROTO_MESSAGE_DUMP diff --git a/esphome/components/api/api_pb2_dump.cpp b/esphome/components/api/api_pb2_dump.cpp index 48121f38c7..dd1c02b469 100644 --- a/esphome/components/api/api_pb2_dump.cpp +++ b/esphome/components/api/api_pb2_dump.cpp @@ -580,16 +580,16 @@ void HelloResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" server_info: "); - if (this->server_info_ptr_ != nullptr) { - out.append("'").append(this->server_info_ptr_).append("'"); + if (!this->server_info_ref_.empty()) { + out.append("'").append(this->server_info_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -627,8 +627,8 @@ void AreaInfo::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -646,8 +646,8 @@ void DeviceInfo::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -670,40 +670,40 @@ void DeviceInfoResponse::dump_to(std::string &out) const { #endif out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } out.append("\n"); out.append(" mac_address: "); - if (this->mac_address_ptr_ != nullptr) { - out.append("'").append(this->mac_address_ptr_).append("'"); + if (!this->mac_address_ref_.empty()) { + out.append("'").append(this->mac_address_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } out.append("\n"); out.append(" esphome_version: "); - if (this->esphome_version_ptr_ != nullptr) { - out.append("'").append(this->esphome_version_ptr_).append("'"); + if (!this->esphome_version_ref_.empty()) { + out.append("'").append(this->esphome_version_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } out.append("\n"); out.append(" compilation_time: "); - if (this->compilation_time_ptr_ != nullptr) { - out.append("'").append(this->compilation_time_ptr_).append("'"); + if (!this->compilation_time_ref_.empty()) { + out.append("'").append(this->compilation_time_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } out.append("\n"); out.append(" model: "); - if (this->model_ptr_ != nullptr) { - out.append("'").append(this->model_ptr_).append("'"); + if (!this->model_ref_.empty()) { + out.append("'").append(this->model_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -717,8 +717,8 @@ void DeviceInfoResponse::dump_to(std::string &out) const { #endif #ifdef ESPHOME_PROJECT_NAME out.append(" project_name: "); - if (this->project_name_ptr_ != nullptr) { - out.append("'").append(this->project_name_ptr_).append("'"); + if (!this->project_name_ref_.empty()) { + out.append("'").append(this->project_name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -727,8 +727,8 @@ void DeviceInfoResponse::dump_to(std::string &out) const { #endif #ifdef ESPHOME_PROJECT_NAME out.append(" project_version: "); - if (this->project_version_ptr_ != nullptr) { - out.append("'").append(this->project_version_ptr_).append("'"); + if (!this->project_version_ref_.empty()) { + out.append("'").append(this->project_version_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -750,16 +750,16 @@ void DeviceInfoResponse::dump_to(std::string &out) const { #endif out.append(" manufacturer: "); - if (this->manufacturer_ptr_ != nullptr) { - out.append("'").append(this->manufacturer_ptr_).append("'"); + if (!this->manufacturer_ref_.empty()) { + out.append("'").append(this->manufacturer_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } out.append("\n"); out.append(" friendly_name: "); - if (this->friendly_name_ptr_ != nullptr) { - out.append("'").append(this->friendly_name_ptr_).append("'"); + if (!this->friendly_name_ref_.empty()) { + out.append("'").append(this->friendly_name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -774,8 +774,8 @@ void DeviceInfoResponse::dump_to(std::string &out) const { #endif #ifdef USE_AREAS out.append(" suggested_area: "); - if (this->suggested_area_ptr_ != nullptr) { - out.append("'").append(this->suggested_area_ptr_).append("'"); + if (!this->suggested_area_ref_.empty()) { + out.append("'").append(this->suggested_area_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -784,8 +784,8 @@ void DeviceInfoResponse::dump_to(std::string &out) const { #endif #ifdef USE_BLUETOOTH_PROXY out.append(" bluetooth_mac_address: "); - if (this->bluetooth_mac_address_ptr_ != nullptr) { - out.append("'").append(this->bluetooth_mac_address_ptr_).append("'"); + if (!this->bluetooth_mac_address_ref_.empty()) { + out.append("'").append(this->bluetooth_mac_address_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -830,8 +830,8 @@ void ListEntitiesBinarySensorResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesBinarySensorResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -843,16 +843,16 @@ void ListEntitiesBinarySensorResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } out.append("\n"); out.append(" device_class: "); - if (this->device_class_ptr_ != nullptr) { - out.append("'").append(this->device_class_ptr_).append("'"); + if (!this->device_class_ref_.empty()) { + out.append("'").append(this->device_class_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -868,8 +868,8 @@ void ListEntitiesBinarySensorResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -920,8 +920,8 @@ void ListEntitiesCoverResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesCoverResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -933,8 +933,8 @@ void ListEntitiesCoverResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -953,8 +953,8 @@ void ListEntitiesCoverResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" device_class: "); - if (this->device_class_ptr_ != nullptr) { - out.append("'").append(this->device_class_ptr_).append("'"); + if (!this->device_class_ref_.empty()) { + out.append("'").append(this->device_class_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -966,8 +966,8 @@ void ListEntitiesCoverResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1067,8 +1067,8 @@ void ListEntitiesFanResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesFanResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1080,8 +1080,8 @@ void ListEntitiesFanResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1110,8 +1110,8 @@ void ListEntitiesFanResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1124,8 +1124,8 @@ void ListEntitiesFanResponse::dump_to(std::string &out) const { for (const auto &it : this->supported_preset_modes) { out.append(" supported_preset_modes: "); - if (this->supported_preset_modes_ptr_ != nullptr) { - out.append("'").append(this->supported_preset_modes_ptr_).append("'"); + if (!this->supported_preset_modes_ref_.empty()) { + out.append("'").append(this->supported_preset_modes_ref_.c_str()).append("'"); } else { out.append("'").append(this->supported_preset_modes).append("'"); } @@ -1167,8 +1167,8 @@ void FanStateResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" preset_mode: "); - if (this->preset_mode_ptr_ != nullptr) { - out.append("'").append(this->preset_mode_ptr_).append("'"); + if (!this->preset_mode_ref_.empty()) { + out.append("'").append(this->preset_mode_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1247,8 +1247,8 @@ void ListEntitiesLightResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesLightResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1260,8 +1260,8 @@ void ListEntitiesLightResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1285,8 +1285,8 @@ void ListEntitiesLightResponse::dump_to(std::string &out) const { for (const auto &it : this->effects) { out.append(" effects: "); - if (this->effects_ptr_ != nullptr) { - out.append("'").append(this->effects_ptr_).append("'"); + if (!this->effects_ref_.empty()) { + out.append("'").append(this->effects_ref_.c_str()).append("'"); } else { out.append("'").append(this->effects).append("'"); } @@ -1299,8 +1299,8 @@ void ListEntitiesLightResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1382,8 +1382,8 @@ void LightStateResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" effect: "); - if (this->effect_ptr_ != nullptr) { - out.append("'").append(this->effect_ptr_).append("'"); + if (!this->effect_ref_.empty()) { + out.append("'").append(this->effect_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1536,8 +1536,8 @@ void ListEntitiesSensorResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesSensorResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1549,8 +1549,8 @@ void ListEntitiesSensorResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1558,8 +1558,8 @@ void ListEntitiesSensorResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1567,8 +1567,8 @@ void ListEntitiesSensorResponse::dump_to(std::string &out) const { #endif out.append(" unit_of_measurement: "); - if (this->unit_of_measurement_ptr_ != nullptr) { - out.append("'").append(this->unit_of_measurement_ptr_).append("'"); + if (!this->unit_of_measurement_ref_.empty()) { + out.append("'").append(this->unit_of_measurement_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1584,8 +1584,8 @@ void ListEntitiesSensorResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" device_class: "); - if (this->device_class_ptr_ != nullptr) { - out.append("'").append(this->device_class_ptr_).append("'"); + if (!this->device_class_ref_.empty()) { + out.append("'").append(this->device_class_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1644,8 +1644,8 @@ void ListEntitiesSwitchResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesSwitchResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1657,8 +1657,8 @@ void ListEntitiesSwitchResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1666,8 +1666,8 @@ void ListEntitiesSwitchResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1687,8 +1687,8 @@ void ListEntitiesSwitchResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" device_class: "); - if (this->device_class_ptr_ != nullptr) { - out.append("'").append(this->device_class_ptr_).append("'"); + if (!this->device_class_ref_.empty()) { + out.append("'").append(this->device_class_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1751,8 +1751,8 @@ void ListEntitiesTextSensorResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesTextSensorResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1764,8 +1764,8 @@ void ListEntitiesTextSensorResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1773,8 +1773,8 @@ void ListEntitiesTextSensorResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1790,8 +1790,8 @@ void ListEntitiesTextSensorResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" device_class: "); - if (this->device_class_ptr_ != nullptr) { - out.append("'").append(this->device_class_ptr_).append("'"); + if (!this->device_class_ref_.empty()) { + out.append("'").append(this->device_class_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1815,8 +1815,8 @@ void TextSensorStateResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" state: "); - if (this->state_ptr_ != nullptr) { - out.append("'").append(this->state_ptr_).append("'"); + if (!this->state_ref_.empty()) { + out.append("'").append(this->state_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1885,16 +1885,16 @@ void HomeassistantServiceMap::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("HomeassistantServiceMap {\n"); out.append(" key: "); - if (this->key_ptr_ != nullptr) { - out.append("'").append(this->key_ptr_).append("'"); + if (!this->key_ref_.empty()) { + out.append("'").append(this->key_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } out.append("\n"); out.append(" value: "); - if (this->value_ptr_ != nullptr) { - out.append("'").append(this->value_ptr_).append("'"); + if (!this->value_ref_.empty()) { + out.append("'").append(this->value_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1905,8 +1905,8 @@ void HomeassistantServiceResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("HomeassistantServiceResponse {\n"); out.append(" service: "); - if (this->service_ptr_ != nullptr) { - out.append("'").append(this->service_ptr_).append("'"); + if (!this->service_ref_.empty()) { + out.append("'").append(this->service_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1942,16 +1942,16 @@ void SubscribeHomeAssistantStateResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("SubscribeHomeAssistantStateResponse {\n"); out.append(" entity_id: "); - if (this->entity_id_ptr_ != nullptr) { - out.append("'").append(this->entity_id_ptr_).append("'"); + if (!this->entity_id_ref_.empty()) { + out.append("'").append(this->entity_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } out.append("\n"); out.append(" attribute: "); - if (this->attribute_ptr_ != nullptr) { - out.append("'").append(this->attribute_ptr_).append("'"); + if (!this->attribute_ref_.empty()) { + out.append("'").append(this->attribute_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -1993,8 +1993,8 @@ void ListEntitiesServicesArgument::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesServicesArgument {\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2009,8 +2009,8 @@ void ListEntitiesServicesResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesServicesResponse {\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2076,8 +2076,8 @@ void ExecuteServiceArgument::dump_to(std::string &out) const { for (const auto &it : this->string_array) { out.append(" string_array: "); - if (this->string_array_ptr_ != nullptr) { - out.append("'").append(this->string_array_ptr_).append("'"); + if (!this->string_array_ref_.empty()) { + out.append("'").append(this->string_array_ref_.c_str()).append("'"); } else { out.append("'").append(this->string_array).append("'"); } @@ -2106,8 +2106,8 @@ void ListEntitiesCameraResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesCameraResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2119,8 +2119,8 @@ void ListEntitiesCameraResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2132,8 +2132,8 @@ void ListEntitiesCameraResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2196,8 +2196,8 @@ void ListEntitiesClimateResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesClimateResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2209,8 +2209,8 @@ void ListEntitiesClimateResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2263,8 +2263,8 @@ void ListEntitiesClimateResponse::dump_to(std::string &out) const { for (const auto &it : this->supported_custom_fan_modes) { out.append(" supported_custom_fan_modes: "); - if (this->supported_custom_fan_modes_ptr_ != nullptr) { - out.append("'").append(this->supported_custom_fan_modes_ptr_).append("'"); + if (!this->supported_custom_fan_modes_ref_.empty()) { + out.append("'").append(this->supported_custom_fan_modes_ref_.c_str()).append("'"); } else { out.append("'").append(this->supported_custom_fan_modes).append("'"); } @@ -2279,8 +2279,8 @@ void ListEntitiesClimateResponse::dump_to(std::string &out) const { for (const auto &it : this->supported_custom_presets) { out.append(" supported_custom_presets: "); - if (this->supported_custom_presets_ptr_ != nullptr) { - out.append("'").append(this->supported_custom_presets_ptr_).append("'"); + if (!this->supported_custom_presets_ref_.empty()) { + out.append("'").append(this->supported_custom_presets_ref_.c_str()).append("'"); } else { out.append("'").append(this->supported_custom_presets).append("'"); } @@ -2293,8 +2293,8 @@ void ListEntitiesClimateResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2382,8 +2382,8 @@ void ClimateStateResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" custom_fan_mode: "); - if (this->custom_fan_mode_ptr_ != nullptr) { - out.append("'").append(this->custom_fan_mode_ptr_).append("'"); + if (!this->custom_fan_mode_ref_.empty()) { + out.append("'").append(this->custom_fan_mode_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2394,8 +2394,8 @@ void ClimateStateResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" custom_preset: "); - if (this->custom_preset_ptr_ != nullptr) { - out.append("'").append(this->custom_preset_ptr_).append("'"); + if (!this->custom_preset_ref_.empty()) { + out.append("'").append(this->custom_preset_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2527,8 +2527,8 @@ void ListEntitiesNumberResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesNumberResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2540,8 +2540,8 @@ void ListEntitiesNumberResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2549,8 +2549,8 @@ void ListEntitiesNumberResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2581,8 +2581,8 @@ void ListEntitiesNumberResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" unit_of_measurement: "); - if (this->unit_of_measurement_ptr_ != nullptr) { - out.append("'").append(this->unit_of_measurement_ptr_).append("'"); + if (!this->unit_of_measurement_ref_.empty()) { + out.append("'").append(this->unit_of_measurement_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2593,8 +2593,8 @@ void ListEntitiesNumberResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" device_class: "); - if (this->device_class_ptr_ != nullptr) { - out.append("'").append(this->device_class_ptr_).append("'"); + if (!this->device_class_ref_.empty()) { + out.append("'").append(this->device_class_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2663,8 +2663,8 @@ void ListEntitiesSelectResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesSelectResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2676,8 +2676,8 @@ void ListEntitiesSelectResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2685,8 +2685,8 @@ void ListEntitiesSelectResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2695,8 +2695,8 @@ void ListEntitiesSelectResponse::dump_to(std::string &out) const { #endif for (const auto &it : this->options) { out.append(" options: "); - if (this->options_ptr_ != nullptr) { - out.append("'").append(this->options_ptr_).append("'"); + if (!this->options_ref_.empty()) { + out.append("'").append(this->options_ref_.c_str()).append("'"); } else { out.append("'").append(this->options).append("'"); } @@ -2729,8 +2729,8 @@ void SelectStateResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" state: "); - if (this->state_ptr_ != nullptr) { - out.append("'").append(this->state_ptr_).append("'"); + if (!this->state_ref_.empty()) { + out.append("'").append(this->state_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2776,8 +2776,8 @@ void ListEntitiesSirenResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesSirenResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2789,8 +2789,8 @@ void ListEntitiesSirenResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2798,8 +2798,8 @@ void ListEntitiesSirenResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2812,8 +2812,8 @@ void ListEntitiesSirenResponse::dump_to(std::string &out) const { for (const auto &it : this->tones) { out.append(" tones: "); - if (this->tones_ptr_ != nullptr) { - out.append("'").append(this->tones_ptr_).append("'"); + if (!this->tones_ref_.empty()) { + out.append("'").append(this->tones_ref_.c_str()).append("'"); } else { out.append("'").append(this->tones).append("'"); } @@ -2919,8 +2919,8 @@ void ListEntitiesLockResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesLockResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2932,8 +2932,8 @@ void ListEntitiesLockResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2941,8 +2941,8 @@ void ListEntitiesLockResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -2970,8 +2970,8 @@ void ListEntitiesLockResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" code_format: "); - if (this->code_format_ptr_ != nullptr) { - out.append("'").append(this->code_format_ptr_).append("'"); + if (!this->code_format_ref_.empty()) { + out.append("'").append(this->code_format_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -3042,8 +3042,8 @@ void ListEntitiesButtonResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesButtonResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -3055,8 +3055,8 @@ void ListEntitiesButtonResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -3064,8 +3064,8 @@ void ListEntitiesButtonResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -3081,8 +3081,8 @@ void ListEntitiesButtonResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" device_class: "); - if (this->device_class_ptr_ != nullptr) { - out.append("'").append(this->device_class_ptr_).append("'"); + if (!this->device_class_ref_.empty()) { + out.append("'").append(this->device_class_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -3120,8 +3120,8 @@ void MediaPlayerSupportedFormat::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("MediaPlayerSupportedFormat {\n"); out.append(" format: "); - if (this->format_ptr_ != nullptr) { - out.append("'").append(this->format_ptr_).append("'"); + if (!this->format_ref_.empty()) { + out.append("'").append(this->format_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -3151,8 +3151,8 @@ void ListEntitiesMediaPlayerResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesMediaPlayerResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -3164,8 +3164,8 @@ void ListEntitiesMediaPlayerResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -3173,8 +3173,8 @@ void ListEntitiesMediaPlayerResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -3787,8 +3787,8 @@ void VoiceAssistantRequest::dump_to(std::string &out) const { out.append("\n"); out.append(" conversation_id: "); - if (this->conversation_id_ptr_ != nullptr) { - out.append("'").append(this->conversation_id_ptr_).append("'"); + if (!this->conversation_id_ref_.empty()) { + out.append("'").append(this->conversation_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -3804,8 +3804,8 @@ void VoiceAssistantRequest::dump_to(std::string &out) const { out.append("\n"); out.append(" wake_word_phrase: "); - if (this->wake_word_phrase_ptr_ != nullptr) { - out.append("'").append(this->wake_word_phrase_ptr_).append("'"); + if (!this->wake_word_phrase_ref_.empty()) { + out.append("'").append(this->wake_word_phrase_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -3929,16 +3929,16 @@ void VoiceAssistantWakeWord::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("VoiceAssistantWakeWord {\n"); out.append(" id: "); - if (this->id_ptr_ != nullptr) { - out.append("'").append(this->id_ptr_).append("'"); + if (!this->id_ref_.empty()) { + out.append("'").append(this->id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } out.append("\n"); out.append(" wake_word: "); - if (this->wake_word_ptr_ != nullptr) { - out.append("'").append(this->wake_word_ptr_).append("'"); + if (!this->wake_word_ref_.empty()) { + out.append("'").append(this->wake_word_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -3946,8 +3946,8 @@ void VoiceAssistantWakeWord::dump_to(std::string &out) const { for (const auto &it : this->trained_languages) { out.append(" trained_languages: "); - if (this->trained_languages_ptr_ != nullptr) { - out.append("'").append(this->trained_languages_ptr_).append("'"); + if (!this->trained_languages_ref_.empty()) { + out.append("'").append(this->trained_languages_ref_.c_str()).append("'"); } else { out.append("'").append(this->trained_languages).append("'"); } @@ -3969,8 +3969,8 @@ void VoiceAssistantConfigurationResponse::dump_to(std::string &out) const { for (const auto &it : this->active_wake_words) { out.append(" active_wake_words: "); - if (this->active_wake_words_ptr_ != nullptr) { - out.append("'").append(this->active_wake_words_ptr_).append("'"); + if (!this->active_wake_words_ref_.empty()) { + out.append("'").append(this->active_wake_words_ref_.c_str()).append("'"); } else { out.append("'").append(this->active_wake_words).append("'"); } @@ -3988,8 +3988,8 @@ void VoiceAssistantSetConfiguration::dump_to(std::string &out) const { out.append("VoiceAssistantSetConfiguration {\n"); for (const auto &it : this->active_wake_words) { out.append(" active_wake_words: "); - if (this->active_wake_words_ptr_ != nullptr) { - out.append("'").append(this->active_wake_words_ptr_).append("'"); + if (!this->active_wake_words_ref_.empty()) { + out.append("'").append(this->active_wake_words_ref_.c_str()).append("'"); } else { out.append("'").append(this->active_wake_words).append("'"); } @@ -4003,8 +4003,8 @@ void ListEntitiesAlarmControlPanelResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesAlarmControlPanelResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4016,8 +4016,8 @@ void ListEntitiesAlarmControlPanelResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4025,8 +4025,8 @@ void ListEntitiesAlarmControlPanelResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4115,8 +4115,8 @@ void ListEntitiesTextResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesTextResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4128,8 +4128,8 @@ void ListEntitiesTextResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4137,8 +4137,8 @@ void ListEntitiesTextResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4164,8 +4164,8 @@ void ListEntitiesTextResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" pattern: "); - if (this->pattern_ptr_ != nullptr) { - out.append("'").append(this->pattern_ptr_).append("'"); + if (!this->pattern_ref_.empty()) { + out.append("'").append(this->pattern_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4193,8 +4193,8 @@ void TextStateResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" state: "); - if (this->state_ptr_ != nullptr) { - out.append("'").append(this->state_ptr_).append("'"); + if (!this->state_ref_.empty()) { + out.append("'").append(this->state_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4240,8 +4240,8 @@ void ListEntitiesDateResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesDateResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4253,8 +4253,8 @@ void ListEntitiesDateResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4262,8 +4262,8 @@ void ListEntitiesDateResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4361,8 +4361,8 @@ void ListEntitiesTimeResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesTimeResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4374,8 +4374,8 @@ void ListEntitiesTimeResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4383,8 +4383,8 @@ void ListEntitiesTimeResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4482,8 +4482,8 @@ void ListEntitiesEventResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesEventResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4495,8 +4495,8 @@ void ListEntitiesEventResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4504,8 +4504,8 @@ void ListEntitiesEventResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4521,8 +4521,8 @@ void ListEntitiesEventResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" device_class: "); - if (this->device_class_ptr_ != nullptr) { - out.append("'").append(this->device_class_ptr_).append("'"); + if (!this->device_class_ref_.empty()) { + out.append("'").append(this->device_class_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4530,8 +4530,8 @@ void ListEntitiesEventResponse::dump_to(std::string &out) const { for (const auto &it : this->event_types) { out.append(" event_types: "); - if (this->event_types_ptr_ != nullptr) { - out.append("'").append(this->event_types_ptr_).append("'"); + if (!this->event_types_ref_.empty()) { + out.append("'").append(this->event_types_ref_.c_str()).append("'"); } else { out.append("'").append(this->event_types).append("'"); } @@ -4556,8 +4556,8 @@ void EventResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" event_type: "); - if (this->event_type_ptr_ != nullptr) { - out.append("'").append(this->event_type_ptr_).append("'"); + if (!this->event_type_ref_.empty()) { + out.append("'").append(this->event_type_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4578,8 +4578,8 @@ void ListEntitiesValveResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesValveResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4591,8 +4591,8 @@ void ListEntitiesValveResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4600,8 +4600,8 @@ void ListEntitiesValveResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4617,8 +4617,8 @@ void ListEntitiesValveResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" device_class: "); - if (this->device_class_ptr_ != nullptr) { - out.append("'").append(this->device_class_ptr_).append("'"); + if (!this->device_class_ref_.empty()) { + out.append("'").append(this->device_class_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4707,8 +4707,8 @@ void ListEntitiesDateTimeResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesDateTimeResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4720,8 +4720,8 @@ void ListEntitiesDateTimeResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4729,8 +4729,8 @@ void ListEntitiesDateTimeResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4808,8 +4808,8 @@ void ListEntitiesUpdateResponse::dump_to(std::string &out) const { __attribute__((unused)) char buffer[64]; out.append("ListEntitiesUpdateResponse {\n"); out.append(" object_id: "); - if (this->object_id_ptr_ != nullptr) { - out.append("'").append(this->object_id_ptr_).append("'"); + if (!this->object_id_ref_.empty()) { + out.append("'").append(this->object_id_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4821,8 +4821,8 @@ void ListEntitiesUpdateResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" name: "); - if (this->name_ptr_ != nullptr) { - out.append("'").append(this->name_ptr_).append("'"); + if (!this->name_ref_.empty()) { + out.append("'").append(this->name_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4830,8 +4830,8 @@ void ListEntitiesUpdateResponse::dump_to(std::string &out) const { #ifdef USE_ENTITY_ICON out.append(" icon: "); - if (this->icon_ptr_ != nullptr) { - out.append("'").append(this->icon_ptr_).append("'"); + if (!this->icon_ref_.empty()) { + out.append("'").append(this->icon_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4847,8 +4847,8 @@ void ListEntitiesUpdateResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" device_class: "); - if (this->device_class_ptr_ != nullptr) { - out.append("'").append(this->device_class_ptr_).append("'"); + if (!this->device_class_ref_.empty()) { + out.append("'").append(this->device_class_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } @@ -4889,40 +4889,40 @@ void UpdateStateResponse::dump_to(std::string &out) const { out.append("\n"); out.append(" current_version: "); - if (this->current_version_ptr_ != nullptr) { - out.append("'").append(this->current_version_ptr_).append("'"); + if (!this->current_version_ref_.empty()) { + out.append("'").append(this->current_version_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } out.append("\n"); out.append(" latest_version: "); - if (this->latest_version_ptr_ != nullptr) { - out.append("'").append(this->latest_version_ptr_).append("'"); + if (!this->latest_version_ref_.empty()) { + out.append("'").append(this->latest_version_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } out.append("\n"); out.append(" title: "); - if (this->title_ptr_ != nullptr) { - out.append("'").append(this->title_ptr_).append("'"); + if (!this->title_ref_.empty()) { + out.append("'").append(this->title_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } out.append("\n"); out.append(" release_summary: "); - if (this->release_summary_ptr_ != nullptr) { - out.append("'").append(this->release_summary_ptr_).append("'"); + if (!this->release_summary_ref_.empty()) { + out.append("'").append(this->release_summary_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } out.append("\n"); out.append(" release_url: "); - if (this->release_url_ptr_ != nullptr) { - out.append("'").append(this->release_url_ptr_).append("'"); + if (!this->release_url_ref_.empty()) { + out.append("'").append(this->release_url_ref_.c_str()).append("'"); } else { out.append("'").append("").append("'"); } diff --git a/esphome/components/api/custom_api_device.h b/esphome/components/api/custom_api_device.h index 18f830551b..6375dbfb9f 100644 --- a/esphome/components/api/custom_api_device.h +++ b/esphome/components/api/custom_api_device.h @@ -148,7 +148,7 @@ class CustomAPIDevice { */ void call_homeassistant_service(const std::string &service_name) { HomeassistantServiceResponse resp; - resp.set_service(service_name.c_str(), service_name.length()); + resp.set_service(StringRef(service_name)); global_api_server->send_homeassistant_service_call(resp); } @@ -168,12 +168,12 @@ class CustomAPIDevice { */ void call_homeassistant_service(const std::string &service_name, const std::map &data) { HomeassistantServiceResponse resp; - resp.set_service(service_name.c_str(), service_name.length()); + resp.set_service(StringRef(service_name)); for (auto &it : data) { resp.data.emplace_back(); auto &kv = resp.data.back(); - kv.set_key(it.first.c_str(), it.first.length()); - kv.set_value(it.second.c_str(), it.second.length()); + kv.set_key(StringRef(it.first)); + kv.set_value(StringRef(it.second)); } global_api_server->send_homeassistant_service_call(resp); } @@ -190,7 +190,7 @@ class CustomAPIDevice { */ void fire_homeassistant_event(const std::string &event_name) { HomeassistantServiceResponse resp; - resp.set_service(event_name.c_str(), event_name.length()); + resp.set_service(StringRef(event_name)); resp.is_event = true; global_api_server->send_homeassistant_service_call(resp); } @@ -210,13 +210,13 @@ class CustomAPIDevice { */ void fire_homeassistant_event(const std::string &service_name, const std::map &data) { HomeassistantServiceResponse resp; - resp.set_service(service_name.c_str(), service_name.length()); + resp.set_service(StringRef(service_name)); resp.is_event = true; for (auto &it : data) { resp.data.emplace_back(); auto &kv = resp.data.back(); - kv.set_key(it.first.c_str(), it.first.length()); - kv.set_value(it.second.c_str(), it.second.length()); + kv.set_key(StringRef(it.first)); + kv.set_value(StringRef(it.second)); } global_api_server->send_homeassistant_service_call(resp); } diff --git a/esphome/components/api/homeassistant_service.h b/esphome/components/api/homeassistant_service.h index ab6f5249b8..4980c0224c 100644 --- a/esphome/components/api/homeassistant_service.h +++ b/esphome/components/api/homeassistant_service.h @@ -60,28 +60,28 @@ template class HomeAssistantServiceCallAction : public Actionservice_.value(x...); - resp.set_service(service_value.c_str(), service_value.length()); + resp.set_service(StringRef(service_value)); resp.is_event = this->is_event_; for (auto &it : this->data_) { resp.data.emplace_back(); auto &kv = resp.data.back(); - kv.set_key(it.key.c_str(), it.key.length()); + kv.set_key(StringRef(it.key)); std::string value = it.value.value(x...); - kv.set_value(value.c_str(), value.length()); + kv.set_value(StringRef(value)); } for (auto &it : this->data_template_) { resp.data_template.emplace_back(); auto &kv = resp.data_template.back(); - kv.set_key(it.key.c_str(), it.key.length()); + kv.set_key(StringRef(it.key)); std::string value = it.value.value(x...); - kv.set_value(value.c_str(), value.length()); + kv.set_value(StringRef(value)); } for (auto &it : this->variables_) { resp.variables.emplace_back(); auto &kv = resp.variables.back(); - kv.set_key(it.key.c_str(), it.key.length()); + kv.set_key(StringRef(it.key)); std::string value = it.value.value(x...); - kv.set_value(value.c_str(), value.length()); + kv.set_value(StringRef(value)); } this->parent_->send_homeassistant_service_call(resp); } diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index ac42a514b9..9b95454328 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -3,6 +3,7 @@ #include "esphome/core/component.h" #include "esphome/core/helpers.h" #include "esphome/core/log.h" +#include "esphome/core/string_ref.h" #include #include @@ -218,6 +219,9 @@ class ProtoWriteBuffer { void encode_string(uint32_t field_id, const std::string &value, bool force = false) { this->encode_string(field_id, value.data(), value.size(), force); } + void encode_string(uint32_t field_id, const StringRef &ref, bool force = false) { + this->encode_string(field_id, ref.c_str(), ref.size(), force); + } void encode_bytes(uint32_t field_id, const uint8_t *data, size_t len, bool force = false) { this->encode_string(field_id, reinterpret_cast(data), len, force); } diff --git a/esphome/components/api/user_services.h b/esphome/components/api/user_services.h index 0ea13aa5e3..deec636cae 100644 --- a/esphome/components/api/user_services.h +++ b/esphome/components/api/user_services.h @@ -33,14 +33,14 @@ template class UserServiceBase : public UserServiceDescriptor { ListEntitiesServicesResponse encode_list_service_response() override { ListEntitiesServicesResponse msg; - msg.set_name(this->name_.c_str(), this->name_.length()); + msg.set_name(StringRef(this->name_)); msg.key = this->key_; std::array arg_types = {to_service_arg_type()...}; for (int i = 0; i < sizeof...(Ts); i++) { msg.args.emplace_back(); auto &arg = msg.args.back(); arg.type = arg_types[i]; - arg.set_name(this->arg_names_[i].c_str(), this->arg_names_[i].length()); + arg.set_name(StringRef(this->arg_names_[i])); } return msg; } diff --git a/esphome/components/homeassistant/number/homeassistant_number.cpp b/esphome/components/homeassistant/number/homeassistant_number.cpp index b78cc6bcbf..9ee7ceb020 100644 --- a/esphome/components/homeassistant/number/homeassistant_number.cpp +++ b/esphome/components/homeassistant/number/homeassistant_number.cpp @@ -89,13 +89,13 @@ void HomeassistantNumber::control(float value) { resp.data.emplace_back(); auto &entity_id = resp.data.back(); entity_id.set_key("entity_id", 9); - entity_id.set_value(this->entity_id_.c_str(), this->entity_id_.length()); + entity_id.set_value(StringRef(this->entity_id_)); resp.data.emplace_back(); auto &entity_value = resp.data.back(); entity_value.set_key("value", 5); std::string value_str = to_string(value); - entity_value.set_value(value_str.c_str(), value_str.length()); + entity_value.set_value(StringRef(value_str)); api::global_api_server->send_homeassistant_service_call(resp); } diff --git a/esphome/components/homeassistant/switch/homeassistant_switch.cpp b/esphome/components/homeassistant/switch/homeassistant_switch.cpp index f8ce102990..5a42ef8f16 100644 --- a/esphome/components/homeassistant/switch/homeassistant_switch.cpp +++ b/esphome/components/homeassistant/switch/homeassistant_switch.cpp @@ -50,7 +50,7 @@ void HomeassistantSwitch::write_state(bool state) { resp.data.emplace_back(); auto &entity_id_kv = resp.data.back(); entity_id_kv.set_key("entity_id", 9); - entity_id_kv.set_value(this->entity_id_.c_str(), this->entity_id_.length()); + entity_id_kv.set_value(StringRef(this->entity_id_)); api::global_api_server->send_homeassistant_service_call(resp); } diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index beb283b470..b8e3f7a590 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -554,13 +554,11 @@ class StringType(TypeInfo): if self._needs_encode: content.extend( [ - # Add pointer/length fields if message needs encoding - f"const char* {self.field_name}_ptr_{{nullptr}};", - f"size_t {self.field_name}_len_{{0}};", + # Add StringRef field if message needs encoding + f"StringRef {self.field_name}_ref_{{}};", # Add setter method if message needs encoding - f"void set_{self.field_name}(const char* data, size_t len) {{", - f" this->{self.field_name}_ptr_ = data;", - f" this->{self.field_name}_len_ = len;", + f"void set_{self.field_name}(const StringRef &ref) {{", + f" this->{self.field_name}_ref_ = ref;", "}", ] ) @@ -568,27 +566,27 @@ class StringType(TypeInfo): @property def encode_content(self) -> str: - return f"buffer.encode_string({self.number}, this->{self.field_name}_ptr_, this->{self.field_name}_len_);" + return f"buffer.encode_string({self.number}, this->{self.field_name}_ref_);" def dump(self, name): # For SOURCE_CLIENT only, always use std::string if not self._needs_encode: return f'out.append("\'").append(this->{self.field_name}).append("\'");' - # For SOURCE_SERVER, always use pointer/length + # For SOURCE_SERVER, always use StringRef if not self._needs_decode: return ( - f"if (this->{self.field_name}_ptr_ != nullptr) {{" - f' out.append("\'").append(this->{self.field_name}_ptr_).append("\'");' + f"if (!this->{self.field_name}_ref_.empty()) {{" + f' out.append("\'").append(this->{self.field_name}_ref_.c_str()).append("\'");' f"}} else {{" f' out.append("\'").append("").append("\'");' f"}}" ) - # For SOURCE_BOTH, check if pointer is set (sending) or use string (received) + # For SOURCE_BOTH, check if StringRef is set (sending) or use string (received) return ( - f"if (this->{self.field_name}_ptr_ != nullptr) {{" - f' out.append("\'").append(this->{self.field_name}_ptr_).append("\'");' + f"if (!this->{self.field_name}_ref_.empty()) {{" + f' out.append("\'").append(this->{self.field_name}_ref_.c_str()).append("\'");' f"}} else {{" f' out.append("\'").append(this->{self.field_name}).append("\'");' f"}}" @@ -605,9 +603,9 @@ class StringType(TypeInfo): field_id_size = self.calculate_field_id_size() return f"ProtoSize::add_string_field(total_size, {field_id_size}, it.length());" - # For messages that need encoding, use the length only + # For messages that need encoding, use the StringRef size field_id_size = self.calculate_field_id_size() - return f"ProtoSize::add_string_field(total_size, {field_id_size}, this->{self.field_name}_len_);" + return f"ProtoSize::add_string_field(total_size, {field_id_size}, this->{self.field_name}_ref_.size());" def get_estimated_size(self) -> int: return self.calculate_field_id_size() + 8 # field ID + 8 bytes typical string @@ -1835,6 +1833,7 @@ def main() -> None: #pragma once #include "esphome/core/defines.h" +#include "esphome/core/string_ref.h" #include "proto.h"