From 3fa3f197aa84704bf8aaf03963a649fc7b71e247 Mon Sep 17 00:00:00 2001 From: Rapsssito Date: Sat, 13 Jul 2024 13:01:18 +0200 Subject: [PATCH] Fix linting issues --- .../ble_server_automations.cpp | 16 ++++++++-------- .../esp32_ble_server/ble_server_automations.h | 18 +++++++++++------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/esphome/components/esp32_ble_server/ble_server_automations.cpp b/esphome/components/esp32_ble_server/ble_server_automations.cpp index 66a27660cb..010e53df75 100644 --- a/esphome/components/esp32_ble_server/ble_server_automations.cpp +++ b/esphome/components/esp32_ble_server/ble_server_automations.cpp @@ -34,14 +34,14 @@ void BLECharacteristicSetValueActionManager::set_listener(BLECharacteristic *cha this->off(BLECharacteristicSetValueActionEvt::PRE_NOTIFY, old_pre_notify_listener_id); } // Create a new listener for the pre-notify event - EventEmitterListenerID pre_notify_listener_id = this->on( - BLECharacteristicSetValueActionEvt::PRE_NOTIFY, - [pre_notify_listener, characteristic](const BLECharacteristic *evt_characteristic) { - // Only call the pre-notify listener if the characteristic is the one we are interested in - if (characteristic == evt_characteristic) { - pre_notify_listener(); - } - } + EventEmitterListenerID pre_notify_listener_id = + this->on(BLECharacteristicSetValueActionEvt::PRE_NOTIFY, + [pre_notify_listener, characteristic](const BLECharacteristic *evt_characteristic) { + // Only call the pre-notify listener if the characteristic is the one we are interested in + if (characteristic == evt_characteristic) { + pre_notify_listener(); + } + } ); // Save the pair listener_id, pre_notify_listener_id to the map this->listeners_[characteristic] = std::make_pair(listener_id, pre_notify_listener_id); diff --git a/esphome/components/esp32_ble_server/ble_server_automations.h b/esphome/components/esp32_ble_server/ble_server_automations.h index 7d4ccaf2b8..d293621426 100644 --- a/esphome/components/esp32_ble_server/ble_server_automations.h +++ b/esphome/components/esp32_ble_server/ble_server_automations.h @@ -28,16 +28,22 @@ enum BLECharacteristicSetValueActionEvt { }; // Class to make sure only one BLECharacteristicSetValueAction is active at a time -class BLECharacteristicSetValueActionManager : public EventEmitter { +class BLECharacteristicSetValueActionManager + : public EventEmitter { public: // Singleton pattern static BLECharacteristicSetValueActionManager *get_instance() { static BLECharacteristicSetValueActionManager instance; return &instance; } - void set_listener(BLECharacteristic *characteristic, EventEmitterListenerID listener_id, std::function pre_notify_listener); - EventEmitterListenerID get_listener(BLECharacteristic *characteristic) { return this->listeners_[characteristic].first; } - void emit_pre_notify(BLECharacteristic *characteristic) { this->emit_(BLECharacteristicSetValueActionEvt::PRE_NOTIFY, characteristic); } + void set_listener(BLECharacteristic *characteristic, EventEmitterListenerID listener_id, + std::function pre_notify_listener); + EventEmitterListenerID get_listener(BLECharacteristic *characteristic) { + return this->listeners_[characteristic].first; + } + void emit_pre_notify(BLECharacteristic *characteristic) { + this->emit_(BLECharacteristicSetValueActionEvt::PRE_NOTIFY, characteristic); + } private: std::unordered_map> listeners_; @@ -61,9 +67,7 @@ template class BLECharacteristicSetValueAction : public Actionset_listener( - this->parent_, this->listener_id_, [this, x...]() { - this->parent_->set_value(this->value_.value(x...)); - }); + this->parent_, this->listener_id_, [this, x...]() { this->parent_->set_value(this->value_.value(x...)); }); } protected: