mirror of
https://github.com/esphome/esphome.git
synced 2026-10-14 10:12:52 +00:00
[wifi] Use register_apply_action for wifi.enable, wifi.disable and wifi.roam
This commit is contained in:
@@ -67,14 +67,13 @@ from esphome.const import (
|
||||
)
|
||||
from esphome.core import (
|
||||
CORE,
|
||||
ID,
|
||||
CoroPriority,
|
||||
EsphomeError,
|
||||
HexInt,
|
||||
coroutine_with_priority,
|
||||
)
|
||||
import esphome.final_validate as fv
|
||||
from esphome.types import ConfigType, TemplateArgsType
|
||||
from esphome.types import ConfigType
|
||||
|
||||
from . import wpa2_eap
|
||||
|
||||
@@ -211,9 +210,6 @@ WIFI_8266_PHY_MODES = {
|
||||
WiFiConnectedCondition = wifi_ns.class_("WiFiConnectedCondition", Condition)
|
||||
WiFiEnabledCondition = wifi_ns.class_("WiFiEnabledCondition", Condition)
|
||||
WiFiAPActiveCondition = wifi_ns.class_("WiFiAPActiveCondition", Condition)
|
||||
WiFiEnableAction = wifi_ns.class_("WiFiEnableAction", automation.Action)
|
||||
WiFiDisableAction = wifi_ns.class_("WiFiDisableAction", automation.Action)
|
||||
WiFiRoamAction = wifi_ns.class_("WiFiRoamAction", automation.Action)
|
||||
WiFiConfigureAction = wifi_ns.class_(
|
||||
"WiFiConfigureAction", automation.Action, cg.Component
|
||||
)
|
||||
@@ -845,30 +841,16 @@ async def wifi_ap_active_to_code(config, condition_id, template_arg, args):
|
||||
return cg.new_Pvariable(condition_id, template_arg)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"wifi.enable", WiFiEnableAction, cv.Schema({}), synchronous=True
|
||||
)
|
||||
async def wifi_enable_to_code(config, action_id, template_arg, args):
|
||||
return cg.new_Pvariable(action_id, template_arg)
|
||||
WIFI_ACTION_SCHEMA = cv.Schema({cv.GenerateID(): cv.use_id(WiFiComponent)})
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"wifi.disable", WiFiDisableAction, cv.Schema({}), synchronous=True
|
||||
)
|
||||
async def wifi_disable_to_code(config, action_id, template_arg, args):
|
||||
return cg.new_Pvariable(action_id, template_arg)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"wifi.roam", WiFiRoamAction, cv.Schema({}), synchronous=True
|
||||
)
|
||||
async def wifi_roam_to_code(
|
||||
config: ConfigType,
|
||||
action_id: ID,
|
||||
template_arg: cg.TemplateArguments,
|
||||
args: TemplateArgsType,
|
||||
) -> cg.MockObj:
|
||||
return cg.new_Pvariable(action_id, template_arg)
|
||||
for _name, _call in (
|
||||
("wifi.enable", "enable()"),
|
||||
("wifi.disable", "disable()"),
|
||||
("wifi.roam", "force_roam_check()"),
|
||||
):
|
||||
automation.register_apply_action(
|
||||
_name, WIFI_ACTION_SCHEMA, automation.ApplyCall(_call)
|
||||
)
|
||||
|
||||
|
||||
KEEP_SCAN_RESULTS_KEY = "wifi_keep_scan_results"
|
||||
|
||||
@@ -21,21 +21,6 @@ template<typename... Ts> class WiFiAPActiveCondition final : public Condition<Ts
|
||||
bool check(const Ts &...x) override { return global_wifi_component->is_ap_active(); }
|
||||
};
|
||||
|
||||
template<typename... Ts> class WiFiEnableAction final : public Action<Ts...> {
|
||||
public:
|
||||
void play(const Ts &...x) override { global_wifi_component->enable(); }
|
||||
};
|
||||
|
||||
template<typename... Ts> class WiFiDisableAction final : public Action<Ts...> {
|
||||
public:
|
||||
void play(const Ts &...x) override { global_wifi_component->disable(); }
|
||||
};
|
||||
|
||||
template<typename... Ts> class WiFiRoamAction final : public Action<Ts...> {
|
||||
public:
|
||||
void play(const Ts &...x) override { global_wifi_component->force_roam_check(); }
|
||||
};
|
||||
|
||||
template<typename... Ts> class WiFiConfigureAction final : public Action<Ts...>, public Component {
|
||||
public:
|
||||
TEMPLATABLE_VALUE(std::string, ssid)
|
||||
|
||||
Reference in New Issue
Block a user