diff --git a/esphome/components/wifi/__init__.py b/esphome/components/wifi/__init__.py index c22d49e6654..767dcda5d00 100644 --- a/esphome/components/wifi/__init__.py +++ b/esphome/components/wifi/__init__.py @@ -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" diff --git a/esphome/components/wifi/automation.h b/esphome/components/wifi/automation.h index c14341330f5..fde1ff5bdbb 100644 --- a/esphome/components/wifi/automation.h +++ b/esphome/components/wifi/automation.h @@ -21,21 +21,6 @@ template class WiFiAPActiveCondition final : public Conditionis_ap_active(); } }; -template class WiFiEnableAction final : public Action { - public: - void play(const Ts &...x) override { global_wifi_component->enable(); } -}; - -template class WiFiDisableAction final : public Action { - public: - void play(const Ts &...x) override { global_wifi_component->disable(); } -}; - -template class WiFiRoamAction final : public Action { - public: - void play(const Ts &...x) override { global_wifi_component->force_roam_check(); } -}; - template class WiFiConfigureAction final : public Action, public Component { public: TEMPLATABLE_VALUE(std::string, ssid)