[esp32_ble] Build ble.enabled, ble.enable and ble.disable with the apply helpers (#20839)

This commit is contained in:
J. Nick Koston
2026-10-17 06:38:25 -10:00
committed by GitHub
parent d08c845c65
commit 905267a9c3
2 changed files with 6 additions and 44 deletions
+6 -23
View File
@@ -296,10 +296,6 @@ NO_BLUETOOTH_VARIANTS = [const.VARIANT_ESP32S2]
esp32_ble_ns = cg.esphome_ns.namespace("esp32_ble")
ESP32BLE = esp32_ble_ns.class_("ESP32BLE", cg.Component)
BLEEnabledCondition = esp32_ble_ns.class_("BLEEnabledCondition", automation.Condition)
BLEEnableAction = esp32_ble_ns.class_("BLEEnableAction", automation.Action)
BLEDisableAction = esp32_ble_ns.class_("BLEDisableAction", automation.Action)
IoCapability = esp32_ble_ns.enum("IoCapability")
IO_CAPABILITY = {
"none": IoCapability.IO_CAP_NONE,
@@ -613,27 +609,14 @@ async def to_code(config: ConfigType) -> None:
cg.add_define("USE_ESP32_BLE_UUID")
automation.register_bare_condition(
"ble.enabled",
BLEEnabledCondition,
cv.Schema({}),
)
BLE_AUTOMATION_SCHEMA = cv.Schema({cv.GenerateID(): cv.use_id(ESP32BLE)})
automation.register_apply_condition("ble.enabled", BLE_AUTOMATION_SCHEMA, "is_active()")
automation.register_bare_action(
"ble.enable",
BLEEnableAction,
cv.Schema({}),
synchronous=True,
)
automation.register_bare_action(
"ble.disable",
BLEDisableAction,
cv.Schema({}),
synchronous=True,
)
for _name, _call in (("ble.enable", "enable()"), ("ble.disable", "disable()")):
automation.register_apply_action(
_name, BLE_AUTOMATION_SCHEMA, automation.ApplyCall(_call)
)
# ble_advertising.cpp is fully #ifdef'd on USE_ESP32_BLE_ADVERTISING, set
-21
View File
@@ -259,27 +259,6 @@ class ESP32BLE final : public Component {
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
extern ESP32BLE *global_ble;
template<typename... Ts> class BLEEnabledCondition final : public Condition<Ts...> {
public:
bool check(const Ts &...x) override { return global_ble != nullptr && global_ble->is_active(); }
};
template<typename... Ts> class BLEEnableAction final : public Action<Ts...> {
public:
void play(const Ts &...x) override {
if (global_ble != nullptr)
global_ble->enable();
}
};
template<typename... Ts> class BLEDisableAction final : public Action<Ts...> {
public:
void play(const Ts &...x) override {
if (global_ble != nullptr)
global_ble->disable();
}
};
} // namespace esphome::esp32_ble
#endif