1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 06:33:51 +00:00

Add cg.with_local_variable (#3577)

This commit is contained in:
Javier Peletier
2022-10-05 00:50:03 +02:00
committed by GitHub
parent 16249c02a5
commit 05edfd0e82
3 changed files with 54 additions and 8 deletions

View File

@@ -332,8 +332,7 @@ def manual_ip(config):
)
def wifi_network(config, static_ip):
ap = cg.variable(config[CONF_ID], WiFiAP())
def wifi_network(config, ap, static_ip):
if CONF_SSID in config:
cg.add(ap.set_ssid(config[CONF_SSID]))
if CONF_PASSWORD in config:
@@ -360,14 +359,21 @@ async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
cg.add(var.set_use_address(config[CONF_USE_ADDRESS]))
for network in config.get(CONF_NETWORKS, []):
def add_sta(ap, network):
ip_config = network.get(CONF_MANUAL_IP, config.get(CONF_MANUAL_IP))
cg.add(var.add_sta(wifi_network(network, ip_config)))
cg.add(var.add_sta(wifi_network(network, ap, ip_config)))
for network in config.get(CONF_NETWORKS, []):
cg.with_local_variable(network[CONF_ID], WiFiAP(), add_sta, network)
if CONF_AP in config:
conf = config[CONF_AP]
ip_config = conf.get(CONF_MANUAL_IP, config.get(CONF_MANUAL_IP))
cg.add(var.set_ap(wifi_network(conf, ip_config)))
cg.with_local_variable(
conf[CONF_ID],
WiFiAP(),
lambda ap: cg.add(var.set_ap(wifi_network(conf, ap, ip_config))),
)
cg.add(var.set_ap_timeout(conf[CONF_AP_TIMEOUT]))
cg.add(var.set_reboot_timeout(config[CONF_REBOOT_TIMEOUT]))