1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-15 14:25:45 +00:00
This commit is contained in:
J. Nick Koston
2025-10-24 14:26:17 -07:00
parent 45770811d2
commit 54fb391f13
2 changed files with 15 additions and 16 deletions

View File

@@ -49,15 +49,10 @@ async def to_code(config):
# Define server count at compile time
cg.add_define("SNTP_SERVER_COUNT", server_count)
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await time_.register_time(var, config)
# Generate PROGMEM strings for ESP8266, regular strings for other platforms
if CORE.is_esp8266:
# On ESP8266, use PROGMEM to store strings in flash
# Use ProgmemAssignmentExpression to generate: static const char name[] PROGMEM = "value";
server_vars = []
for i, server in enumerate(servers):
var_name = f"{config[CONF_ID].id}_server_{i}"
# Create PROGMEM string: static const char var_name[] PROGMEM = "server";
@@ -65,12 +60,17 @@ async def to_code(config):
"char", var_name, cg.safe_exp(server)
)
cg.add(assignment)
# Assign pointer to array element
cg.add(cg.RawStatement(f"{var}->servers_[{i}] = {var_name};"))
server_vars.append(cg.RawExpression(var_name))
# Pass PROGMEM string pointers to constructor using ArrayInitializer
var = cg.new_Pvariable(config[CONF_ID], cg.ArrayInitializer(*server_vars))
else:
# On other platforms, use regular string literals
for i, server in enumerate(servers):
cg.add(cg.RawStatement(f"{var}->servers_[{i}] = {cg.safe_exp(server)};"))
# On other platforms, pass regular string literals to constructor
var = cg.new_Pvariable(
config[CONF_ID], cg.ArrayInitializer(*[cg.safe_exp(s) for s in servers])
)
await cg.register_component(var, config)
await time_.register_time(var, config)
if CORE.is_esp8266 and len(servers) > 1:
# We need LwIP features enabled to get 3 SNTP servers (not just one)