11static size_t append_flash_str(
char *buf,
size_t buf_size,
size_t pos,
const char *str) {
19static void append_unit(
char *buf,
size_t buf_size,
size_t &
pos,
const char *separator,
unsigned value,
22 pos = append_flash_str(buf, buf_size,
pos, separator);
24 pos = buf_append_printf(buf, buf_size,
pos,
"%u",
value);
25 pos = append_flash_str(buf, buf_size,
pos, label);
36 unsigned seconds = uptime % 60;
38 unsigned minutes = uptime % 60;
40 unsigned hours = uptime % 24;
42 unsigned days = uptime;
45 bool seconds_enabled = interval < 30;
46 bool minutes_enabled = interval < 1800;
47 bool hours_enabled = interval < 12 * 3600;
51 bool show_hours = hours_enabled && (show_days || hours > 0);
52 bool show_minutes = minutes_enabled && (show_hours || minutes > 0);
53 bool show_seconds = seconds_enabled && (show_minutes || seconds > 0);
56 if (!show_days && !show_hours && !show_minutes && !show_seconds) {
57 if (seconds_enabled) {
59 }
else if (minutes_enabled) {
61 }
else if (hours_enabled) {
75 append_unit(buf,
sizeof(buf),
pos,
format->separator, days,
format->days);
77 append_unit(buf,
sizeof(buf),
pos,
format->separator, hours,
format->hours);
79 append_unit(buf,
sizeof(buf),
pos,
format->separator, minutes,
format->minutes);
81 append_unit(buf,
sizeof(buf),
pos,
format->separator, seconds,
format->seconds);
virtual uint32_t get_update_interval() const
Get the update interval in ms of this sensor.
void publish_state(const std::string &state)
void publish_uptime_(uint32_t uptime)
float get_setup_priority() const override
const UptimeFormat * format_
void publish_uptime(uint32_t uptime)
Publish uptime (in seconds) as text, keeping only the units the update interval can resolve.
void dump_config() override
constexpr float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
ESPHOME_LOG_TAG(TAG, "uptime.sensor")
size_t buf_append_str_p(char *buf, size_t size, size_t pos, PGM_P str)
Safely append a PROGMEM string to buffer, returning new position (capped at size).
size_t buf_append_str(char *buf, size_t size, size_t pos, const char *str)
Safely append a string to buffer, returning new position (capped at size).
uint8_t progmem_read_byte(const uint8_t *addr)