ESPHome
2026.1.0-dev
Loading...
Searching...
No Matches
esphome
components
version
version_text_sensor.cpp
Go to the documentation of this file.
1
#include "
version_text_sensor.h
"
2
#include "
esphome/core/application.h
"
3
#include "
esphome/core/log.h
"
4
#include "
esphome/core/version.h
"
5
#include "
esphome/core/helpers.h
"
6
#include "
esphome/core/progmem.h
"
7
8
namespace
esphome
{
9
namespace
version {
10
11
static
const
char
*
const
TAG =
"version.text_sensor"
;
12
13
void
VersionTextSensor::setup
() {
14
static
const
char
PREFIX[]
PROGMEM
= ESPHOME_VERSION
" (config hash 0x"
;
15
static
const
char
BUILT_STR[]
PROGMEM
=
", built "
;
16
// Buffer size: PREFIX + 8 hex chars + BUILT_STR + BUILD_TIME_STR_SIZE + ")" + null
17
constexpr
size_t
buf_size =
sizeof
(PREFIX) + 8 +
sizeof
(BUILT_STR) +
esphome::Application::BUILD_TIME_STR_SIZE
+ 2;
18
char
version_str[buf_size];
19
20
ESPHOME_strncpy_P(version_str, PREFIX,
sizeof
(version_str));
21
22
size_t
len
= strlen(version_str);
23
snprintf(version_str +
len
,
sizeof
(version_str) -
len
,
"%08"
PRIx32,
App
.
get_config_hash
());
24
25
if
(!this->
hide_timestamp_
) {
26
size_t
len = strlen(version_str);
27
ESPHOME_strncat_P(version_str, BUILT_STR,
sizeof
(version_str) -
len
- 1);
28
ESPHOME_strncat_P(version_str, ESPHOME_BUILD_TIME_STR,
sizeof
(version_str) - strlen(version_str) - 1);
29
}
30
31
strncat(version_str,
")"
,
sizeof
(version_str) - strlen(version_str) - 1);
32
version_str[
sizeof
(version_str) - 1] =
'\0'
;
33
this->
publish_state
(version_str);
34
}
35
float
VersionTextSensor::get_setup_priority
()
const
{
return
setup_priority::DATA
; }
36
void
VersionTextSensor::set_hide_timestamp
(
bool
hide_timestamp) { this->
hide_timestamp_
= hide_timestamp; }
37
void
VersionTextSensor::dump_config
() { LOG_TEXT_SENSOR(
""
,
"Version Text Sensor"
,
this
); }
38
39
}
// namespace version
40
}
// namespace esphome
application.h
esphome::Application::BUILD_TIME_STR_SIZE
static constexpr size_t BUILD_TIME_STR_SIZE
Size of buffer required for build time string (including null terminator)
Definition
application.h:283
esphome::Application::get_config_hash
constexpr uint32_t get_config_hash()
Get the config hash as a 32-bit integer.
Definition
application.h:286
esphome::text_sensor::TextSensor::publish_state
void publish_state(const std::string &state)
Definition
text_sensor.cpp:27
esphome::version::VersionTextSensor::hide_timestamp_
bool hide_timestamp_
Definition
version_text_sensor.h:17
esphome::version::VersionTextSensor::setup
void setup() override
Definition
version_text_sensor.cpp:13
esphome::version::VersionTextSensor::set_hide_timestamp
void set_hide_timestamp(bool hide_timestamp)
Definition
version_text_sensor.cpp:36
esphome::version::VersionTextSensor::dump_config
void dump_config() override
Definition
version_text_sensor.cpp:37
esphome::version::VersionTextSensor::get_setup_priority
float get_setup_priority() const override
Definition
version_text_sensor.cpp:35
helpers.h
log.h
esphome::setup_priority::DATA
const float DATA
For components that import data from directly connected sensors like DHT.
Definition
component.cpp:81
esphome
Providing packet encoding functions for exchanging data with a remote host.
Definition
a01nyub.cpp:7
esphome::len
std::string size_t len
Definition
helpers.h:533
esphome::App
Application App
Global storage of Application pointer - only one Application can exist.
Definition
application.cpp:652
progmem.h
version.h
version_text_sensor.h
PROGMEM
const uint8_t ESPHOME_WEBSERVER_INDEX_HTML[] PROGMEM
Definition
web_server.h:27
Generated by
1.12.0