Skip to content

Commit

Permalink
Merge pull request adafruit#13 from dhalbert/adv-name
Browse files Browse the repository at this point in the history
Add device name to advertisement data that is passed back.
  • Loading branch information
dhalbert authored Jun 24, 2020
2 parents 696d299 + c6d3902 commit 2b09e8c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions _bleio/scan_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* Author(s): Dan Halbert for Adafruit Industries
"""
from __future__ import annotations
import re
from typing import Union

from _bleio import Address, UUID
Expand All @@ -36,6 +37,18 @@


class ScanEntry:
# Some device names are created by the bleak code or what it calls, and aren't the
# real advertised name. Suppress those. Patterns seen include (XX are hex digits):
# dev_XX_XX_XX_XX_XX_XX
# XX-XX-XX-XX-XX-XX
# Unknown
_RE_IGNORABLE_NAME = re.compile(
r"((dev_)?"
r"[0-9A-F]{2}[-_][0-9A-F]{2}[-_][0-9A-F]{2}[-_][0-9A-F]{2}[-_][0-9A-F]{2}[-_][0-9A-F]{2})"
r"|Unknown",
re.IGNORECASE,
)

def __init__(
self,
*,
Expand Down Expand Up @@ -173,6 +186,10 @@ def _data_dict_from_bleak(device):
# Complete list of 128-bit UUIDs
data_dict[0x07] = uuids128

if not ScanEntry._RE_IGNORABLE_NAME.fullmatch(device.name):
# Complete name
data_dict[0x09] = device.name.encode("utf-8")

return data_dict

@staticmethod
Expand Down

0 comments on commit 2b09e8c

Please sign in to comment.