mirror of
https://github.com/esphome/esphome.git
synced 2026-06-24 14:52:50 +00:00
[esp32_ble][esp32_ble_server][esp32_ble_beacon] Fix UUID regex, IndexError, and unused inheritance (#15504)
This commit is contained in:
@@ -373,14 +373,14 @@ def bt_uuid(value):
|
||||
value = in_value.upper()
|
||||
|
||||
if len(value) == len(bt_uuid16_format):
|
||||
pattern = re.compile("^[A-F|0-9]{4,}$")
|
||||
pattern = re.compile("^[A-F0-9]{4,}$")
|
||||
if not pattern.match(value):
|
||||
raise cv.Invalid(
|
||||
f"Invalid hexadecimal value for 16 bit UUID format: '{in_value}'"
|
||||
)
|
||||
return value
|
||||
if len(value) == len(bt_uuid32_format):
|
||||
pattern = re.compile("^[A-F|0-9]{8,}$")
|
||||
pattern = re.compile("^[A-F0-9]{8,}$")
|
||||
if not pattern.match(value):
|
||||
raise cv.Invalid(
|
||||
f"Invalid hexadecimal value for 32 bit UUID format: '{in_value}'"
|
||||
@@ -388,7 +388,7 @@ def bt_uuid(value):
|
||||
return value
|
||||
if len(value) == len(bt_uuid128_format):
|
||||
pattern = re.compile(
|
||||
"^[A-F|0-9]{8,}-[A-F|0-9]{4,}-[A-F|0-9]{4,}-[A-F|0-9]{4,}-[A-F|0-9]{12,}$"
|
||||
"^[A-F0-9]{8,}-[A-F0-9]{4,}-[A-F0-9]{4,}-[A-F0-9]{4,}-[A-F0-9]{12,}$"
|
||||
)
|
||||
if not pattern.match(value):
|
||||
raise cv.Invalid(
|
||||
|
||||
@@ -10,11 +10,7 @@ AUTO_LOAD = ["esp32_ble"]
|
||||
DEPENDENCIES = ["esp32"]
|
||||
|
||||
esp32_ble_beacon_ns = cg.esphome_ns.namespace("esp32_ble_beacon")
|
||||
ESP32BLEBeacon = esp32_ble_beacon_ns.class_(
|
||||
"ESP32BLEBeacon",
|
||||
cg.Component,
|
||||
cg.Parented.template(esp32_ble.ESP32BLE),
|
||||
)
|
||||
ESP32BLEBeacon = esp32_ble_beacon_ns.class_("ESP32BLEBeacon", cg.Component)
|
||||
CONF_MAJOR = "major"
|
||||
CONF_MINOR = "minor"
|
||||
CONF_MIN_INTERVAL = "min_interval"
|
||||
|
||||
@@ -35,7 +35,7 @@ using esp_ble_ibeacon_t = struct {
|
||||
|
||||
using namespace esp32_ble;
|
||||
|
||||
class ESP32BLEBeacon : public Component, public Parented<ESP32BLE> {
|
||||
class ESP32BLEBeacon : public Component {
|
||||
public:
|
||||
explicit ESP32BLEBeacon(const std::array<uint8_t, 16> &uuid) : uuid_(uuid) {}
|
||||
|
||||
|
||||
@@ -307,24 +307,30 @@ def final_validate_config(config):
|
||||
# Check if all characteristics that require notifications have the notify property set
|
||||
for char_id in CORE.data.get(DOMAIN, {}).get(KEY_NOTIFY_REQUIRED, set()):
|
||||
# Look for the characteristic in the configuration
|
||||
char_config = [
|
||||
matches = [
|
||||
char_conf
|
||||
for service_conf in config[CONF_SERVICES]
|
||||
for char_conf in service_conf[CONF_CHARACTERISTICS]
|
||||
if char_conf[CONF_ID] == char_id
|
||||
][0]
|
||||
]
|
||||
if not matches:
|
||||
continue
|
||||
char_config = matches[0]
|
||||
if not char_config[CONF_NOTIFY]:
|
||||
raise cv.Invalid(
|
||||
f"Characteristic {char_config[CONF_UUID]} has notify actions and the {CONF_NOTIFY} property is not set"
|
||||
)
|
||||
for char_id in CORE.data.get(DOMAIN, {}).get(KEY_SET_VALUE, set()):
|
||||
# Look for the characteristic in the configuration
|
||||
char_config = [
|
||||
matches = [
|
||||
char_conf
|
||||
for service_conf in config[CONF_SERVICES]
|
||||
for char_conf in service_conf[CONF_CHARACTERISTICS]
|
||||
if char_conf[CONF_ID] == char_id
|
||||
][0]
|
||||
]
|
||||
if not matches:
|
||||
continue
|
||||
char_config = matches[0]
|
||||
if isinstance(char_config.get(CONF_VALUE, {}).get(CONF_DATA), cv.Lambda):
|
||||
raise cv.Invalid(
|
||||
f"Characteristic {char_config[CONF_UUID]} has both a set_value action and a templated value"
|
||||
|
||||
Reference in New Issue
Block a user