Fix linting

This commit is contained in:
Rapsssito 2024-08-19 17:26:31 +02:00
parent efd3dbecfb
commit 93f30a0798
2 changed files with 20 additions and 15 deletions

View file

@ -32,8 +32,8 @@ CONF_DESCRIPTORS = "descriptors"
CONF_VALUE_ACTION_ID_ = "value_action_id_" CONF_VALUE_ACTION_ID_ = "value_action_id_"
# Core key to store the global configuration # Core key to store the global configuration
KEY_ESP32_BLE_SERVER_NOTIFY_REQUIRED = "esp32_ble_server_notify_required" _KEY_NOTIFY_REQUIRED = "esp32_ble_server_notify_required"
KEY_ESP32_BLE_SERVER_NOTIFY_PROVIDED = "esp32_ble_server_notify_provided" _KEY_NOTIFY_PROVIDED = "esp32_ble_server_notify_provided"
esp32_ble_server_ns = cg.esphome_ns.namespace("esp32_ble_server") esp32_ble_server_ns = cg.esphome_ns.namespace("esp32_ble_server")
ESPBTUUID_ns = cg.esphome_ns.namespace("esp32_ble").namespace("ESPBTUUID") ESPBTUUID_ns = cg.esphome_ns.namespace("esp32_ble").namespace("ESPBTUUID")
@ -87,24 +87,28 @@ def validate_on_write(char_config):
def validate_notify_characteristic(char_config): def validate_notify_characteristic(char_config):
if KEY_ESP32_BLE_SERVER_NOTIFY_PROVIDED not in CORE.data: if _KEY_NOTIFY_PROVIDED not in CORE.data:
CORE.data[KEY_ESP32_BLE_SERVER_NOTIFY_PROVIDED] = dict() CORE.data[_KEY_NOTIFY_PROVIDED] = {}
CORE.data[KEY_ESP32_BLE_SERVER_NOTIFY_PROVIDED][char_config[CONF_ID]] = char_config[CONF_NOTIFY] CORE.data[_KEY_NOTIFY_PROVIDED][char_config[CONF_ID]] = char_config[CONF_NOTIFY]
# Check if the NOTIFY property is set if the characteristic has a notify action # Check if the NOTIFY property is set if the characteristic has a notify action
char_ids = CORE.data.get(KEY_ESP32_BLE_SERVER_NOTIFY_REQUIRED, set()) char_ids = CORE.data.get(_KEY_NOTIFY_REQUIRED, set())
if not char_config[CONF_NOTIFY] and char_config[CONF_ID] in char_ids: if not char_config[CONF_NOTIFY] and char_config[CONF_ID] in char_ids:
raise cv.Invalid("Characteristic has a notify action, but the NOTIFY property is not set") raise cv.Invalid(
"Characteristic has a notify action, but the NOTIFY property is not set"
)
return char_config return char_config
def validate_notify_action(action_char_id): def validate_notify_action(action_char_id):
if KEY_ESP32_BLE_SERVER_NOTIFY_REQUIRED not in CORE.data: if _KEY_NOTIFY_REQUIRED not in CORE.data:
CORE.data[KEY_ESP32_BLE_SERVER_NOTIFY_REQUIRED] = set() CORE.data[_KEY_NOTIFY_REQUIRED] = set()
CORE.data[KEY_ESP32_BLE_SERVER_NOTIFY_REQUIRED].add(action_char_id) CORE.data[_KEY_NOTIFY_REQUIRED].add(action_char_id)
# Check if the NOTIFY property is set for the characteristic # Check if the NOTIFY property is set for the characteristic
char_notify_value = CORE.data.get(KEY_ESP32_BLE_SERVER_NOTIFY_PROVIDED, dict()).get(action_char_id, None) char_notify_value = CORE.data.get(_KEY_NOTIFY_PROVIDED, {}).get(action_char_id, None)
if char_notify_value is not None and not char_notify_value: if char_notify_value is not None and not char_notify_value:
raise cv.Invalid("Missing NOTIFY property for characteristic with notify action") raise cv.Invalid(
"Missing NOTIFY property for characteristic with notify action"
)
return action_char_id return action_char_id
@ -155,7 +159,7 @@ SERVICE_CHARACTERISTIC_SCHEMA = cv.Schema(
), ),
}, },
extra_schemas=[validate_on_write, validate_notify_characteristic], extra_schemas=[validate_on_write, validate_notify_characteristic],
).extend({cv.Optional(k, default=False): cv.boolean for k in PROPERTY_MAP.keys()}) ).extend({cv.Optional(k, default=False): cv.boolean for k in PROPERTY_MAP})
SERVICE_SCHEMA = cv.Schema( SERVICE_SCHEMA = cv.Schema(
{ {

View file

@ -47,7 +47,7 @@ void BLEServer::loop() {
for (unsigned i = 0; i < this->services_to_start_.size(); i++) { for (unsigned i = 0; i < this->services_to_start_.size(); i++) {
BLEService *service = this->services_to_start_[i]; BLEService *service = this->services_to_start_[i];
if (service->is_created()) { if (service->is_created()) {
service->start(); service->start(); // Needs to be called once per characteristic in the service
} else { } else {
index_to_remove = i + 1; index_to_remove = i + 1;
} }
@ -125,7 +125,8 @@ bool BLEServer::create_device_characteristics_() {
BLECharacteristic *manufacturer = BLECharacteristic *manufacturer =
this->device_information_service_->create_characteristic(MANUFACTURER_UUID, BLECharacteristic::PROPERTY_READ); this->device_information_service_->create_characteristic(MANUFACTURER_UUID, BLECharacteristic::PROPERTY_READ);
manufacturer->set_value(ByteBuffer::wrap(std::vector<uint8_t>(this->manufacturer_.begin(), this->manufacturer_.end()))); manufacturer->set_value(
ByteBuffer::wrap(std::vector<uint8_t>(this->manufacturer_.begin(), this->manufacturer_.end())));
return true; return true;
} }