This commit is contained in:
Rapsssito 2024-09-17 12:34:32 +02:00
parent eef6236bc9
commit be7adba352
3 changed files with 5 additions and 6 deletions

View file

@ -67,6 +67,7 @@ WiFiEnableAction = wifi_ns.class_("WiFiEnableAction", automation.Action)
WiFiDisableAction = wifi_ns.class_("WiFiDisableAction", automation.Action)
WiFiSetSTAAction = wifi_ns.class_("WiFiSetSTAAction", automation.Action, cg.Component)
def validate_password(value):
value = cv.string_strict(value)
if not value:
@ -515,8 +516,6 @@ async def wifi_set_sta_to_code(config, action_id, template_arg, args):
var.get_connect_trigger(), [], on_connect_config
)
if on_error_config := config.get(CONF_ON_ERROR):
await automation.build_automation(
var.get_error_trigger(), [], on_error_config
)
await automation.build_automation(var.get_error_trigger(), [], on_error_config)
await cg.register_component(var, config)
return var

View file

@ -457,7 +457,7 @@ template<typename... Ts> class WiFiSetSTAAction : public Action<Ts...>, public C
// If already connected to the same AP, do nothing
if (global_wifi_component->wifi_ssid() == ssid) {
// Callback to notify the user that the connection was successful
this->connect_trigger_->trigger();
this->connect_trigger_->trigger();
return;
}
// Set the state to connecting
@ -506,7 +506,7 @@ template<typename... Ts> class WiFiSetSTAAction : public Action<Ts...>, public C
}
}
}
protected:
bool connecting_{false};
WiFiAP new_sta_;

View file

@ -6,7 +6,7 @@ esphome:
- wifi.set_sta:
ssid: MySSID
password: password1
on_connect:
on_connect:
- logger.log: "Connected to WiFi!"
on_error:
- logger.log: "Failed to connect to WiFi!"