Home Assistant Unofficial Reference 2024.12.1
homeassistant.components.bluetooth.match Namespace Reference

Classes

class  _BluetoothCallbackMatcherWithCallback
 
class  BluetoothCallbackMatcher
 
class  BluetoothCallbackMatcherIndex
 
class  BluetoothCallbackMatcherOptional
 
class  BluetoothCallbackMatcherWithCallback
 
class  BluetoothMatcherIndex
 
class  BluetoothMatcherIndexBase
 
class  IntegrationMatcher
 
class  IntegrationMatchHistory
 

Functions

None __init__ (self)
 
re.Pattern _compile_fnmatch (str pattern)
 
str _local_name_to_index_key (str local_name)
 
bool _memorized_fnmatch (str name, str pattern)
 
bool add (self, _T matcher)
 
bool ble_device_matches (BluetoothMatcherOptional matcher, BluetoothServiceInfoBleak service_info)
 
None build (self)
 
list[_T] match (self, BluetoothServiceInfoBleak service_info)
 
bool remove (self, _T matcher)
 
bool seen_all_fields (IntegrationMatchHistory previous_match, AdvertisementData advertisement_data)
 

Variables

tuple __slots__
 
 Final
 
int LOCAL_NAME_MIN_MATCH_LENGTH = 3
 
 manufacturer_id_set
 
 service_data_uuid_set
 
 service_uuid_set
 

Detailed Description

The bluetooth integration matchers.

Function Documentation

◆ __init__()

None homeassistant.components.bluetooth.match.__init__ (   self)
Initialize the matcher index.

Definition at line 175 of file match.py.

◆ _compile_fnmatch()

re.Pattern homeassistant.components.bluetooth.match._compile_fnmatch ( str  pattern)
private
Compile a fnmatch pattern.

Definition at line 434 of file match.py.

◆ _local_name_to_index_key()

str homeassistant.components.bluetooth.match._local_name_to_index_key ( str  local_name)
private
Convert a local name to an index.

We check the local name matchers here and raise a ValueError
if they try to setup a matcher that will is overly broad
as would match too many devices and cause a performance hit.

Definition at line 376 of file match.py.

◆ _memorized_fnmatch()

bool homeassistant.components.bluetooth.match._memorized_fnmatch ( str  name,
str  pattern 
)
private
Memorized version of fnmatch that has a larger lru_cache.

The default version of fnmatch only has a lru_cache of 256 entries.
With many devices we quickly reach that limit and end up compiling
the same pattern over and over again.

Bluetooth has its own memorized fnmatch with its own lru_cache
since the data is going to be relatively the same
since the devices will not change frequently.

Definition at line 440 of file match.py.

◆ add()

bool homeassistant.components.bluetooth.match.add (   self,
_T  matcher 
)
Add a matcher to the index.

Matchers must end up only in one bucket.

We put them in the bucket that they are most likely to match.

Definition at line 185 of file match.py.

◆ ble_device_matches()

bool homeassistant.components.bluetooth.match.ble_device_matches ( BluetoothMatcherOptional  matcher,
BluetoothServiceInfoBleak  service_info 
)
Check if a ble device and advertisement_data matches the matcher.

Definition at line 393 of file match.py.

◆ build()

None homeassistant.components.bluetooth.match.build (   self)
Rebuild the index sets.

Definition at line 240 of file match.py.

◆ match()

list[_T] homeassistant.components.bluetooth.match.match (   self,
BluetoothServiceInfoBleak  service_info 
)
Check for a match.

Definition at line 246 of file match.py.

◆ remove()

bool homeassistant.components.bluetooth.match.remove (   self,
_T  matcher 
)
Remove a matcher from the index.

Matchers only end up in one bucket, so once we have
removed one, we are done.

Definition at line 214 of file match.py.

◆ seen_all_fields()

bool homeassistant.components.bluetooth.match.seen_all_fields ( IntegrationMatchHistory  previous_match,
AdvertisementData   advertisement_data 
)
Return if we have seen all fields.

Definition at line 73 of file match.py.

Variable Documentation

◆ __slots__

tuple homeassistant.components.bluetooth.match.__slots__
private
Initial value:
1 = (
2  "local_name",
3  "service_uuid",
4  "service_data_uuid",
5  "manufacturer_id",
6  "service_uuid_set",
7  "service_data_uuid_set",
8  "manufacturer_id_set",
9  )
Bluetooth matcher base for the bluetooth integration.

The indexer puts each matcher in the bucket that it is most
likely to match. This allows us to only check the service infos
against each bucket to see if we should match against the data.

This is optimized for cases when no service infos will be matched in
any bucket and we can quickly reject the service info as not matching.

Definition at line 165 of file match.py.

◆ Final

homeassistant.components.bluetooth.match.Final

Definition at line 23 of file match.py.

◆ LOCAL_NAME_MIN_MATCH_LENGTH

int homeassistant.components.bluetooth.match.LOCAL_NAME_MIN_MATCH_LENGTH = 3

Definition at line 35 of file match.py.

◆ manufacturer_id_set

homeassistant.components.bluetooth.match.manufacturer_id_set

Definition at line 244 of file match.py.

◆ service_data_uuid_set

homeassistant.components.bluetooth.match.service_data_uuid_set

Definition at line 243 of file match.py.

◆ service_uuid_set

homeassistant.components.bluetooth.match.service_uuid_set

Definition at line 242 of file match.py.