1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-24 12:43:51 +01:00
Files
esphome/esphome/components/sntp/sntp_component.h
2024-12-04 13:13:07 +13:00

36 lines
1.2 KiB
C++

#pragma once
#include "esphome/core/component.h"
#include "esphome/components/time/real_time_clock.h"
namespace esphome {
namespace sntp {
/// The SNTP component allows you to configure local timekeeping via Simple Network Time Protocol.
///
/// \note
/// The C library (newlib) available on ESPs only supports TZ strings that specify an offset and DST info;
/// you cannot specify zone names or paths to zoneinfo files.
/// \see https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
class SNTPComponent : public time::RealTimeClock {
public:
SNTPComponent(const std::vector<std::string> &servers) : servers_(servers) {}
// Note: set_servers() has been removed and replaced by a constructor - calling set_servers after setup would
// have had no effect anyway, and making the strings immutable avoids the need to strdup their contents.
void setup() override;
void dump_config() override;
float get_setup_priority() const override { return setup_priority::BEFORE_CONNECTION; }
void update() override;
void loop() override;
protected:
std::vector<std::string> servers_;
bool has_time_{false};
};
} // namespace sntp
} // namespace esphome