This commit is contained in:
J. Nick Koston 2025-07-21 17:21:59 -10:00
parent c4ac22286f
commit b0aafb1226
No known key found for this signature in database
12 changed files with 718 additions and 968 deletions

View File

@ -248,8 +248,8 @@ void APIConnection::loop() {
if (state_subs_at_ < static_cast<int>(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<binary_sensor::BinarySensor *>(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<enums::FanDirection>(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<sensor::Sensor *>(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<enums::SensorStateClass>(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<switch_::Switch *>(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<text_sensor::TextSensor *>(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<text_sensor::TextSensor *>(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<enums::ClimateFanMode>(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<enums::ClimatePreset>(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<enums::ClimateSwingMode>(climate->swing_mode);
@ -741,11 +732,9 @@ uint16_t APIConnection::try_send_number_info(EntityBase *entity, APIConnection *
bool is_single) {
auto *number = static_cast<number::Number *>(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<enums::NumberMode>(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<text::Text *>(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<enums::TextMode>(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<select::Select *>(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<button::Button *>(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<valve::Valve *>(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<event::Event *>(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<update::UpdateEntity *>(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;

View File

@ -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<enums::EntityCategory>(entity->get_entity_category());

File diff suppressed because it is too large Load Diff

View File

@ -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<HomeassistantServiceMap> data{};
std::vector<HomeassistantServiceMap> data_template{};
std::vector<HomeassistantServiceMap> 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<ListEntitiesServicesArgument> 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<std::string> 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<std::string> 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

File diff suppressed because it is too large Load Diff

View File

@ -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<std::string, std::string> &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<std::string, std::string> &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);
}

View File

@ -60,28 +60,28 @@ template<typename... Ts> class HomeAssistantServiceCallAction : public Action<Ts
void play(Ts... x) override {
HomeassistantServiceResponse resp;
std::string service_value = this->service_.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);
}

View File

@ -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 <cassert>
#include <cstring>
@ -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<const char *>(data), len, force);
}

View File

@ -33,14 +33,14 @@ template<typename... Ts> 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<enums::ServiceArgType, sizeof...(Ts)> arg_types = {to_service_arg_type<Ts>()...};
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;
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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"