Compare commits

..

1 Commits

Author SHA1 Message Date
J. Nick Koston
d67e9d0926 [web_server] Add legacy_id to SSE events for third-party integration compatibility 2026-01-23 08:18:24 -10:00
2 changed files with 16 additions and 21 deletions

View File

@@ -533,6 +533,17 @@ static void set_json_id(JsonObject &root, EntityBase *obj, const char *prefix, J
root[ESPHOME_F("id")] = id_buf;
// Add legacy_id for backward compatibility with third-party integrations
// Old format: {prefix}-{object_id} (e.g., "cover-garage_door")
// Remove before 2026.7.0 when object_id support is fully removed
char legacy_buf[ESPHOME_DOMAIN_MAX_LEN + 1 + OBJECT_ID_MAX_LEN];
char *lp = legacy_buf;
memcpy(lp, prefix, prefix_len);
lp += prefix_len;
*lp++ = '-';
obj->write_object_id_to(lp, sizeof(legacy_buf) - (lp - legacy_buf));
root[ESPHOME_F("legacy_id")] = legacy_buf;
if (start_config == DETAIL_ALL) {
root[ESPHOME_F("domain")] = prefix;
root[ESPHOME_F("name")] = name;

View File

@@ -746,32 +746,16 @@ void WiFiComponent::setup_ap_config_() {
return;
if (this->ap_.get_ssid().empty()) {
// Build AP SSID from app name without heap allocation
// WiFi SSID max is 32 bytes, with MAC suffix we keep first 25 + last 7
static constexpr size_t AP_SSID_MAX_LEN = 32;
static constexpr size_t AP_SSID_PREFIX_LEN = 25;
static constexpr size_t AP_SSID_SUFFIX_LEN = 7;
const std::string &app_name = App.get_name();
const char *name_ptr = app_name.c_str();
size_t name_len = app_name.length();
if (name_len <= AP_SSID_MAX_LEN) {
// Name fits, use directly
this->ap_.set_ssid(name_ptr);
} else {
// Name too long, need to truncate into stack buffer
char ssid_buf[AP_SSID_MAX_LEN + 1];
std::string name = App.get_name();
if (name.length() > 32) {
if (App.is_name_add_mac_suffix_enabled()) {
// Keep first 25 chars and last 7 chars (MAC suffix), remove middle
memcpy(ssid_buf, name_ptr, AP_SSID_PREFIX_LEN);
memcpy(ssid_buf + AP_SSID_PREFIX_LEN, name_ptr + name_len - AP_SSID_SUFFIX_LEN, AP_SSID_SUFFIX_LEN);
name.erase(25, name.length() - 32);
} else {
memcpy(ssid_buf, name_ptr, AP_SSID_MAX_LEN);
name.resize(32);
}
ssid_buf[AP_SSID_MAX_LEN] = '\0';
this->ap_.set_ssid(ssid_buf);
}
this->ap_.set_ssid(name);
}
this->ap_setup_ = this->wifi_start_ap_(this->ap_);