diff --git a/esphome/components/ethernet/__init__.py b/esphome/components/ethernet/__init__.py index 1a50dbebfc3..a4b18942026 100644 --- a/esphome/components/ethernet/__init__.py +++ b/esphome/components/ethernet/__init__.py @@ -1,7 +1,6 @@ from dataclasses import dataclass from esphome import automation, pins -from esphome.automation import Condition import esphome.codegen as cg from esphome.components import spi from esphome.components.network import ( @@ -238,10 +237,6 @@ MANUAL_IP_SCHEMA = cv.Schema( 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: @@ -932,15 +927,22 @@ def _filter_source_files() -> list[str]: FILTER_SOURCE_FILES = _filter_source_files -automation.register_bare_condition( - "ethernet.connected", EthernetConnectedCondition, cv.Schema({}) -) -automation.register_bare_condition( - "ethernet.enabled", EthernetEnabledCondition, cv.Schema({}) -) -automation.register_bare_action( - "ethernet.enable", EthernetEnableAction, cv.Schema({}), synchronous=True -) -automation.register_bare_action( - "ethernet.disable", EthernetDisableAction, cv.Schema({}), synchronous=True +ETHERNET_AUTOMATION_SCHEMA = cv.Schema( + { + cv.GenerateID(): cv.use_id(EthernetComponent), + } ) + +for _name, _check in ( + ("ethernet.connected", "is_connected()"), + ("ethernet.enabled", "is_enabled()"), +): + automation.register_apply_condition(_name, ETHERNET_AUTOMATION_SCHEMA, _check) + +for _name, _call in ( + ("ethernet.enable", "enable()"), + ("ethernet.disable", "disable()"), +): + automation.register_apply_action( + _name, ETHERNET_AUTOMATION_SCHEMA, automation.ApplyCall(_call) + ) diff --git a/esphome/components/ethernet/automation.h b/esphome/components/ethernet/automation.h deleted file mode 100644 index f975f52bffd..00000000000 --- a/esphome/components/ethernet/automation.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include "esphome/core/defines.h" -#ifdef USE_ETHERNET -#include "ethernet_component.h" - -namespace esphome::ethernet { - -template class EthernetConnectedCondition final : public Condition { - public: - bool check(const Ts &...x) override { return global_eth_component->is_connected(); } -}; - -template class EthernetEnabledCondition final : public Condition { - public: - 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