mirror of
https://github.com/home-assistant/core.git
synced 2025-04-22 16:27:56 +00:00
Avoid creating iBeacon trackers when the device has no name (#78983)
This commit is contained in:
parent
ace9592aa1
commit
5477ebdb13
@ -67,7 +67,7 @@ def async_name(
|
||||
base_name = service_info.name
|
||||
if unique_address:
|
||||
short_address = make_short_address(service_info.address)
|
||||
if not base_name.endswith(short_address):
|
||||
if not base_name.upper().endswith(short_address):
|
||||
return f"{base_name} {short_address}"
|
||||
return base_name
|
||||
|
||||
@ -233,6 +233,12 @@ class IBeaconCoordinator:
|
||||
address = service_info.address
|
||||
unique_id = f"{group_id}_{address}"
|
||||
new = unique_id not in self._last_rssi_by_unique_id
|
||||
# Reject creating new trackers if the name is not set
|
||||
if new and (
|
||||
service_info.device.name is None
|
||||
or service_info.device.name.replace("-", ":") == service_info.device.address
|
||||
):
|
||||
return
|
||||
self._last_rssi_by_unique_id[unique_id] = service_info.rssi
|
||||
self._async_track_ibeacon_with_unique_address(address, group_id, unique_id)
|
||||
if address not in self._unavailable_trackers:
|
||||
|
@ -28,6 +28,15 @@ BLUECHARM_BEACON_SERVICE_INFO_2 = BluetoothServiceInfo(
|
||||
service_uuids=["0000feaa-0000-1000-8000-00805f9b34fb"],
|
||||
source="local",
|
||||
)
|
||||
BLUECHARM_BEACON_SERVICE_INFO_DBUS = BluetoothServiceInfo(
|
||||
name="BlueCharm_177999",
|
||||
address="AA:BB:CC:DD:EE:FF",
|
||||
rssi=-63,
|
||||
service_data={},
|
||||
manufacturer_data={76: b"\x02\x15BlueCharmBeacons\x0e\xfe\x13U\xc5"},
|
||||
service_uuids=[],
|
||||
source="local",
|
||||
)
|
||||
NO_NAME_BEACON_SERVICE_INFO = BluetoothServiceInfo(
|
||||
name="61DE521B-F0BF-9F44-64D4-75BBE1738105",
|
||||
address="61DE521B-F0BF-9F44-64D4-75BBE1738105",
|
||||
|
@ -8,7 +8,7 @@ import pytest
|
||||
from homeassistant.components.ibeacon.const import DOMAIN
|
||||
from homeassistant.helpers.service_info.bluetooth import BluetoothServiceInfo
|
||||
|
||||
from . import BLUECHARM_BEACON_SERVICE_INFO
|
||||
from . import BLUECHARM_BEACON_SERVICE_INFO, BLUECHARM_BEACON_SERVICE_INFO_DBUS
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.bluetooth import inject_bluetooth_service_info
|
||||
@ -73,3 +73,57 @@ async def test_ignore_not_ibeacons(hass):
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert len(hass.states.async_entity_ids()) == before_entity_count
|
||||
|
||||
|
||||
async def test_ignore_no_name_but_create_if_set_later(hass):
|
||||
"""Test we ignore devices with no name but create it if it set set later."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
before_entity_count = len(hass.states.async_entity_ids())
|
||||
inject_bluetooth_service_info(
|
||||
hass,
|
||||
replace(BLUECHARM_BEACON_SERVICE_INFO, name=None),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert len(hass.states.async_entity_ids()) == before_entity_count
|
||||
|
||||
inject_bluetooth_service_info(
|
||||
hass,
|
||||
replace(
|
||||
BLUECHARM_BEACON_SERVICE_INFO,
|
||||
service_data={
|
||||
"00002080-0000-1000-8000-00805f9b34fb": b"j\x0c\x0e\xfe\x13U",
|
||||
"0000feaa-0000-1000-8000-00805f9b34fb": b" \x00\x0c\x00\x1c\x00\x00\x00\x06h\x00\x008\x10",
|
||||
},
|
||||
),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert len(hass.states.async_entity_ids()) > before_entity_count
|
||||
|
||||
|
||||
async def test_ignore_default_name(hass):
|
||||
"""Test we ignore devices with default name."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
before_entity_count = len(hass.states.async_entity_ids())
|
||||
inject_bluetooth_service_info(
|
||||
hass,
|
||||
replace(
|
||||
BLUECHARM_BEACON_SERVICE_INFO_DBUS,
|
||||
name=BLUECHARM_BEACON_SERVICE_INFO_DBUS.address,
|
||||
),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert len(hass.states.async_entity_ids()) == before_entity_count
|
||||
|
Loading…
x
Reference in New Issue
Block a user