mirror of
https://github.com/esphome/esphome.git
synced 2025-01-03 19:31:46 +01:00
Recover hex UUIDs
This commit is contained in:
parent
36b3a8bac3
commit
321a9a0fa8
1 changed files with 13 additions and 6 deletions
|
@ -152,7 +152,7 @@ VALUE_EXTRAS_SCHEMA = cv.Schema(
|
||||||
DESCRIPTOR_SCHEMA = cv.Schema(
|
DESCRIPTOR_SCHEMA = cv.Schema(
|
||||||
{
|
{
|
||||||
cv.GenerateID(): cv.declare_id(BLEDescriptor),
|
cv.GenerateID(): cv.declare_id(BLEDescriptor),
|
||||||
cv.Required(CONF_UUID): bt_uuid,
|
cv.Required(CONF_UUID): cv.Any(bt_uuid, cv.hex_uint32_t),
|
||||||
cv.Optional(CONF_READ, default=True): cv.boolean,
|
cv.Optional(CONF_READ, default=True): cv.boolean,
|
||||||
cv.Optional(CONF_WRITE, default=True): cv.boolean,
|
cv.Optional(CONF_WRITE, default=True): cv.boolean,
|
||||||
cv.Optional(CONF_ON_WRITE): automation.validate_automation(
|
cv.Optional(CONF_ON_WRITE): automation.validate_automation(
|
||||||
|
@ -167,7 +167,7 @@ SERVICE_CHARACTERISTIC_SCHEMA = (
|
||||||
cv.Schema(
|
cv.Schema(
|
||||||
{
|
{
|
||||||
cv.GenerateID(): cv.declare_id(BLECharacteristic),
|
cv.GenerateID(): cv.declare_id(BLECharacteristic),
|
||||||
cv.Required(CONF_UUID): bt_uuid,
|
cv.Required(CONF_UUID): cv.Any(bt_uuid, cv.hex_uint32_t),
|
||||||
cv.Optional(CONF_VALUE): VALUE_SCHEMA,
|
cv.Optional(CONF_VALUE): VALUE_SCHEMA,
|
||||||
cv.GenerateID(CONF_CHAR_VALUE_ACTION_ID_): cv.declare_id(
|
cv.GenerateID(CONF_CHAR_VALUE_ACTION_ID_): cv.declare_id(
|
||||||
BLECharacteristicSetValueAction
|
BLECharacteristicSetValueAction
|
||||||
|
@ -188,7 +188,7 @@ SERVICE_CHARACTERISTIC_SCHEMA = (
|
||||||
SERVICE_SCHEMA = cv.Schema(
|
SERVICE_SCHEMA = cv.Schema(
|
||||||
{
|
{
|
||||||
cv.GenerateID(): cv.declare_id(BLEService),
|
cv.GenerateID(): cv.declare_id(BLEService),
|
||||||
cv.Required(CONF_UUID): bt_uuid,
|
cv.Required(CONF_UUID): cv.Any(bt_uuid, cv.hex_uint32_t),
|
||||||
cv.Optional(CONF_ADVERTISE, default=False): cv.boolean,
|
cv.Optional(CONF_ADVERTISE, default=False): cv.boolean,
|
||||||
cv.Optional(CONF_CHARACTERISTICS, default=[]): cv.ensure_list(
|
cv.Optional(CONF_CHARACTERISTICS, default=[]): cv.ensure_list(
|
||||||
SERVICE_CHARACTERISTIC_SCHEMA
|
SERVICE_CHARACTERISTIC_SCHEMA
|
||||||
|
@ -216,6 +216,13 @@ def parse_properties(char_conf):
|
||||||
start=0,
|
start=0,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def parse_uuid(uuid):
|
||||||
|
# If the UUID is a int, use from_uint32
|
||||||
|
if isinstance(uuid, int):
|
||||||
|
return ESPBTUUID_ns.from_uint32(uuid)
|
||||||
|
# Otherwise, use ESPBTUUID_ns.from_raw
|
||||||
|
return ESPBTUUID_ns.from_raw(uuid)
|
||||||
|
|
||||||
|
|
||||||
def bytebuffer_parser_(value, str_encoding):
|
def bytebuffer_parser_(value, str_encoding):
|
||||||
for val_method, casting in zip(
|
for val_method, casting in zip(
|
||||||
|
@ -301,7 +308,7 @@ async def to_code_descriptor(descriptor_conf, char_var):
|
||||||
)
|
)
|
||||||
desc_var = cg.new_Pvariable(
|
desc_var = cg.new_Pvariable(
|
||||||
descriptor_conf[CONF_ID],
|
descriptor_conf[CONF_ID],
|
||||||
ESPBTUUID_ns.from_raw(descriptor_conf[CONF_UUID]),
|
parse_uuid(descriptor_conf[CONF_UUID]),
|
||||||
value.get_capacity(),
|
value.get_capacity(),
|
||||||
descriptor_conf[CONF_READ],
|
descriptor_conf[CONF_READ],
|
||||||
descriptor_conf[CONF_WRITE],
|
descriptor_conf[CONF_WRITE],
|
||||||
|
@ -321,7 +328,7 @@ async def to_code_characteristic(service_var, char_conf):
|
||||||
char_var = cg.Pvariable(
|
char_var = cg.Pvariable(
|
||||||
char_conf[CONF_ID],
|
char_conf[CONF_ID],
|
||||||
service_var.create_characteristic(
|
service_var.create_characteristic(
|
||||||
ESPBTUUID_ns.from_raw(char_conf[CONF_UUID]),
|
parse_uuid(char_conf[CONF_UUID]),
|
||||||
parse_properties(char_conf),
|
parse_properties(char_conf),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -371,7 +378,7 @@ async def to_code(config):
|
||||||
service_var = cg.Pvariable(
|
service_var = cg.Pvariable(
|
||||||
service_config[CONF_ID],
|
service_config[CONF_ID],
|
||||||
var.create_service(
|
var.create_service(
|
||||||
ESPBTUUID_ns.from_raw(service_config[CONF_UUID]),
|
parse_uuid(service_config[CONF_UUID]),
|
||||||
service_config[CONF_ADVERTISE],
|
service_config[CONF_ADVERTISE],
|
||||||
num_handles,
|
num_handles,
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue