[zephyr_ble_server] Use register_apply_action for ble_server.numeric_comparison_reply (#19692)

This commit is contained in:
J. Nick Koston
2026-09-25 20:31:41 -04:00
committed by GitHub
parent c0c1643efe
commit d1dd4e53ce
2 changed files with 3 additions and 34 deletions
@@ -3,8 +3,7 @@ import esphome.codegen as cg
from esphome.components.zephyr import zephyr_add_prj_conf
import esphome.config_validation as cv
from esphome.const import CONF_ID, Framework
from esphome.core import CORE, ID
from esphome.cpp_generator import MockObj, TemplateArgsType
from esphome.core import CORE
from esphome.types import ConfigType
zephyr_ble_server_ns = cg.esphome_ns.namespace("zephyr_ble_server")
@@ -49,10 +48,6 @@ async def to_code(config: ConfigType) -> None:
await automation.build_callback_automations(var, config, _CALLBACK_AUTOMATIONS)
BLENumericComparisonReplyAction = zephyr_ble_server_ns.class_(
"BLENumericComparisonReplyAction", automation.Action
)
BLE_NUMERIC_COMPARISON_REPLY_ACTION_SCHEMA = cv.Schema(
{
cv.GenerateID(CONF_ID): cv.use_id(BLEServer),
@@ -61,22 +56,8 @@ BLE_NUMERIC_COMPARISON_REPLY_ACTION_SCHEMA = cv.Schema(
)
@automation.register_action(
automation.register_apply_action(
"ble_server.numeric_comparison_reply",
BLENumericComparisonReplyAction,
BLE_NUMERIC_COMPARISON_REPLY_ACTION_SCHEMA,
synchronous=True,
automation.ApplyField(CONF_ACCEPT, "numeric_comparison_reply", cg.bool_),
)
async def numeric_comparison_reply_to_code(
config: ConfigType,
action_id: ID,
template_arg: cg.TemplateArguments,
args: TemplateArgsType,
) -> MockObj:
parent = await cg.get_variable(config[CONF_ID])
var = cg.new_Pvariable(action_id, template_arg, parent)
templ = await cg.templatable(config[CONF_ACCEPT], args, cg.bool_)
cg.add(var.set_accept(templ))
return var
@@ -21,17 +21,5 @@ class BLEServer final : public Component {
CallbackManager<void(uint32_t)> passkey_cb_;
};
template<typename... Ts> class BLENumericComparisonReplyAction final : public Action<Ts...> {
public:
explicit BLENumericComparisonReplyAction(BLEServer *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(bool, accept)
void play(const Ts &...x) override { this->parent_->numeric_comparison_reply(this->accept_.value(x...)); }
protected:
BLEServer *parent_;
};
} // namespace esphome::zephyr_ble_server
#endif