1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-31 15:12:06 +00:00

Merge branch 'sntp_servers_flash' into integration

This commit is contained in:
J. Nick Koston
2025-10-24 17:32:46 -07:00
2 changed files with 3 additions and 8 deletions

View File

@@ -18,7 +18,7 @@ namespace sntp {
/// \see https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html /// \see https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
class SNTPComponent : public time::RealTimeClock { class SNTPComponent : public time::RealTimeClock {
public: public:
SNTPComponent(std::array<const char *, SNTP_SERVER_COUNT> servers) : servers_(servers) {} SNTPComponent(const std::array<const char *, SNTP_SERVER_COUNT> &servers) : servers_(servers) {}
void setup() override; void setup() override;
void dump_config() override; void dump_config() override;

View File

@@ -43,17 +43,12 @@ CONFIG_SCHEMA = cv.All(
async def to_code(config): async def to_code(config):
servers = config[CONF_SERVERS] servers = config[CONF_SERVERS]
server_count = len(servers)
# Define server count at compile time # Define server count at compile time
cg.add_define("SNTP_SERVER_COUNT", server_count) cg.add_define("SNTP_SERVER_COUNT", len(servers))
# Pass string literals to constructor - stored in flash/rodata by compiler # Pass string literals to constructor - stored in flash/rodata by compiler
# On ESP8266, LWIP doesn't support PROGMEM pointers, so strings are in rodata (RAM) var = cg.new_Pvariable(config[CONF_ID], servers)
# but we still avoid the ~24 byte std::string overhead per server
var = cg.new_Pvariable(
config[CONF_ID], cg.ArrayInitializer(*[cg.safe_exp(s) for s in servers])
)
await cg.register_component(var, config) await cg.register_component(var, config)
await time_.register_time(var, config) await time_.register_time(var, config)