mirror of
https://github.com/esphome/esphome.git
synced 2024-12-18 03:24:54 +01:00
Add wifi.save_ap_settings action
This commit is contained in:
parent
3cbdf63f56
commit
0d6b79d714
3 changed files with 29 additions and 0 deletions
|
@ -63,6 +63,7 @@ WiFiConnectedCondition = wifi_ns.class_("WiFiConnectedCondition", Condition)
|
|||
WiFiEnabledCondition = wifi_ns.class_("WiFiEnabledCondition", Condition)
|
||||
WiFiEnableAction = wifi_ns.class_("WiFiEnableAction", automation.Action)
|
||||
WiFiDisableAction = wifi_ns.class_("WiFiDisableAction", automation.Action)
|
||||
WiFiSaveAPSettingsAction = wifi_ns.class_("WiFiSaveAPSettingsAction", automation.Action)
|
||||
|
||||
|
||||
def validate_password(value):
|
||||
|
@ -483,3 +484,16 @@ async def wifi_enable_to_code(config, action_id, template_arg, args):
|
|||
@automation.register_action("wifi.disable", WiFiDisableAction, cv.Schema({}))
|
||||
async def wifi_disable_to_code(config, action_id, template_arg, args):
|
||||
return cg.new_Pvariable(action_id, template_arg)
|
||||
|
||||
|
||||
@automation.register_action("wifi.save_ap_settings", WiFiSaveAPSettingsAction, cv.Schema({
|
||||
cv.Required(CONF_SSID): cv.templatable(cv.ssid),
|
||||
cv.Required(CONF_PASSWORD): cv.templatable(validate_password),
|
||||
}))
|
||||
async def wifi_save_settings_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
ssid = await cg.templatable(config[CONF_SSID], args, cg.std_string)
|
||||
password = await cg.templatable(config[CONF_PASSWORD], args, cg.std_string)
|
||||
cg.add(var.set_ssid(ssid))
|
||||
cg.add(var.set_password(password))
|
||||
return var
|
||||
|
|
|
@ -441,6 +441,18 @@ template<typename... Ts> class WiFiDisableAction : public Action<Ts...> {
|
|||
void play(Ts... x) override { global_wifi_component->disable(); }
|
||||
};
|
||||
|
||||
template<typename... Ts> class WiFiSaveAPSettingsAction : public Action<Ts...> {
|
||||
public:
|
||||
TEMPLATABLE_VALUE(std::string, ssid)
|
||||
TEMPLATABLE_VALUE(std::string, password)
|
||||
|
||||
void play(Ts... x) override {
|
||||
global_wifi_component->save_wifi_sta(
|
||||
this->ssid_.value(x...), this->password_.value(x...)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace wifi
|
||||
} // namespace esphome
|
||||
#endif
|
||||
|
|
|
@ -3,6 +3,9 @@ esphome:
|
|||
then:
|
||||
- wifi.disable
|
||||
- wifi.enable
|
||||
- wifi.save_ap_settings:
|
||||
- ssid: MySSID
|
||||
- password: password1
|
||||
|
||||
wifi:
|
||||
ssid: MySSID
|
||||
|
|
Loading…
Reference in a new issue