[sx127x] Use register_apply_action for the five mode and calibration actions (#19636)

This commit is contained in:
J. Nick Koston
2026-09-25 13:15:13 -04:00
committed by GitHub
parent d6831c8c75
commit bdb492c196
2 changed files with 10 additions and 78 deletions
+10 -53
View File
@@ -120,24 +120,9 @@ SHAPING = {
"NONE": SX127xPaRamp.SHAPING_NONE,
}
RunImageCalAction = sx127x_ns.class_(
"RunImageCalAction", automation.Action, cg.Parented.template(SX127x)
)
SendPacketAction = sx127x_ns.class_(
"SendPacketAction", automation.Action, cg.Parented.template(SX127x)
)
SetModeTxAction = sx127x_ns.class_(
"SetModeTxAction", automation.Action, cg.Parented.template(SX127x)
)
SetModeRxAction = sx127x_ns.class_(
"SetModeRxAction", automation.Action, cg.Parented.template(SX127x)
)
SetModeSleepAction = sx127x_ns.class_(
"SetModeSleepAction", automation.Action, cg.Parented.template(SX127x)
)
SetModeStandbyAction = sx127x_ns.class_(
"SetModeStandbyAction", automation.Action, cg.Parented.template(SX127x)
)
def validate_raw_data(value: Any) -> bytes | list[int]:
@@ -286,44 +271,16 @@ NO_ARGS_ACTION_SCHEMA = automation.maybe_simple_id(
)
automation.register_parented_action(
"sx127x.run_image_cal",
RunImageCalAction,
NO_ARGS_ACTION_SCHEMA,
synchronous=True,
)
automation.register_parented_action(
"sx127x.set_mode_tx",
SetModeTxAction,
NO_ARGS_ACTION_SCHEMA,
synchronous=True,
)
automation.register_parented_action(
"sx127x.set_mode_rx",
SetModeRxAction,
NO_ARGS_ACTION_SCHEMA,
synchronous=True,
)
automation.register_parented_action(
"sx127x.set_mode_sleep",
SetModeSleepAction,
NO_ARGS_ACTION_SCHEMA,
synchronous=True,
)
automation.register_parented_action(
"sx127x.set_mode_standby",
SetModeStandbyAction,
NO_ARGS_ACTION_SCHEMA,
synchronous=True,
)
for _name, _call in (
("sx127x.run_image_cal", "run_image_cal()"),
("sx127x.set_mode_tx", "set_mode_tx()"),
("sx127x.set_mode_rx", "set_mode_rx()"),
("sx127x.set_mode_sleep", "set_mode_sleep()"),
("sx127x.set_mode_standby", "set_mode_standby()"),
):
automation.register_apply_action(
_name, NO_ARGS_ACTION_SCHEMA, automation.ApplyCall(_call)
)
SEND_PACKET_ACTION_SCHEMA = cv.maybe_simple_value(
-25
View File
@@ -6,11 +6,6 @@
namespace esphome::sx127x {
template<typename... Ts> class RunImageCalAction final : public Action<Ts...>, public Parented<SX127x> {
public:
void play(const Ts &...x) override { this->parent_->run_image_cal(); }
};
template<typename... Ts> class SendPacketAction final : public Action<Ts...>, public Parented<SX127x> {
public:
void set_data_template(std::vector<uint8_t> (*func)(Ts...)) {
@@ -43,24 +38,4 @@ template<typename... Ts> class SendPacketAction final : public Action<Ts...>, pu
} data_;
};
template<typename... Ts> class SetModeTxAction final : public Action<Ts...>, public Parented<SX127x> {
public:
void play(const Ts &...x) override { this->parent_->set_mode_tx(); }
};
template<typename... Ts> class SetModeRxAction final : public Action<Ts...>, public Parented<SX127x> {
public:
void play(const Ts &...x) override { this->parent_->set_mode_rx(); }
};
template<typename... Ts> class SetModeSleepAction final : public Action<Ts...>, public Parented<SX127x> {
public:
void play(const Ts &...x) override { this->parent_->set_mode_sleep(); }
};
template<typename... Ts> class SetModeStandbyAction final : public Action<Ts...>, public Parented<SX127x> {
public:
void play(const Ts &...x) override { this->parent_->set_mode_standby(); }
};
} // namespace esphome::sx127x