mirror of
https://github.com/esphome/esphome.git
synced 2025-04-15 15:20:27 +01:00
real_time_clock: Apply timezone immediately in set_timezone() (#8531)
This commit is contained in:
parent
399c9ba4be
commit
8c5adfb33f
@ -21,10 +21,6 @@ namespace time {
|
|||||||
static const char *const TAG = "time";
|
static const char *const TAG = "time";
|
||||||
|
|
||||||
RealTimeClock::RealTimeClock() = default;
|
RealTimeClock::RealTimeClock() = default;
|
||||||
void RealTimeClock::call_setup() {
|
|
||||||
this->apply_timezone_();
|
|
||||||
PollingComponent::call_setup();
|
|
||||||
}
|
|
||||||
void RealTimeClock::synchronize_epoch_(uint32_t epoch) {
|
void RealTimeClock::synchronize_epoch_(uint32_t epoch) {
|
||||||
// Update UTC epoch time.
|
// Update UTC epoch time.
|
||||||
struct timeval timev {
|
struct timeval timev {
|
||||||
|
@ -21,7 +21,10 @@ class RealTimeClock : public PollingComponent {
|
|||||||
explicit RealTimeClock();
|
explicit RealTimeClock();
|
||||||
|
|
||||||
/// Set the time zone.
|
/// Set the time zone.
|
||||||
void set_timezone(const std::string &tz) { this->timezone_ = tz; }
|
void set_timezone(const std::string &tz) {
|
||||||
|
this->timezone_ = tz;
|
||||||
|
this->apply_timezone_();
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the time zone currently in use.
|
/// Get the time zone currently in use.
|
||||||
std::string get_timezone() { return this->timezone_; }
|
std::string get_timezone() { return this->timezone_; }
|
||||||
@ -35,8 +38,6 @@ class RealTimeClock : public PollingComponent {
|
|||||||
/// Get the current time as the UTC epoch since January 1st 1970.
|
/// Get the current time as the UTC epoch since January 1st 1970.
|
||||||
time_t timestamp_now() { return ::time(nullptr); }
|
time_t timestamp_now() { return ::time(nullptr); }
|
||||||
|
|
||||||
void call_setup() override;
|
|
||||||
|
|
||||||
void add_on_time_sync_callback(std::function<void()> callback) {
|
void add_on_time_sync_callback(std::function<void()> callback) {
|
||||||
this->time_sync_callback_.add(std::move(callback));
|
this->time_sync_callback_.add(std::move(callback));
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user