mirror of
https://github.com/esphome/esphome.git
synced 2026-09-27 23:10:21 +00:00
[sx126x] Use register_apply_action for the five mode and calibration actions (#19635)
This commit is contained in:
@@ -131,24 +131,9 @@ SHAPING = {
|
||||
"NONE": SX126xPulseShape.NO_FILTER,
|
||||
}
|
||||
|
||||
RunImageCalAction = sx126x_ns.class_(
|
||||
"RunImageCalAction", automation.Action, cg.Parented.template(SX126x)
|
||||
)
|
||||
SendPacketAction = sx126x_ns.class_(
|
||||
"SendPacketAction", automation.Action, cg.Parented.template(SX126x)
|
||||
)
|
||||
SetModeTxAction = sx126x_ns.class_(
|
||||
"SetModeTxAction", automation.Action, cg.Parented.template(SX126x)
|
||||
)
|
||||
SetModeRxAction = sx126x_ns.class_(
|
||||
"SetModeRxAction", automation.Action, cg.Parented.template(SX126x)
|
||||
)
|
||||
SetModeSleepAction = sx126x_ns.class_(
|
||||
"SetModeSleepAction", automation.Action, cg.Parented.template(SX126x)
|
||||
)
|
||||
SetModeStandbyAction = sx126x_ns.class_(
|
||||
"SetModeStandbyAction", automation.Action, cg.Parented.template(SX126x)
|
||||
)
|
||||
|
||||
|
||||
def validate_raw_data(value: Any) -> bytes | list[int]:
|
||||
@@ -302,37 +287,15 @@ NO_ARGS_ACTION_SCHEMA = automation.maybe_simple_id(
|
||||
)
|
||||
|
||||
|
||||
automation.register_parented_action(
|
||||
"sx126x.run_image_cal",
|
||||
RunImageCalAction,
|
||||
NO_ARGS_ACTION_SCHEMA,
|
||||
synchronous=True,
|
||||
)
|
||||
|
||||
|
||||
automation.register_parented_action(
|
||||
"sx126x.set_mode_tx",
|
||||
SetModeTxAction,
|
||||
NO_ARGS_ACTION_SCHEMA,
|
||||
synchronous=True,
|
||||
)
|
||||
|
||||
|
||||
automation.register_parented_action(
|
||||
"sx126x.set_mode_rx",
|
||||
SetModeRxAction,
|
||||
NO_ARGS_ACTION_SCHEMA,
|
||||
synchronous=True,
|
||||
)
|
||||
|
||||
|
||||
automation.register_parented_action(
|
||||
"sx126x.set_mode_standby",
|
||||
SetModeStandbyAction,
|
||||
NO_ARGS_ACTION_SCHEMA,
|
||||
synchronous=True,
|
||||
)
|
||||
|
||||
for _name, _call in (
|
||||
("sx126x.run_image_cal", "run_image_cal()"),
|
||||
("sx126x.set_mode_tx", "set_mode_tx()"),
|
||||
("sx126x.set_mode_rx", "set_mode_rx()"),
|
||||
("sx126x.set_mode_standby", "set_mode_standby(sx126x::STDBY_XOSC)"),
|
||||
):
|
||||
automation.register_apply_action(
|
||||
_name, NO_ARGS_ACTION_SCHEMA, automation.ApplyCall(_call)
|
||||
)
|
||||
|
||||
SET_MODE_SLEEP_ACTION_SCHEMA = automation.maybe_simple_id(
|
||||
{
|
||||
@@ -341,24 +304,11 @@ SET_MODE_SLEEP_ACTION_SCHEMA = automation.maybe_simple_id(
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
automation.register_apply_action(
|
||||
"sx126x.set_mode_sleep",
|
||||
SetModeSleepAction,
|
||||
SET_MODE_SLEEP_ACTION_SCHEMA,
|
||||
synchronous=True,
|
||||
automation.ApplyField(CONF_COLD, "set_mode_sleep", cg.bool_),
|
||||
)
|
||||
async def set_mode_sleep_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_ID])
|
||||
template_ = await cg.templatable(config[CONF_COLD], args, bool)
|
||||
cg.add(var.set_cold(template_))
|
||||
return var
|
||||
|
||||
|
||||
SEND_PACKET_ACTION_SCHEMA = cv.maybe_simple_value(
|
||||
|
||||
@@ -6,11 +6,6 @@
|
||||
|
||||
namespace esphome::sx126x {
|
||||
|
||||
template<typename... Ts> class RunImageCalAction final : public Action<Ts...>, public Parented<SX126x> {
|
||||
public:
|
||||
void play(const Ts &...x) override { this->parent_->run_image_cal(); }
|
||||
};
|
||||
|
||||
template<typename... Ts> class SendPacketAction final : public Action<Ts...>, public Parented<SX126x> {
|
||||
public:
|
||||
void set_data_template(std::vector<uint8_t> (*func)(Ts...)) {
|
||||
@@ -43,25 +38,4 @@ template<typename... Ts> class SendPacketAction final : public Action<Ts...>, pu
|
||||
} data_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class SetModeTxAction final : public Action<Ts...>, public Parented<SX126x> {
|
||||
public:
|
||||
void play(const Ts &...x) override { this->parent_->set_mode_tx(); }
|
||||
};
|
||||
|
||||
template<typename... Ts> class SetModeRxAction final : public Action<Ts...>, public Parented<SX126x> {
|
||||
public:
|
||||
void play(const Ts &...x) override { this->parent_->set_mode_rx(); }
|
||||
};
|
||||
|
||||
template<typename... Ts> class SetModeSleepAction final : public Action<Ts...>, public Parented<SX126x> {
|
||||
public:
|
||||
TEMPLATABLE_VALUE(bool, cold)
|
||||
void play(const Ts &...x) override { this->parent_->set_mode_sleep(this->cold_.value(x...)); }
|
||||
};
|
||||
|
||||
template<typename... Ts> class SetModeStandbyAction final : public Action<Ts...>, public Parented<SX126x> {
|
||||
public:
|
||||
void play(const Ts &...x) override { this->parent_->set_mode_standby(STDBY_XOSC); }
|
||||
};
|
||||
|
||||
} // namespace esphome::sx126x
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
button:
|
||||
- platform: template
|
||||
name: SX126x Mode Actions
|
||||
on_press:
|
||||
- sx126x.set_mode_tx
|
||||
- sx126x.set_mode_sleep:
|
||||
cold: true
|
||||
- sx126x.set_mode_sleep:
|
||||
cold: !lambda return id(sx126x_my_number).state > 1;
|
||||
@@ -0,0 +1,13 @@
|
||||
substitutions:
|
||||
clk_pin: GPIO0
|
||||
mosi_pin: GPIO15
|
||||
miso_pin: GPIO16
|
||||
cs_pin: GPIO1
|
||||
rst_pin: GPIO2
|
||||
busy_pin: GPIO4
|
||||
dio1_pin: GPIO3
|
||||
|
||||
packages:
|
||||
spi: !include ../../test_build_components/common/spi/esp8266-ard.yaml
|
||||
sx126x: !include common.yaml
|
||||
actions: !include common-actions.yaml
|
||||
Reference in New Issue
Block a user