diff --git a/esphome/components/esp32_ble_server/__init__.py b/esphome/components/esp32_ble_server/__init__.py index 793db92ded..9d12ca1f50 100644 --- a/esphome/components/esp32_ble_server/__init__.py +++ b/esphome/components/esp32_ble_server/__init__.py @@ -7,7 +7,7 @@ from esphome.const import ( CONF_UUID, CONF_SERVICES, CONF_VALUE, - CONF_MAX_LENGTH + CONF_MAX_LENGTH, ) from esphome.components import esp32_ble from esphome.core import CORE @@ -65,7 +65,7 @@ PROPERTIES_SCHEMA = cv.All( upper=True, ) ), - cv.Length(min=1) + cv.Length(min=1), ) UUID_SCHEMA = cv.Any(cv.All(cv.string, validate_uuid), cv.hex_uint32_t) @@ -164,7 +164,7 @@ def parse_value(value): def calculate_num_handles(service_config): total = 1 for char_conf in service_config[CONF_CHARACTERISTICS]: - total += 2 # One for the char_conf itself and one for the value + total += 2 # One for the char_conf itself and one for the value for _ in char_conf[CONF_DESCRIPTORS]: total += 1 return total @@ -202,7 +202,7 @@ async def to_code(config): char_conf[CONF_ID], service_var.create_characteristic( parse_uuid(char_conf[CONF_UUID]), - parse_properties(char_conf[CONF_PROPERTIES]) + parse_properties(char_conf[CONF_PROPERTIES]), ), ) if CONF_ON_WRITE in char_conf: @@ -233,6 +233,7 @@ async def to_code(config): if CORE.using_esp_idf: add_idf_sdkconfig_option("CONFIG_BT_ENABLED", True) + @automation.register_action( "ble_server.characteristic_set_value", BLECharacteristicSetValueAction, diff --git a/esphome/components/esp32_ble_server/ble_server.cpp b/esphome/components/esp32_ble_server/ble_server.cpp index da6c85447e..7e4575999f 100644 --- a/esphome/components/esp32_ble_server/ble_server.cpp +++ b/esphome/components/esp32_ble_server/ble_server.cpp @@ -63,7 +63,7 @@ void BLEServer::loop() { // Remove the services that have been started if (index_to_remove > 0) { this->services_to_start_.erase(this->services_to_start_.begin(), - this->services_to_start_.begin() + index_to_remove - 1); + this->services_to_start_.begin() + index_to_remove - 1); } } break; @@ -86,7 +86,7 @@ void BLEServer::loop() { } if (this->device_information_service_ == nullptr) { this->device_information_service_ = - this->create_service(ESPBTUUID::from_uint16(DEVICE_INFORMATION_SERVICE_UUID), false, 7); + this->create_service(ESPBTUUID::from_uint16(DEVICE_INFORMATION_SERVICE_UUID), false, 7); this->create_device_characteristics_(); } this->state_ = STARTING_SERVICE; @@ -152,7 +152,7 @@ BLEService *BLEServer::create_service(ESPBTUUID uuid, bool advertise, uint16_t n return nullptr; } BLEService *service = - new BLEService(uuid, num_handles, inst_id, advertise); // NOLINT(cppcoreguidelines-owning-memory) + new BLEService(uuid, num_handles, inst_id, advertise); // NOLINT(cppcoreguidelines-owning-memory) this->services_.emplace(BLEServer::get_service_key(uuid, inst_id), service); if (this->parent_->is_active() && this->registered_) { service->do_create(this); diff --git a/esphome/components/esp32_ble_server/ble_server.h b/esphome/components/esp32_ble_server/ble_server.h index cfe6b97b1f..8ba9e37bd6 100644 --- a/esphome/components/esp32_ble_server/ble_server.h +++ b/esphome/components/esp32_ble_server/ble_server.h @@ -31,13 +31,13 @@ class BLEServerAutomationInterface { static Trigger *create_on_write_trigger(BLECharacteristic *characteristic); template class BLECharacteristicSetValueAction : public Action { - public: - BLECharacteristicSetValueAction(BLECharacteristic *characteristic) : parent_(characteristic) {} - TEMPLATABLE_VALUE(std::string, value) - void play(Ts... x) override { this->parent_->set_value(this->value_.value(x...)); } + public: + BLECharacteristicSetValueAction(BLECharacteristic *characteristic) : parent_(characteristic) {} + TEMPLATABLE_VALUE(std::string, value) + void play(Ts... x) override { this->parent_->set_value(this->value_.value(x...)); } - protected: - BLECharacteristic *parent_; + protected: + BLECharacteristic *parent_; }; }; diff --git a/esphome/components/esp32_ble_server/ble_service.cpp b/esphome/components/esp32_ble_server/ble_service.cpp index 7ee434440c..5d735ba4cc 100644 --- a/esphome/components/esp32_ble_server/ble_service.cpp +++ b/esphome/components/esp32_ble_server/ble_service.cpp @@ -63,7 +63,7 @@ void BLEService::emit_client_connect(const uint16_t conn_id) { this->on_client_connect_(conn_id); } -void emit_client_disconnect(const uint16_t conn_id) { +void BLEService::emit_client_disconnect(const uint16_t conn_id) { if (this->on_client_disconnect_ && this->is_running()) this->on_client_disconnect_(conn_id); }