mirror of
https://github.com/esphome/esphome.git
synced 2026-02-21 08:55:36 -07:00
Use PROGMEM for version text sensor strings on ESP8266
Build version string incrementally from PROGMEM literal prefix, avoiding format strings in RAM. Copy from PROGMEM on ESP8266, use directly on other platforms.
This commit is contained in:
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user