mirror of
https://github.com/esphome/esphome.git
synced 2024-11-24 16:08:10 +01:00
Fix linting issues
This commit is contained in:
parent
03ff9fca0b
commit
30335eaf93
3 changed files with 9 additions and 9 deletions
|
@ -180,7 +180,7 @@ void BLECharacteristic::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt
|
|||
if (!param->read.need_rsp)
|
||||
break; // For some reason you can request a read but not want a response
|
||||
|
||||
this->EventEmitter<BLECharacteristicEvt::EmptyEvt>::emit(BLECharacteristicEvt::EmptyEvt::ON_READ);
|
||||
this->EventEmitter<BLECharacteristicEvt::EmptyEvt>::emit_(BLECharacteristicEvt::EmptyEvt::ON_READ);
|
||||
|
||||
uint16_t max_offset = 22;
|
||||
|
||||
|
@ -248,7 +248,7 @@ void BLECharacteristic::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt
|
|||
}
|
||||
|
||||
if (!param->write.is_prep) {
|
||||
this->EventEmitter<BLECharacteristicEvt::VectorEvt, std::vector<uint8_t>>::emit(
|
||||
this->EventEmitter<BLECharacteristicEvt::VectorEvt, std::vector<uint8_t>>::emit_(
|
||||
BLECharacteristicEvt::VectorEvt::ON_WRITE, this->value_);
|
||||
}
|
||||
|
||||
|
@ -260,7 +260,7 @@ void BLECharacteristic::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt
|
|||
break;
|
||||
this->write_event_ = false;
|
||||
if (param->exec_write.exec_write_flag == ESP_GATT_PREP_WRITE_EXEC) {
|
||||
this->EventEmitter<BLECharacteristicEvt::VectorEvt, std::vector<uint8_t>>::emit(
|
||||
this->EventEmitter<BLECharacteristicEvt::VectorEvt, std::vector<uint8_t>>::emit_(
|
||||
BLECharacteristicEvt::VectorEvt::ON_WRITE, this->value_);
|
||||
}
|
||||
esp_err_t err =
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace esphome {
|
|||
|
||||
static const char *const TAG = "event_emitter";
|
||||
|
||||
void RaiseEventEmitterFullError() {
|
||||
void raise_event_emitter_full_error() {
|
||||
ESP_LOGE(TAG, "EventEmitter has reached the maximum number of listeners for event");
|
||||
ESP_LOGW(TAG, "Removing listener to make space for new listener");
|
||||
}
|
||||
|
|
|
@ -9,14 +9,14 @@
|
|||
namespace esphome {
|
||||
|
||||
using EventEmitterListenerID = uint32_t;
|
||||
void RaiseEventEmitterFullError();
|
||||
void raise_event_emitter_full_error();
|
||||
|
||||
// EventEmitter class that can emit events with a specific name (it is highly recommended to use an enum class for this)
|
||||
// and a list of arguments. Supports multiple listeners for each event.
|
||||
template<typename EvtType, typename... Args> class EventEmitter {
|
||||
public:
|
||||
EventEmitterListenerID on(EvtType event, std::function<void(Args...)> listener) {
|
||||
EventEmitterListenerID listener_id = get_next_id(event);
|
||||
EventEmitterListenerID listener_id = get_next_id_(event);
|
||||
listeners_[event][listener_id] = listener;
|
||||
return listener_id;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ template<typename EvtType, typename... Args> class EventEmitter {
|
|||
}
|
||||
|
||||
protected:
|
||||
void emit(EvtType event, Args... args) {
|
||||
void emit_(EvtType event, Args... args) {
|
||||
if (listeners_.count(event) == 0)
|
||||
return;
|
||||
for (const auto &listener : listeners_[event]) {
|
||||
|
@ -36,11 +36,11 @@ template<typename EvtType, typename... Args> class EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
EventEmitterListenerID get_next_id(EvtType event) {
|
||||
EventEmitterListenerID get_next_id_(EvtType event) {
|
||||
// Check if the map is full
|
||||
if (listeners_[event].size() == std::numeric_limits<EventEmitterListenerID>::max()) {
|
||||
// Raise an error if the map is full
|
||||
RaiseEventEmitterFullError();
|
||||
raise_event_emitter_full_error();
|
||||
off(event, 0);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue