[remote_transmitter] Use register_apply_action for the digital_write action (#19550)

This commit is contained in:
J. Nick Koston
2026-09-24 13:28:29 +00:00
committed by GitHub
parent da148bedfe
commit b59518f6ab
3 changed files with 7 additions and 38 deletions
@@ -20,8 +20,7 @@ from esphome.const import (
CONF_VALUE,
PlatformFramework,
)
from esphome.core import CORE, ID
from esphome.cpp_generator import MockObj, TemplateArgsType
from esphome.core import CORE
from esphome.types import ConfigType
_LOGGER = logging.getLogger(__name__)
@@ -38,11 +37,6 @@ remote_transmitter_ns = cg.esphome_ns.namespace("remote_transmitter")
RemoteTransmitterComponent = remote_transmitter_ns.class_(
"RemoteTransmitterComponent", remote_base.RemoteTransmitterBase, cg.Component
)
DigitalWriteAction = remote_transmitter_ns.class_(
"DigitalWriteAction",
automation.Action,
cg.Parented.template(RemoteTransmitterComponent),
)
# Keep in sync with the USE_LIBRETINY_VARIANT_RTL8720C / REMOTE_TRANSMITTER_BK_PWM gates in
@@ -138,23 +132,12 @@ DIGITAL_WRITE_ACTION_SCHEMA = cv.maybe_simple_value(
)
@automation.register_action(
automation.register_apply_action(
"remote_transmitter.digital_write",
DigitalWriteAction,
DIGITAL_WRITE_ACTION_SCHEMA,
synchronous=True,
automation.ApplyField(CONF_VALUE, "digital_write", cg.bool_),
id_key=CONF_TRANSMITTER_ID,
)
async def digital_write_action_to_code(
config: ConfigType,
action_id: ID,
template_arg: cg.TemplateArguments,
args: TemplateArgsType,
) -> MockObj:
var = cg.new_Pvariable(action_id, template_arg)
await cg.register_parented(var, config[CONF_TRANSMITTER_ID])
template_ = await cg.templatable(config[CONF_VALUE], args, cg.bool_)
cg.add(var.set_value(template_))
return var
async def to_code(config: ConfigType) -> None:
@@ -1,17 +0,0 @@
#pragma once
#include "esphome/components/remote_transmitter/remote_transmitter.h"
#include "esphome/core/automation.h"
#include "esphome/core/component.h"
#include "esphome/core/helpers.h"
namespace esphome::remote_transmitter {
template<typename... Ts>
class DigitalWriteAction final : public Action<Ts...>, public Parented<RemoteTransmitterComponent> {
public:
TEMPLATABLE_VALUE(bool, value)
void play(const Ts &...x) override { this->parent_->digital_write(this->value_.value(x...)); }
};
} // namespace esphome::remote_transmitter
@@ -275,3 +275,6 @@ button:
- remote_transmitter.digital_write: true
- remote_transmitter.digital_write:
value: false
- remote_transmitter.digital_write:
transmitter_id: xmitr
value: !lambda return id(remote_transmitter_test_number).state > 127;