mirror of
https://github.com/esphome/esphome.git
synced 2025-01-01 02:11:44 +01:00
Fix linting issues
This commit is contained in:
parent
63e5b31fe5
commit
3fa3f197aa
2 changed files with 19 additions and 15 deletions
|
@ -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);
|
||||
|
|
|
@ -28,16 +28,22 @@ enum BLECharacteristicSetValueActionEvt {
|
|||
};
|
||||
|
||||
// Class to make sure only one BLECharacteristicSetValueAction is active at a time
|
||||
class BLECharacteristicSetValueActionManager : public EventEmitter<BLECharacteristicSetValueActionEvt, BLECharacteristic *> {
|
||||
class BLECharacteristicSetValueActionManager
|
||||
: public EventEmitter<BLECharacteristicSetValueActionEvt, BLECharacteristic *> {
|
||||
public:
|
||||
// Singleton pattern
|
||||
static BLECharacteristicSetValueActionManager *get_instance() {
|
||||
static BLECharacteristicSetValueActionManager instance;
|
||||
return &instance;
|
||||
}
|
||||
void set_listener(BLECharacteristic *characteristic, EventEmitterListenerID listener_id, std::function<void()> 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<void()> 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<BLECharacteristic *, std::pair<EventEmitterListenerID, EventEmitterListenerID>> listeners_;
|
||||
|
@ -61,9 +67,7 @@ template<typename... Ts> class BLECharacteristicSetValueAction : public Action<T
|
|||
});
|
||||
// Set the listener in the global manager so only one BLECharacteristicSetValueAction is set for each characteristic
|
||||
BLECharacteristicSetValueActionManager::get_instance()->set_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:
|
||||
|
|
Loading…
Reference in a new issue