ESPHome
2026.3.0-dev
Loading...
Searching...
No Matches
esphome
components
uptime
sensor
uptime_seconds_sensor.cpp
Go to the documentation of this file.
1
#include "
uptime_seconds_sensor.h
"
2
3
#include "
esphome/core/hal.h
"
4
#include "
esphome/core/log.h
"
5
6
namespace
esphome::uptime
{
7
8
static
const
char
*
const
TAG =
"uptime.sensor"
;
9
10
void
UptimeSecondsSensor::update
() {
11
const
uint64_t uptime =
millis_64
();
12
const
uint64_t seconds_int = uptime / 1000ULL;
13
const
float
seconds = float(seconds_int) + (uptime % 1000ULL) / 1000.0f;
14
this->
publish_state
(seconds);
15
}
16
float
UptimeSecondsSensor::get_setup_priority
()
const
{
return
setup_priority::HARDWARE
; }
17
void
UptimeSecondsSensor::dump_config
() {
18
LOG_SENSOR(
""
,
"Uptime Sensor"
,
this
);
19
ESP_LOGCONFIG(TAG,
" Type: Seconds"
);
20
}
21
22
}
// namespace esphome::uptime
esphome::sensor::Sensor::publish_state
void publish_state(float state)
Publish a new state to the front-end.
Definition
sensor.cpp:65
esphome::uptime::UptimeSecondsSensor::get_setup_priority
float get_setup_priority() const override
Definition
uptime_seconds_sensor.cpp:16
esphome::uptime::UptimeSecondsSensor::update
void update() override
Definition
uptime_seconds_sensor.cpp:10
esphome::uptime::UptimeSecondsSensor::dump_config
void dump_config() override
Definition
uptime_seconds_sensor.cpp:17
hal.h
log.h
esphome::setup_priority::HARDWARE
constexpr float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition
component.h:29
esphome::uptime
Definition
uptime_seconds_sensor.cpp:6
esphome::millis_64
uint64_t HOT millis_64()
Definition
core.cpp:26
uptime_seconds_sensor.h
Generated by
1.12.0