From 937b73c8f18b9c33631fb21bece80456f89e2c0c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 25 Sep 2026 01:51:23 +0100 Subject: [PATCH] [ethernet] Use register_apply_action for ethernet.enable and ethernet.disable --- esphome/components/ethernet/__init__.py | 15 ++++++++------- esphome/components/ethernet/automation.h | 10 ---------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/esphome/components/ethernet/__init__.py b/esphome/components/ethernet/__init__.py index 3e7d345805c..d6d4a385bf7 100644 --- a/esphome/components/ethernet/__init__.py +++ b/esphome/components/ethernet/__init__.py @@ -241,8 +241,6 @@ EthernetComponent = ethernet_ns.class_("EthernetComponent", cg.Component) ManualIP = ethernet_ns.struct("ManualIP") EthernetConnectedCondition = ethernet_ns.class_("EthernetConnectedCondition", Condition) EthernetEnabledCondition = ethernet_ns.class_("EthernetEnabledCondition", Condition) -EthernetEnableAction = ethernet_ns.class_("EthernetEnableAction", automation.Action) -EthernetDisableAction = ethernet_ns.class_("EthernetDisableAction", automation.Action) def _is_framework_spi_polling_mode_supported() -> bool: @@ -938,10 +936,13 @@ for _name, _cls in ( ("ethernet.enabled", EthernetEnabledCondition), ): automation.register_condition(_name, _cls, cv.Schema({}))(_new_pvariable_to_code) -for _name, _cls in ( - ("ethernet.enable", EthernetEnableAction), - ("ethernet.disable", EthernetDisableAction), + +ETHERNET_ACTION_SCHEMA = cv.Schema({cv.GenerateID(): cv.use_id(EthernetComponent)}) + +for _name, _method in ( + ("ethernet.enable", "enable()"), + ("ethernet.disable", "disable()"), ): - automation.register_action(_name, _cls, cv.Schema({}), synchronous=True)( - _new_pvariable_to_code + automation.register_apply_action( + _name, ETHERNET_ACTION_SCHEMA, automation.ApplyCall(_method) ) diff --git a/esphome/components/ethernet/automation.h b/esphome/components/ethernet/automation.h index f975f52bffd..711d63ae8f1 100644 --- a/esphome/components/ethernet/automation.h +++ b/esphome/components/ethernet/automation.h @@ -16,15 +16,5 @@ template class EthernetEnabledCondition final : public Condition bool check(const Ts &...x) override { return global_eth_component->is_enabled(); } }; -template class EthernetEnableAction final : public Action { - public: - void play(const Ts &...x) override { global_eth_component->enable(); } -}; - -template class EthernetDisableAction final : public Action { - public: - void play(const Ts &...x) override { global_eth_component->disable(); } -}; - } // namespace esphome::ethernet #endif