diff --git a/esphome/components/version/version_text_sensor.cpp b/esphome/components/version/version_text_sensor.cpp index f03c91e5f5..67611e55a5 100644 --- a/esphome/components/version/version_text_sensor.cpp +++ b/esphome/components/version/version_text_sensor.cpp @@ -10,14 +10,28 @@ namespace version { static const char *const TAG = "version.text_sensor"; void VersionTextSensor::setup() { - if (this->hide_timestamp_) { - this->publish_state(str_sprintf(ESPHOME_VERSION " (config hash 0x%08" PRIx32 ")", App.get_config_hash())); - } else { + static const char prefix[] PROGMEM = ESPHOME_VERSION " (config hash 0x"; + char version_str[128]; + +#ifdef USE_ESP8266 + strcpy_P(version_str, prefix); +#else + strcpy(version_str, prefix); +#endif + + char hash_str[9]; + snprintf(hash_str, sizeof(hash_str), "%08" PRIx32, App.get_config_hash()); + strcat(version_str, hash_str); + + if (!this->hide_timestamp_) { + strcat(version_str, ", built: "); char build_time_str[esphome::Application::BUILD_TIME_STR_SIZE]; App.get_build_time_string(build_time_str); - this->publish_state(str_sprintf(ESPHOME_VERSION " (config hash 0x%08" PRIx32 ", built: %s)", App.get_config_hash(), - build_time_str)); + strcat(version_str, build_time_str); } + + strcat(version_str, ")"); + this->publish_state(version_str); } float VersionTextSensor::get_setup_priority() const { return setup_priority::DATA; } void VersionTextSensor::set_hide_timestamp(bool hide_timestamp) { this->hide_timestamp_ = hide_timestamp; }