-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
startup.cpp
37 lines (27 loc) · 742 Bytes
/
startup.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "esphome/core/log.h"
#include "esphome/core/helpers.h"
#include "esphome/core/hal.h"
#include "startup.h"
namespace esphome {
namespace startup {
static const char *const TAG = "startup";
StartupSensor::StartupSensor() : start_(millis()){};
void StartupSensor::dump_config() { LOG_SENSOR("", "Startup Sensor", this); }
void StartupSensor::update() {
if (this->startup_ != 0) {
this->publish_state((float) this->startup_);
}
}
void StartupSensor::loop() {
if (startup_ != 0) {
return;
}
auto now = this->time_->now();
if (!now.is_valid()) {
// time is not sync yet
return;
}
this->startup_ = now.timestamp - (millis() - this->start_) / 1000;
}
} // namespace startup
} // namespace esphome