mirror of
https://github.com/esphome/esphome.git
synced 2025-07-30 07:06:38 +00:00
zero_copy_str
This commit is contained in:
parent
b17e2019c7
commit
c4ac22286f
@ -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.entity_id = it.entity_id;
|
||||
resp.attribute = it.attribute.value();
|
||||
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.once = it.once;
|
||||
if (this->send_message(resp, SubscribeHomeAssistantStateResponse::MESSAGE_TYPE)) {
|
||||
state_subs_at_++;
|
||||
@ -344,7 +344,8 @@ 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;
|
||||
msg.device_class = binary_sensor->get_device_class();
|
||||
const std::string &device_class = binary_sensor->get_device_class();
|
||||
msg.set_device_class(device_class.c_str(), device_class.length());
|
||||
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);
|
||||
@ -376,7 +377,8 @@ 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();
|
||||
msg.device_class = cover->get_device_class();
|
||||
const std::string &device_class = cover->get_device_class();
|
||||
msg.set_device_class(device_class.c_str(), device_class.length());
|
||||
return fill_and_encode_entity_info(cover, msg, ListEntitiesCoverResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
@ -411,7 +413,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.preset_mode = fan->preset_mode;
|
||||
msg.set_preset_mode(fan->preset_mode.c_str(), fan->preset_mode.length());
|
||||
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,
|
||||
@ -468,8 +470,10 @@ uint16_t APIConnection::try_send_light_state(EntityBase *entity, APIConnection *
|
||||
resp.color_temperature = values.get_color_temperature();
|
||||
resp.cold_white = values.get_cold_white();
|
||||
resp.warm_white = values.get_warm_white();
|
||||
if (light->supports_effects())
|
||||
resp.effect = light->get_effect_name();
|
||||
if (light->supports_effects()) {
|
||||
const std::string &effect_name = light->get_effect_name();
|
||||
resp.set_effect(effect_name.c_str(), effect_name.length());
|
||||
}
|
||||
return fill_and_encode_entity_state(light, resp, LightStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
}
|
||||
uint16_t APIConnection::try_send_light_info(EntityBase *entity, APIConnection *conn, uint32_t remaining_size,
|
||||
@ -545,10 +549,12 @@ uint16_t APIConnection::try_send_sensor_info(EntityBase *entity, APIConnection *
|
||||
bool is_single) {
|
||||
auto *sensor = static_cast<sensor::Sensor *>(entity);
|
||||
ListEntitiesSensorResponse msg;
|
||||
msg.unit_of_measurement = sensor->get_unit_of_measurement();
|
||||
const std::string &unit = sensor->get_unit_of_measurement();
|
||||
msg.set_unit_of_measurement(unit.c_str(), unit.length());
|
||||
msg.accuracy_decimals = sensor->get_accuracy_decimals();
|
||||
msg.force_update = sensor->get_force_update();
|
||||
msg.device_class = sensor->get_device_class();
|
||||
const std::string &device_class = sensor->get_device_class();
|
||||
msg.set_device_class(device_class.c_str(), device_class.length());
|
||||
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);
|
||||
@ -575,7 +581,8 @@ 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();
|
||||
msg.device_class = a_switch->get_device_class();
|
||||
const std::string &device_class = a_switch->get_device_class();
|
||||
msg.set_device_class(device_class.c_str(), device_class.length());
|
||||
return fill_and_encode_entity_info(a_switch, msg, ListEntitiesSwitchResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
@ -600,7 +607,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.state = text_sensor->state;
|
||||
resp.set_state(text_sensor->state.c_str(), text_sensor->state.length());
|
||||
resp.missing_state = !text_sensor->has_state();
|
||||
return fill_and_encode_entity_state(text_sensor, resp, TextSensorStateResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
@ -609,7 +616,8 @@ 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;
|
||||
msg.device_class = text_sensor->get_device_class();
|
||||
const std::string &device_class = text_sensor->get_device_class();
|
||||
msg.set_device_class(device_class.c_str(), device_class.length());
|
||||
return fill_and_encode_entity_info(text_sensor, msg, ListEntitiesTextSensorResponse::MESSAGE_TYPE, conn,
|
||||
remaining_size, is_single);
|
||||
}
|
||||
@ -637,13 +645,17 @@ 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())
|
||||
resp.custom_fan_mode = climate->custom_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());
|
||||
}
|
||||
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())
|
||||
resp.custom_preset = climate->custom_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());
|
||||
}
|
||||
if (traits.get_supports_swing_modes())
|
||||
resp.swing_mode = static_cast<enums::ClimateSwingMode>(climate->swing_mode);
|
||||
if (traits.get_supports_current_humidity())
|
||||
@ -729,9 +741,11 @@ uint16_t APIConnection::try_send_number_info(EntityBase *entity, APIConnection *
|
||||
bool is_single) {
|
||||
auto *number = static_cast<number::Number *>(entity);
|
||||
ListEntitiesNumberResponse msg;
|
||||
msg.unit_of_measurement = number->traits.get_unit_of_measurement();
|
||||
const std::string &unit = number->traits.get_unit_of_measurement();
|
||||
msg.set_unit_of_measurement(unit.c_str(), unit.length());
|
||||
msg.mode = static_cast<enums::NumberMode>(number->traits.get_mode());
|
||||
msg.device_class = number->traits.get_device_class();
|
||||
const std::string &device_class = number->traits.get_device_class();
|
||||
msg.set_device_class(device_class.c_str(), device_class.length());
|
||||
msg.min_value = number->traits.get_min_value();
|
||||
msg.max_value = number->traits.get_max_value();
|
||||
msg.step = number->traits.get_step();
|
||||
@ -844,7 +858,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.state = text->state;
|
||||
resp.set_state(text->state.c_str(), text->state.length());
|
||||
resp.missing_state = !text->has_state();
|
||||
return fill_and_encode_entity_state(text, resp, TextStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
}
|
||||
@ -856,7 +870,8 @@ 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();
|
||||
msg.pattern = text->traits.get_pattern();
|
||||
const std::string &pattern = text->traits.get_pattern();
|
||||
msg.set_pattern(pattern.c_str(), pattern.length());
|
||||
return fill_and_encode_entity_info(text, msg, ListEntitiesTextResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
@ -877,7 +892,7 @@ uint16_t APIConnection::try_send_select_state(EntityBase *entity, APIConnection
|
||||
bool is_single) {
|
||||
auto *select = static_cast<select::Select *>(entity);
|
||||
SelectStateResponse resp;
|
||||
resp.state = select->state;
|
||||
resp.set_state(select->state.c_str(), select->state.length());
|
||||
resp.missing_state = !select->has_state();
|
||||
return fill_and_encode_entity_state(select, resp, SelectStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
}
|
||||
@ -903,7 +918,8 @@ uint16_t APIConnection::try_send_button_info(EntityBase *entity, APIConnection *
|
||||
bool is_single) {
|
||||
auto *button = static_cast<button::Button *>(entity);
|
||||
ListEntitiesButtonResponse msg;
|
||||
msg.device_class = button->get_device_class();
|
||||
const std::string &device_class = button->get_device_class();
|
||||
msg.set_device_class(device_class.c_str(), device_class.length());
|
||||
return fill_and_encode_entity_info(button, msg, ListEntitiesButtonResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
@ -972,7 +988,8 @@ 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();
|
||||
msg.device_class = valve->get_device_class();
|
||||
const std::string &device_class = valve->get_device_class();
|
||||
msg.set_device_class(device_class.c_str(), device_class.length());
|
||||
msg.assumed_state = traits.get_is_assumed_state();
|
||||
msg.supports_position = traits.get_supports_position();
|
||||
msg.supports_stop = traits.get_supports_stop();
|
||||
@ -1273,7 +1290,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.event_type = event_type;
|
||||
resp.set_event_type(event_type.c_str(), event_type.length());
|
||||
return fill_and_encode_entity_state(event, resp, EventResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
}
|
||||
|
||||
@ -1281,7 +1298,8 @@ uint16_t APIConnection::try_send_event_info(EntityBase *entity, APIConnection *c
|
||||
bool is_single) {
|
||||
auto *event = static_cast<event::Event *>(entity);
|
||||
ListEntitiesEventResponse msg;
|
||||
msg.device_class = event->get_device_class();
|
||||
const std::string &device_class = event->get_device_class();
|
||||
msg.set_device_class(device_class.c_str(), device_class.length());
|
||||
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,
|
||||
@ -1305,11 +1323,11 @@ uint16_t APIConnection::try_send_update_state(EntityBase *entity, APIConnection
|
||||
resp.has_progress = true;
|
||||
resp.progress = update->update_info.progress;
|
||||
}
|
||||
resp.current_version = update->update_info.current_version;
|
||||
resp.latest_version = update->update_info.latest_version;
|
||||
resp.title = update->update_info.title;
|
||||
resp.release_summary = update->update_info.summary;
|
||||
resp.release_url = update->update_info.release_url;
|
||||
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());
|
||||
}
|
||||
return fill_and_encode_entity_state(update, resp, UpdateStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
|
||||
}
|
||||
@ -1317,7 +1335,8 @@ uint16_t APIConnection::try_send_update_info(EntityBase *entity, APIConnection *
|
||||
bool is_single) {
|
||||
auto *update = static_cast<update::UpdateEntity *>(entity);
|
||||
ListEntitiesUpdateResponse msg;
|
||||
msg.device_class = update->get_device_class();
|
||||
const std::string &device_class = update->get_device_class();
|
||||
msg.set_device_class(device_class.c_str(), device_class.length());
|
||||
return fill_and_encode_entity_info(update, msg, ListEntitiesUpdateResponse::MESSAGE_TYPE, conn, remaining_size,
|
||||
is_single);
|
||||
}
|
||||
@ -1377,8 +1396,10 @@ HelloResponse APIConnection::hello(const HelloRequest &msg) {
|
||||
HelloResponse resp;
|
||||
resp.api_version_major = 1;
|
||||
resp.api_version_minor = 10;
|
||||
resp.server_info = App.get_name() + " (esphome v" ESPHOME_VERSION ")";
|
||||
resp.name = App.get_name();
|
||||
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());
|
||||
|
||||
#ifdef USE_API_PASSWORD
|
||||
// Password required - wait for authentication
|
||||
@ -1409,41 +1430,47 @@ DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) {
|
||||
#ifdef USE_API_PASSWORD
|
||||
resp.uses_password = true;
|
||||
#endif
|
||||
resp.name = App.get_name();
|
||||
resp.friendly_name = App.get_friendly_name();
|
||||
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());
|
||||
#ifdef USE_AREAS
|
||||
resp.suggested_area = App.get_area();
|
||||
const std::string &area = App.get_area();
|
||||
resp.set_suggested_area(area.c_str(), area.length());
|
||||
#endif
|
||||
resp.mac_address = get_mac_address_pretty();
|
||||
resp.esphome_version = ESPHOME_VERSION;
|
||||
resp.compilation_time = App.get_compilation_time();
|
||||
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());
|
||||
#if defined(USE_ESP8266) || defined(USE_ESP32)
|
||||
resp.manufacturer = "Espressif";
|
||||
resp.set_manufacturer("Espressif", 9);
|
||||
#elif defined(USE_RP2040)
|
||||
resp.manufacturer = "Raspberry Pi";
|
||||
resp.set_manufacturer("Raspberry Pi", 12);
|
||||
#elif defined(USE_BK72XX)
|
||||
resp.manufacturer = "Beken";
|
||||
resp.set_manufacturer("Beken", 5);
|
||||
#elif defined(USE_LN882X)
|
||||
resp.manufacturer = "Lightning";
|
||||
resp.set_manufacturer("Lightning", 9);
|
||||
#elif defined(USE_RTL87XX)
|
||||
resp.manufacturer = "Realtek";
|
||||
resp.set_manufacturer("Realtek", 7);
|
||||
#elif defined(USE_HOST)
|
||||
resp.manufacturer = "Host";
|
||||
resp.set_manufacturer("Host", 4);
|
||||
#endif
|
||||
resp.model = ESPHOME_BOARD;
|
||||
resp.set_model(ESPHOME_BOARD, strlen(ESPHOME_BOARD));
|
||||
#ifdef USE_DEEP_SLEEP
|
||||
resp.has_deep_sleep = deep_sleep::global_has_deep_sleep;
|
||||
#endif
|
||||
#ifdef ESPHOME_PROJECT_NAME
|
||||
resp.project_name = ESPHOME_PROJECT_NAME;
|
||||
resp.project_version = ESPHOME_PROJECT_VERSION;
|
||||
resp.set_project_name(ESPHOME_PROJECT_NAME, strlen(ESPHOME_PROJECT_NAME));
|
||||
resp.set_project_version(ESPHOME_PROJECT_VERSION, strlen(ESPHOME_PROJECT_VERSION));
|
||||
#endif
|
||||
#ifdef USE_WEBSERVER
|
||||
resp.webserver_port = USE_WEBSERVER_PORT;
|
||||
#endif
|
||||
#ifdef USE_BLUETOOTH_PROXY
|
||||
resp.bluetooth_proxy_feature_flags = bluetooth_proxy::global_bluetooth_proxy->get_feature_flags();
|
||||
resp.bluetooth_mac_address = bluetooth_proxy::global_bluetooth_proxy->get_bluetooth_mac_address_pretty();
|
||||
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());
|
||||
#endif
|
||||
#ifdef USE_VOICE_ASSISTANT
|
||||
resp.voice_assistant_feature_flags = voice_assistant::global_voice_assistant->get_feature_flags();
|
||||
@ -1453,19 +1480,21 @@ DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) {
|
||||
#endif
|
||||
#ifdef USE_DEVICES
|
||||
for (auto const &device : App.get_devices()) {
|
||||
DeviceInfo device_info;
|
||||
resp.devices.emplace_back();
|
||||
auto &device_info = resp.devices.back();
|
||||
device_info.device_id = device->get_device_id();
|
||||
device_info.name = device->get_name();
|
||||
const std::string &device_name = device->get_name();
|
||||
device_info.set_name(device_name.c_str(), device_name.length());
|
||||
device_info.area_id = device->get_area_id();
|
||||
resp.devices.push_back(device_info);
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_AREAS
|
||||
for (auto const &area : App.get_areas()) {
|
||||
AreaInfo area_info;
|
||||
resp.areas.emplace_back();
|
||||
auto &area_info = resp.areas.back();
|
||||
area_info.area_id = area->get_area_id();
|
||||
area_info.name = area->get_name();
|
||||
resp.areas.push_back(area_info);
|
||||
const std::string &area_name = area->get_name();
|
||||
area_info.set_name(area_name.c_str(), area_name.length());
|
||||
}
|
||||
#endif
|
||||
return resp;
|
||||
|
@ -313,14 +313,18 @@ 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();
|
||||
msg.object_id = entity->get_object_id();
|
||||
const std::string &object_id = entity->get_object_id();
|
||||
msg.set_object_id(object_id.c_str(), object_id.length());
|
||||
|
||||
if (entity->has_own_name())
|
||||
msg.name = entity->get_name();
|
||||
if (entity->has_own_name()) {
|
||||
const std::string &name = entity->get_name();
|
||||
msg.set_name(name.c_str(), name.length());
|
||||
}
|
||||
|
||||
// Set common EntityBase properties
|
||||
// Set common EntityBase properties
|
||||
#ifdef USE_ENTITY_ICON
|
||||
msg.icon = entity->get_icon();
|
||||
const std::string &icon = entity->get_icon();
|
||||
msg.set_icon(icon.c_str(), icon.length());
|
||||
#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
@ -269,12 +269,27 @@ enum UpdateCommand : uint32_t {
|
||||
class InfoResponseProtoMessage : public ProtoMessage {
|
||||
public:
|
||||
~InfoResponseProtoMessage() override = default;
|
||||
std::string object_id{};
|
||||
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;
|
||||
}
|
||||
uint32_t key{0};
|
||||
std::string name{};
|
||||
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;
|
||||
}
|
||||
bool disabled_by_default{false};
|
||||
#ifdef USE_ENTITY_ICON
|
||||
std::string 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;
|
||||
}
|
||||
#endif
|
||||
enums::EntityCategory entity_category{};
|
||||
#ifdef USE_DEVICES
|
||||
@ -332,8 +347,18 @@ class HelloResponse : public ProtoMessage {
|
||||
#endif
|
||||
uint32_t api_version_major{0};
|
||||
uint32_t api_version_minor{0};
|
||||
std::string server_info{};
|
||||
std::string name{};
|
||||
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;
|
||||
}
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
@ -442,7 +467,12 @@ class DeviceInfoRequest : public ProtoDecodableMessage {
|
||||
class AreaInfo : public ProtoMessage {
|
||||
public:
|
||||
uint32_t area_id{0};
|
||||
std::string name{};
|
||||
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;
|
||||
}
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
@ -456,7 +486,12 @@ class AreaInfo : public ProtoMessage {
|
||||
class DeviceInfo : public ProtoMessage {
|
||||
public:
|
||||
uint32_t device_id{0};
|
||||
std::string name{};
|
||||
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;
|
||||
}
|
||||
uint32_t area_id{0};
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
@ -477,19 +512,54 @@ class DeviceInfoResponse : public ProtoMessage {
|
||||
#ifdef USE_API_PASSWORD
|
||||
bool uses_password{false};
|
||||
#endif
|
||||
std::string name{};
|
||||
std::string mac_address{};
|
||||
std::string esphome_version{};
|
||||
std::string compilation_time{};
|
||||
std::string model{};
|
||||
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;
|
||||
}
|
||||
#ifdef USE_DEEP_SLEEP
|
||||
bool has_deep_sleep{false};
|
||||
#endif
|
||||
#ifdef ESPHOME_PROJECT_NAME
|
||||
std::string 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;
|
||||
}
|
||||
#endif
|
||||
#ifdef ESPHOME_PROJECT_NAME
|
||||
std::string project_version{};
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_WEBSERVER
|
||||
uint32_t webserver_port{0};
|
||||
@ -497,16 +567,36 @@ class DeviceInfoResponse : public ProtoMessage {
|
||||
#ifdef USE_BLUETOOTH_PROXY
|
||||
uint32_t bluetooth_proxy_feature_flags{0};
|
||||
#endif
|
||||
std::string manufacturer{};
|
||||
std::string friendly_name{};
|
||||
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;
|
||||
}
|
||||
#ifdef USE_VOICE_ASSISTANT
|
||||
uint32_t voice_assistant_feature_flags{0};
|
||||
#endif
|
||||
#ifdef USE_AREAS
|
||||
std::string suggested_area{};
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_BLUETOOTH_PROXY
|
||||
std::string bluetooth_mac_address{};
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_API_NOISE
|
||||
bool api_encryption_supported{false};
|
||||
@ -575,7 +665,12 @@ class ListEntitiesBinarySensorResponse : public InfoResponseProtoMessage {
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_binary_sensor_response"; }
|
||||
#endif
|
||||
std::string device_class{};
|
||||
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;
|
||||
}
|
||||
bool is_status_binary_sensor{false};
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
@ -614,7 +709,12 @@ class ListEntitiesCoverResponse : public InfoResponseProtoMessage {
|
||||
bool assumed_state{false};
|
||||
bool supports_position{false};
|
||||
bool supports_tilt{false};
|
||||
std::string device_class{};
|
||||
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;
|
||||
}
|
||||
bool supports_stop{false};
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
@ -695,7 +795,12 @@ class FanStateResponse : public StateResponseProtoMessage {
|
||||
bool oscillating{false};
|
||||
enums::FanDirection direction{};
|
||||
int32_t speed_level{0};
|
||||
std::string preset_mode{};
|
||||
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;
|
||||
}
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
@ -769,7 +874,12 @@ class LightStateResponse : public StateResponseProtoMessage {
|
||||
float color_temperature{0.0f};
|
||||
float cold_white{0.0f};
|
||||
float warm_white{0.0f};
|
||||
std::string effect{};
|
||||
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;
|
||||
}
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
@ -829,10 +939,20 @@ class ListEntitiesSensorResponse : public InfoResponseProtoMessage {
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_sensor_response"; }
|
||||
#endif
|
||||
std::string unit_of_measurement{};
|
||||
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;
|
||||
}
|
||||
int32_t accuracy_decimals{0};
|
||||
bool force_update{false};
|
||||
std::string device_class{};
|
||||
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;
|
||||
}
|
||||
enums::SensorStateClass state_class{};
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
@ -869,7 +989,12 @@ class ListEntitiesSwitchResponse : public InfoResponseProtoMessage {
|
||||
const char *message_name() const override { return "list_entities_switch_response"; }
|
||||
#endif
|
||||
bool assumed_state{false};
|
||||
std::string device_class{};
|
||||
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;
|
||||
}
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
@ -919,7 +1044,12 @@ class ListEntitiesTextSensorResponse : public InfoResponseProtoMessage {
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_text_sensor_response"; }
|
||||
#endif
|
||||
std::string device_class{};
|
||||
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;
|
||||
}
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
@ -935,7 +1065,12 @@ class TextSensorStateResponse : public StateResponseProtoMessage {
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "text_sensor_state_response"; }
|
||||
#endif
|
||||
std::string state{};
|
||||
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;
|
||||
}
|
||||
bool missing_state{false};
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
@ -1032,8 +1167,18 @@ class SubscribeHomeassistantServicesRequest : public ProtoDecodableMessage {
|
||||
};
|
||||
class HomeassistantServiceMap : public ProtoMessage {
|
||||
public:
|
||||
std::string key{};
|
||||
std::string value{};
|
||||
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;
|
||||
}
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
@ -1049,7 +1194,12 @@ class HomeassistantServiceResponse : public ProtoMessage {
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "homeassistant_service_response"; }
|
||||
#endif
|
||||
std::string service{};
|
||||
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;
|
||||
}
|
||||
std::vector<HomeassistantServiceMap> data{};
|
||||
std::vector<HomeassistantServiceMap> data_template{};
|
||||
std::vector<HomeassistantServiceMap> variables{};
|
||||
@ -1082,8 +1232,18 @@ class SubscribeHomeAssistantStateResponse : public ProtoMessage {
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "subscribe_home_assistant_state_response"; }
|
||||
#endif
|
||||
std::string entity_id{};
|
||||
std::string attribute{};
|
||||
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;
|
||||
}
|
||||
bool once{false};
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
@ -1143,7 +1303,12 @@ class GetTimeResponse : public ProtoDecodableMessage {
|
||||
#ifdef USE_API_SERVICES
|
||||
class ListEntitiesServicesArgument : public ProtoMessage {
|
||||
public:
|
||||
std::string name{};
|
||||
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;
|
||||
}
|
||||
enums::ServiceArgType type{};
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
@ -1160,7 +1325,12 @@ class ListEntitiesServicesResponse : public ProtoMessage {
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_services_response"; }
|
||||
#endif
|
||||
std::string name{};
|
||||
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;
|
||||
}
|
||||
uint32_t key{0};
|
||||
std::vector<ListEntitiesServicesArgument> args{};
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
@ -1312,9 +1482,19 @@ class ClimateStateResponse : public StateResponseProtoMessage {
|
||||
enums::ClimateAction action{};
|
||||
enums::ClimateFanMode fan_mode{};
|
||||
enums::ClimateSwingMode swing_mode{};
|
||||
std::string custom_fan_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;
|
||||
}
|
||||
enums::ClimatePreset preset{};
|
||||
std::string custom_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;
|
||||
}
|
||||
float current_humidity{0.0f};
|
||||
float target_humidity{0.0f};
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
@ -1373,9 +1553,19 @@ class ListEntitiesNumberResponse : public InfoResponseProtoMessage {
|
||||
float min_value{0.0f};
|
||||
float max_value{0.0f};
|
||||
float step{0.0f};
|
||||
std::string unit_of_measurement{};
|
||||
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;
|
||||
}
|
||||
enums::NumberMode mode{};
|
||||
std::string device_class{};
|
||||
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;
|
||||
}
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
@ -1442,7 +1632,12 @@ class SelectStateResponse : public StateResponseProtoMessage {
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "select_state_response"; }
|
||||
#endif
|
||||
std::string state{};
|
||||
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;
|
||||
}
|
||||
bool missing_state{false};
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
@ -1541,7 +1736,12 @@ class ListEntitiesLockResponse : public InfoResponseProtoMessage {
|
||||
bool assumed_state{false};
|
||||
bool supports_open{false};
|
||||
bool requires_code{false};
|
||||
std::string code_format{};
|
||||
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;
|
||||
}
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
@ -1594,7 +1794,12 @@ class ListEntitiesButtonResponse : public InfoResponseProtoMessage {
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_button_response"; }
|
||||
#endif
|
||||
std::string device_class{};
|
||||
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;
|
||||
}
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
@ -1622,7 +1827,12 @@ class ButtonCommandRequest : public CommandProtoMessage {
|
||||
#ifdef USE_MEDIA_PLAYER
|
||||
class MediaPlayerSupportedFormat : public ProtoMessage {
|
||||
public:
|
||||
std::string format{};
|
||||
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;
|
||||
}
|
||||
uint32_t sample_rate{0};
|
||||
uint32_t num_channels{0};
|
||||
enums::MediaPlayerFormatPurpose purpose{};
|
||||
@ -2219,10 +2429,20 @@ class VoiceAssistantRequest : public ProtoMessage {
|
||||
const char *message_name() const override { return "voice_assistant_request"; }
|
||||
#endif
|
||||
bool start{false};
|
||||
std::string conversation_id{};
|
||||
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;
|
||||
}
|
||||
uint32_t flags{0};
|
||||
VoiceAssistantAudioSettings audio_settings{};
|
||||
std::string wake_word_phrase{};
|
||||
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;
|
||||
}
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
@ -2358,8 +2578,18 @@ class VoiceAssistantAnnounceFinished : public ProtoMessage {
|
||||
};
|
||||
class VoiceAssistantWakeWord : public ProtoMessage {
|
||||
public:
|
||||
std::string id{};
|
||||
std::string wake_word{};
|
||||
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;
|
||||
}
|
||||
std::vector<std::string> trained_languages{};
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
@ -2480,7 +2710,12 @@ class ListEntitiesTextResponse : public InfoResponseProtoMessage {
|
||||
#endif
|
||||
uint32_t min_length{0};
|
||||
uint32_t max_length{0};
|
||||
std::string pattern{};
|
||||
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;
|
||||
}
|
||||
enums::TextMode mode{};
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
@ -2497,7 +2732,12 @@ class TextStateResponse : public StateResponseProtoMessage {
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "text_state_response"; }
|
||||
#endif
|
||||
std::string state{};
|
||||
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;
|
||||
}
|
||||
bool missing_state{false};
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
@ -2641,7 +2881,12 @@ class ListEntitiesEventResponse : public InfoResponseProtoMessage {
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_event_response"; }
|
||||
#endif
|
||||
std::string device_class{};
|
||||
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;
|
||||
}
|
||||
std::vector<std::string> event_types{};
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
@ -2658,7 +2903,12 @@ class EventResponse : public StateResponseProtoMessage {
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "event_response"; }
|
||||
#endif
|
||||
std::string event_type{};
|
||||
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;
|
||||
}
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
@ -2676,7 +2926,12 @@ class ListEntitiesValveResponse : public InfoResponseProtoMessage {
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_valve_response"; }
|
||||
#endif
|
||||
std::string device_class{};
|
||||
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;
|
||||
}
|
||||
bool assumed_state{false};
|
||||
bool supports_position{false};
|
||||
bool supports_stop{false};
|
||||
@ -2782,7 +3037,12 @@ class ListEntitiesUpdateResponse : public InfoResponseProtoMessage {
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "list_entities_update_response"; }
|
||||
#endif
|
||||
std::string device_class{};
|
||||
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;
|
||||
}
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(uint32_t &total_size) const override;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
@ -2802,11 +3062,36 @@ class UpdateStateResponse : public StateResponseProtoMessage {
|
||||
bool in_progress{false};
|
||||
bool has_progress{false};
|
||||
float progress{0.0f};
|
||||
std::string current_version{};
|
||||
std::string latest_version{};
|
||||
std::string title{};
|
||||
std::string release_summary{};
|
||||
std::string release_url{};
|
||||
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;
|
||||
}
|
||||
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
@ -148,7 +148,7 @@ class CustomAPIDevice {
|
||||
*/
|
||||
void call_homeassistant_service(const std::string &service_name) {
|
||||
HomeassistantServiceResponse resp;
|
||||
resp.service = service_name;
|
||||
resp.set_service(service_name.c_str(), service_name.length());
|
||||
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.service = service_name;
|
||||
resp.set_service(service_name.c_str(), service_name.length());
|
||||
for (auto &it : data) {
|
||||
HomeassistantServiceMap kv;
|
||||
kv.key = it.first;
|
||||
kv.value = it.second;
|
||||
resp.data.push_back(kv);
|
||||
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());
|
||||
}
|
||||
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.service = event_name;
|
||||
resp.set_service(event_name.c_str(), event_name.length());
|
||||
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.service = service_name;
|
||||
resp.set_service(service_name.c_str(), service_name.length());
|
||||
resp.is_event = true;
|
||||
for (auto &it : data) {
|
||||
HomeassistantServiceMap kv;
|
||||
kv.key = it.first;
|
||||
kv.value = it.second;
|
||||
resp.data.push_back(kv);
|
||||
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());
|
||||
}
|
||||
global_api_server->send_homeassistant_service_call(resp);
|
||||
}
|
||||
|
@ -59,25 +59,29 @@ template<typename... Ts> class HomeAssistantServiceCallAction : public Action<Ts
|
||||
|
||||
void play(Ts... x) override {
|
||||
HomeassistantServiceResponse resp;
|
||||
resp.service = this->service_.value(x...);
|
||||
std::string service_value = this->service_.value(x...);
|
||||
resp.set_service(service_value.c_str(), service_value.length());
|
||||
resp.is_event = this->is_event_;
|
||||
for (auto &it : this->data_) {
|
||||
HomeassistantServiceMap kv;
|
||||
kv.key = it.key;
|
||||
kv.value = it.value.value(x...);
|
||||
resp.data.push_back(kv);
|
||||
resp.data.emplace_back();
|
||||
auto &kv = resp.data.back();
|
||||
kv.set_key(it.key.c_str(), it.key.length());
|
||||
std::string value = it.value.value(x...);
|
||||
kv.set_value(value.c_str(), value.length());
|
||||
}
|
||||
for (auto &it : this->data_template_) {
|
||||
HomeassistantServiceMap kv;
|
||||
kv.key = it.key;
|
||||
kv.value = it.value.value(x...);
|
||||
resp.data_template.push_back(kv);
|
||||
resp.data_template.emplace_back();
|
||||
auto &kv = resp.data_template.back();
|
||||
kv.set_key(it.key.c_str(), it.key.length());
|
||||
std::string value = it.value.value(x...);
|
||||
kv.set_value(value.c_str(), value.length());
|
||||
}
|
||||
for (auto &it : this->variables_) {
|
||||
HomeassistantServiceMap kv;
|
||||
kv.key = it.key;
|
||||
kv.value = it.value.value(x...);
|
||||
resp.variables.push_back(kv);
|
||||
resp.variables.emplace_back();
|
||||
auto &kv = resp.variables.back();
|
||||
kv.set_key(it.key.c_str(), it.key.length());
|
||||
std::string value = it.value.value(x...);
|
||||
kv.set_value(value.c_str(), value.length());
|
||||
}
|
||||
this->parent_->send_homeassistant_service_call(resp);
|
||||
}
|
||||
|
@ -683,12 +683,16 @@ class ProtoSize {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calculates and adds the size of a string/bytes field to the total message size (repeated field version)
|
||||
* @brief Calculates and adds the size of a string field using length
|
||||
*/
|
||||
static inline void add_string_field_repeated(uint32_t &total_size, uint32_t field_id_size, const std::string &str) {
|
||||
// Always calculate size for repeated fields
|
||||
const uint32_t str_size = static_cast<uint32_t>(str.size());
|
||||
total_size += field_id_size + varint(str_size) + str_size;
|
||||
static inline void add_string_field(uint32_t &total_size, uint32_t field_id_size, size_t len) {
|
||||
// Skip calculation if string is empty
|
||||
if (len == 0) {
|
||||
return; // No need to update total_size
|
||||
}
|
||||
|
||||
// Field ID + length varint + string bytes
|
||||
total_size += field_id_size + varint(static_cast<uint32_t>(len)) + static_cast<uint32_t>(len);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,14 +33,14 @@ template<typename... Ts> class UserServiceBase : public UserServiceDescriptor {
|
||||
|
||||
ListEntitiesServicesResponse encode_list_service_response() override {
|
||||
ListEntitiesServicesResponse msg;
|
||||
msg.name = this->name_;
|
||||
msg.set_name(this->name_.c_str(), this->name_.length());
|
||||
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++) {
|
||||
ListEntitiesServicesArgument arg;
|
||||
msg.args.emplace_back();
|
||||
auto &arg = msg.args.back();
|
||||
arg.type = arg_types[i];
|
||||
arg.name = this->arg_names_[i];
|
||||
msg.args.push_back(arg);
|
||||
arg.set_name(this->arg_names_[i].c_str(), this->arg_names_[i].length());
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
@ -84,17 +84,18 @@ void HomeassistantNumber::control(float value) {
|
||||
this->publish_state(value);
|
||||
|
||||
api::HomeassistantServiceResponse resp;
|
||||
resp.service = "number.set_value";
|
||||
resp.set_service("number.set_value", 17);
|
||||
|
||||
api::HomeassistantServiceMap entity_id;
|
||||
entity_id.key = "entity_id";
|
||||
entity_id.value = this->entity_id_;
|
||||
resp.data.push_back(entity_id);
|
||||
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());
|
||||
|
||||
api::HomeassistantServiceMap entity_value;
|
||||
entity_value.key = "value";
|
||||
entity_value.value = to_string(value);
|
||||
resp.data.push_back(entity_value);
|
||||
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());
|
||||
|
||||
api::global_api_server->send_homeassistant_service_call(resp);
|
||||
}
|
||||
|
@ -42,15 +42,15 @@ void HomeassistantSwitch::write_state(bool state) {
|
||||
|
||||
api::HomeassistantServiceResponse resp;
|
||||
if (state) {
|
||||
resp.service = "homeassistant.turn_on";
|
||||
resp.set_service("homeassistant.turn_on", 22);
|
||||
} else {
|
||||
resp.service = "homeassistant.turn_off";
|
||||
resp.set_service("homeassistant.turn_off", 23);
|
||||
}
|
||||
|
||||
api::HomeassistantServiceMap entity_id_kv;
|
||||
entity_id_kv.key = "entity_id";
|
||||
entity_id_kv.value = this->entity_id_;
|
||||
resp.data.push_back(entity_id_kv);
|
||||
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());
|
||||
|
||||
api::global_api_server->send_homeassistant_service_call(resp);
|
||||
}
|
||||
|
@ -340,6 +340,10 @@ def create_field_type_info(
|
||||
if field.type == 12:
|
||||
return BytesType(field, needs_decode, needs_encode)
|
||||
|
||||
# Special handling for string fields
|
||||
if field.type == 9:
|
||||
return StringType(field, needs_decode, needs_encode)
|
||||
|
||||
validate_field_type(field.type, field.name)
|
||||
return TYPE_INFO[field.type](field)
|
||||
|
||||
@ -540,12 +544,70 @@ class StringType(TypeInfo):
|
||||
encode_func = "encode_string"
|
||||
wire_type = WireType.LENGTH_DELIMITED # Uses wire type 2
|
||||
|
||||
@property
|
||||
def public_content(self) -> list[str]:
|
||||
content: list[str] = []
|
||||
# Add std::string storage if message needs decoding
|
||||
if self._needs_decode:
|
||||
content.append(f"std::string {self.field_name}{{}};")
|
||||
|
||||
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 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;",
|
||||
"}",
|
||||
]
|
||||
)
|
||||
return content
|
||||
|
||||
@property
|
||||
def encode_content(self) -> str:
|
||||
return f"buffer.encode_string({self.number}, this->{self.field_name}_ptr_, this->{self.field_name}_len_);"
|
||||
|
||||
def dump(self, name):
|
||||
o = f'out.append("\'").append({name}).append("\'");'
|
||||
return o
|
||||
# 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
|
||||
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"}} else {{"
|
||||
f' out.append("\'").append("").append("\'");'
|
||||
f"}}"
|
||||
)
|
||||
|
||||
# For SOURCE_BOTH, check if pointer 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"}} else {{"
|
||||
f' out.append("\'").append(this->{self.field_name}).append("\'");'
|
||||
f"}}"
|
||||
)
|
||||
|
||||
def get_size_calculation(self, name: str, force: bool = False) -> str:
|
||||
return self._get_simple_size_calculation(name, force, "add_string_field")
|
||||
# For SOURCE_CLIENT only messages, use the string field directly
|
||||
if not self._needs_encode:
|
||||
return self._get_simple_size_calculation(name, force, "add_string_field")
|
||||
|
||||
# Check if this is being called from a repeated field context
|
||||
# In that case, 'name' will be 'it' and we need to use .length()
|
||||
if name == "it":
|
||||
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
|
||||
field_id_size = self.calculate_field_id_size()
|
||||
return f"ProtoSize::add_string_field(total_size, {field_id_size}, this->{self.field_name}_len_);"
|
||||
|
||||
def get_estimated_size(self) -> int:
|
||||
return self.calculate_field_id_size() + 8 # field ID + 8 bytes typical string
|
||||
|
Loading…
x
Reference in New Issue
Block a user