mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 17:27:59 +01:00
Fix linting issues
This commit is contained in:
parent
9c64b377c8
commit
6bb7a10deb
7 changed files with 41 additions and 34 deletions
|
@ -35,7 +35,7 @@ CONF_DESCRIPTORS = "descriptors"
|
|||
CONF_STRING_ENCODING = "string_encoding"
|
||||
CONF_DESCRIPTION = "description"
|
||||
|
||||
CONF_CHAR_VALUE_ACTION_ID_ = "characteristic_value_action_id_"
|
||||
CONF_CHAR_VALUE_ACTION_ID_ = "char_value_action_id_"
|
||||
CONF_VALUE_BUFFER_ = "value_buffer_"
|
||||
CONF_CUD_ID_ = "cud_id_"
|
||||
CONF_CUD_VALUE_BUFFER_ = "cud_value_buffer_"
|
||||
|
@ -149,7 +149,12 @@ def create_notify_cccd(char_config):
|
|||
# If the CCCD descriptor is already present, return the config
|
||||
for desc in char_config[CONF_DESCRIPTORS]:
|
||||
if desc[CONF_UUID] == 0x2902:
|
||||
return
|
||||
# Check if the WRITE property is set
|
||||
if not desc[CONF_WRITE]:
|
||||
raise cv.Invalid(
|
||||
f"Characteristic {char_config[CONF_UUID]} has notify actions, but the CCCD descriptor does not have the {CONF_WRITE} property set"
|
||||
)
|
||||
return char_config
|
||||
# Manually add the CCCD descriptor
|
||||
char_config[CONF_DESCRIPTORS].append(
|
||||
{
|
||||
|
|
|
@ -55,8 +55,8 @@ void BLECharacteristic::notify() {
|
|||
ESP_LOGW(TAG, "INDICATE acknowledgment is not yet supported (i.e. it works as a NOTIFY)");
|
||||
require_ack = false;
|
||||
}
|
||||
esp_err_t err = esp_ble_gatts_send_indicate(this->service_->get_server()->get_gatts_if(), client,
|
||||
this->handle_, length, this->value_.data(), require_ack);
|
||||
esp_err_t err = esp_ble_gatts_send_indicate(this->service_->get_server()->get_gatts_if(), client, this->handle_,
|
||||
length, this->value_.data(), require_ack);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "esp_ble_gatts_send_indicate failed %d", err);
|
||||
return;
|
||||
|
@ -67,9 +67,7 @@ void BLECharacteristic::notify() {
|
|||
void BLECharacteristic::add_descriptor(BLEDescriptor *descriptor) {
|
||||
// If the descriptor is the CCCD descriptor, listen to its write event to know if the client wants to be notified
|
||||
if (descriptor->get_uuid() == ESPBTUUID::from_uint16(ESP_GATT_UUID_CHAR_CLIENT_CONFIG)) {
|
||||
descriptor->on(
|
||||
BLEDescriptorEvt::VectorEvt::ON_WRITE,
|
||||
[this](const std::vector<uint8_t> &value, uint16_t conn_id) {
|
||||
descriptor->on(BLEDescriptorEvt::VectorEvt::ON_WRITE, [this](const std::vector<uint8_t> &value, uint16_t conn_id) {
|
||||
if (value.size() != 2)
|
||||
return;
|
||||
uint16_t cccd = encode_uint16(value[1], value[0]);
|
||||
|
@ -80,8 +78,7 @@ void BLECharacteristic::add_descriptor(BLEDescriptor *descriptor) {
|
|||
} else {
|
||||
this->clients_to_notify_.erase(conn_id);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
this->descriptors_.push_back(descriptor);
|
||||
}
|
||||
|
@ -204,8 +201,8 @@ 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, uint16_t>::emit_(
|
||||
BLECharacteristicEvt::EmptyEvt::ON_READ, param->read.conn_id);
|
||||
this->EventEmitter<BLECharacteristicEvt::EmptyEvt, uint16_t>::emit_(BLECharacteristicEvt::EmptyEvt::ON_READ,
|
||||
param->read.conn_id);
|
||||
|
||||
uint16_t max_offset = 22;
|
||||
|
||||
|
|
|
@ -72,11 +72,9 @@ void BLEDescriptor::gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_
|
|||
break;
|
||||
this->value_.attr_len = param->write.len;
|
||||
memcpy(this->value_.attr_value, param->write.value, param->write.len);
|
||||
this->emit_(
|
||||
BLEDescriptorEvt::VectorEvt::ON_WRITE,
|
||||
this->emit_(BLEDescriptorEvt::VectorEvt::ON_WRITE,
|
||||
std::vector<uint8_t>(param->write.value, param->write.value + param->write.len),
|
||||
param->write.conn_id
|
||||
);
|
||||
param->write.conn_id);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -34,8 +34,11 @@ enum EmptyEvt {
|
|||
};
|
||||
} // namespace BLEServerEvt
|
||||
|
||||
class BLEServer : public Component, public GATTsEventHandler, public BLEStatusEventHandler,
|
||||
public Parented<ESP32BLE>, public EventEmitter<BLEServerEvt::EmptyEvt, uint16_t> {
|
||||
class BLEServer : public Component,
|
||||
public GATTsEventHandler,
|
||||
public BLEStatusEventHandler,
|
||||
public Parented<ESP32BLE>,
|
||||
public EventEmitter<BLEServerEvt::EmptyEvt, uint16_t> {
|
||||
public:
|
||||
void setup() override;
|
||||
void loop() override;
|
||||
|
|
|
@ -9,7 +9,8 @@ namespace esp32_ble_server_automations {
|
|||
|
||||
using namespace esp32_ble;
|
||||
|
||||
Trigger<std::vector<uint8_t>, uint16_t> *BLETriggers::create_characteristic_on_write_trigger(BLECharacteristic *characteristic) {
|
||||
Trigger<std::vector<uint8_t>, uint16_t> *BLETriggers::create_characteristic_on_write_trigger(
|
||||
BLECharacteristic *characteristic) {
|
||||
Trigger<std::vector<uint8_t>, uint16_t> *on_write_trigger = // NOLINT(cppcoreguidelines-owning-memory)
|
||||
new Trigger<std::vector<uint8_t>, uint16_t>();
|
||||
characteristic->EventEmitter<BLECharacteristicEvt::VectorEvt, std::vector<uint8_t>, uint16_t>::on(
|
||||
|
@ -29,13 +30,15 @@ Trigger<std::vector<uint8_t>, uint16_t> *BLETriggers::create_descriptor_on_write
|
|||
|
||||
Trigger<uint16_t> *BLETriggers::create_server_on_connect_trigger(BLEServer *server) {
|
||||
Trigger<uint16_t> *on_connect_trigger = new Trigger<uint16_t>(); // NOLINT(cppcoreguidelines-owning-memory)
|
||||
server->on(BLEServerEvt::EmptyEvt::ON_CONNECT, [on_connect_trigger](uint16_t conn_id) { on_connect_trigger->trigger(conn_id); });
|
||||
server->on(BLEServerEvt::EmptyEvt::ON_CONNECT,
|
||||
[on_connect_trigger](uint16_t conn_id) { on_connect_trigger->trigger(conn_id); });
|
||||
return on_connect_trigger;
|
||||
}
|
||||
|
||||
Trigger<uint16_t> *BLETriggers::create_server_on_disconnect_trigger(BLEServer *server) {
|
||||
Trigger<uint16_t> *on_disconnect_trigger = new Trigger<uint16_t>(); // NOLINT(cppcoreguidelines-owning-memory)
|
||||
server->on(BLEServerEvt::EmptyEvt::ON_DISCONNECT, [on_disconnect_trigger](uint16_t conn_id) { on_disconnect_trigger->trigger(conn_id); });
|
||||
server->on(BLEServerEvt::EmptyEvt::ON_DISCONNECT,
|
||||
[on_disconnect_trigger](uint16_t conn_id) { on_disconnect_trigger->trigger(conn_id); });
|
||||
return on_disconnect_trigger;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,8 @@ using namespace esp32_ble;
|
|||
|
||||
class BLETriggers {
|
||||
public:
|
||||
static Trigger<std::vector<uint8_t>, uint16_t> *create_characteristic_on_write_trigger(BLECharacteristic *characteristic);
|
||||
static Trigger<std::vector<uint8_t>, uint16_t> *create_characteristic_on_write_trigger(
|
||||
BLECharacteristic *characteristic);
|
||||
static Trigger<std::vector<uint8_t>, uint16_t> *create_descriptor_on_write_trigger(BLEDescriptor *descriptor);
|
||||
static Trigger<uint16_t> *create_server_on_connect_trigger(BLEServer *server);
|
||||
static Trigger<uint16_t> *create_server_on_disconnect_trigger(BLEServer *server);
|
||||
|
|
|
@ -41,8 +41,8 @@ void ESP32ImprovComponent::setup_characteristics() {
|
|||
this->error_->add_descriptor(error_descriptor);
|
||||
|
||||
this->rpc_ = this->service_->create_characteristic(improv::RPC_COMMAND_UUID, BLECharacteristic::PROPERTY_WRITE);
|
||||
this->rpc_->EventEmitter<BLECharacteristicEvt::VectorEvt, std::vector<uint8_t>>::on(
|
||||
BLECharacteristicEvt::VectorEvt::ON_WRITE, [this](const std::vector<uint8_t> &data) {
|
||||
this->rpc_->EventEmitter<BLECharacteristicEvt::VectorEvt, std::vector<uint8_t>, uint16_t>::on(
|
||||
BLECharacteristicEvt::VectorEvt::ON_WRITE, [this](const std::vector<uint8_t> &data, uint16_t id) {
|
||||
if (!data.empty()) {
|
||||
this->incoming_data_.insert(this->incoming_data_.end(), data.begin(), data.end());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue