Move None bluetooth fixtures to decorator (#118802)
This commit is contained in:
parent
f120f55d86
commit
80975d7a63
12 changed files with 253 additions and 230 deletions
|
@ -59,8 +59,9 @@ from . import (
|
|||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_setup_and_stop(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test we and setup and stop the scanner."""
|
||||
mock_bt = [
|
||||
|
@ -84,8 +85,9 @@ async def test_setup_and_stop(
|
|||
assert len(mock_bleak_scanner_start.mock_calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("one_adapter")
|
||||
async def test_setup_and_stop_passive(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, one_adapter: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test we and setup and stop the scanner the passive scanner."""
|
||||
entry = MockConfigEntry(
|
||||
|
@ -183,8 +185,9 @@ async def test_setup_and_stop_old_bluez(
|
|||
}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("one_adapter")
|
||||
async def test_setup_and_stop_no_bluetooth(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, one_adapter: None
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test we fail gracefully when bluetooth is not available."""
|
||||
mock_bt = [
|
||||
|
@ -211,8 +214,9 @@ async def test_setup_and_stop_no_bluetooth(
|
|||
assert "Failed to initialize Bluetooth" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("macos_adapter")
|
||||
async def test_setup_and_stop_broken_bluetooth(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, macos_adapter: None
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test we fail gracefully when bluetooth/dbus is broken."""
|
||||
mock_bt = []
|
||||
|
@ -236,8 +240,9 @@ async def test_setup_and_stop_broken_bluetooth(
|
|||
assert len(bluetooth.async_discovered_service_info(hass)) == 0
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("macos_adapter")
|
||||
async def test_setup_and_stop_broken_bluetooth_hanging(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, macos_adapter: None
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test we fail gracefully when bluetooth/dbus is hanging."""
|
||||
mock_bt = []
|
||||
|
@ -265,8 +270,9 @@ async def test_setup_and_stop_broken_bluetooth_hanging(
|
|||
assert "Timed out starting Bluetooth" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("macos_adapter")
|
||||
async def test_setup_and_retry_adapter_not_yet_available(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, macos_adapter: None
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test we retry if the adapter is not yet available."""
|
||||
mock_bt = []
|
||||
|
@ -304,8 +310,9 @@ async def test_setup_and_retry_adapter_not_yet_available(
|
|||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("macos_adapter")
|
||||
async def test_no_race_during_manual_reload_in_retry_state(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, macos_adapter: None
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test we can successfully reload when the entry is in a retry state."""
|
||||
mock_bt = []
|
||||
|
@ -344,8 +351,9 @@ async def test_no_race_during_manual_reload_in_retry_state(
|
|||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("macos_adapter")
|
||||
async def test_calling_async_discovered_devices_no_bluetooth(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, macos_adapter: None
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test we fail gracefully when asking for discovered devices and there is no blueooth."""
|
||||
mock_bt = []
|
||||
|
@ -370,8 +378,9 @@ async def test_calling_async_discovered_devices_no_bluetooth(
|
|||
assert not bluetooth.async_address_present(hass, "aa:bb:bb:dd:ee:ff")
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_discovery_match_by_service_uuid(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test bluetooth discovery match by service_uuid."""
|
||||
mock_bt = [
|
||||
|
@ -467,8 +476,9 @@ def _domains_from_mock_config_flow(mock_config_flow: Mock) -> list[str]:
|
|||
return [call[1][0] for call in mock_config_flow.mock_calls if call[1][0] != DOMAIN]
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("macos_adapter")
|
||||
async def test_discovery_match_by_service_uuid_connectable(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, macos_adapter: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test bluetooth discovery match by service_uuid and the ble device is connectable."""
|
||||
mock_bt = [
|
||||
|
@ -518,8 +528,9 @@ async def test_discovery_match_by_service_uuid_connectable(
|
|||
assert called_domains == ["switchbot"]
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("macos_adapter")
|
||||
async def test_discovery_match_by_service_uuid_not_connectable(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, macos_adapter: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test bluetooth discovery match by service_uuid and the ble device is not connectable."""
|
||||
mock_bt = [
|
||||
|
@ -567,8 +578,9 @@ async def test_discovery_match_by_service_uuid_not_connectable(
|
|||
assert len(_domains_from_mock_config_flow(mock_config_flow)) == 0
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("macos_adapter")
|
||||
async def test_discovery_match_by_name_connectable_false(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, macos_adapter: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test bluetooth discovery match by name and the integration will take non-connectable devices."""
|
||||
mock_bt = [
|
||||
|
@ -645,8 +657,9 @@ async def test_discovery_match_by_name_connectable_false(
|
|||
assert _domains_from_mock_config_flow(mock_config_flow) == ["qingping"]
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("macos_adapter")
|
||||
async def test_discovery_match_by_local_name(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, macos_adapter: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test bluetooth discovery match by local_name."""
|
||||
mock_bt = [{"domain": "switchbot", "local_name": "wohand"}]
|
||||
|
@ -683,8 +696,9 @@ async def test_discovery_match_by_local_name(
|
|||
assert mock_config_flow.mock_calls[0][1][0] == "switchbot"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("macos_adapter")
|
||||
async def test_discovery_match_by_manufacturer_id_and_manufacturer_data_start(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, macos_adapter: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test bluetooth discovery match by manufacturer_id and manufacturer_data_start."""
|
||||
mock_bt = [
|
||||
|
@ -759,8 +773,9 @@ async def test_discovery_match_by_manufacturer_id_and_manufacturer_data_start(
|
|||
assert len(mock_config_flow.mock_calls) == 0
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("macos_adapter")
|
||||
async def test_discovery_match_by_service_data_uuid_then_others(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, macos_adapter: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test bluetooth discovery match by service_data_uuid and then other fields."""
|
||||
mock_bt = [
|
||||
|
@ -913,8 +928,9 @@ async def test_discovery_match_by_service_data_uuid_then_others(
|
|||
assert len(mock_config_flow.mock_calls) == 0
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("macos_adapter")
|
||||
async def test_discovery_match_by_service_data_uuid_when_format_changes(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, macos_adapter: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test bluetooth discovery match by service_data_uuid when format changes."""
|
||||
mock_bt = [
|
||||
|
@ -996,8 +1012,9 @@ async def test_discovery_match_by_service_data_uuid_when_format_changes(
|
|||
mock_config_flow.reset_mock()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("macos_adapter")
|
||||
async def test_discovery_match_by_service_data_uuid_bthome(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, macos_adapter: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test bluetooth discovery match by service_data_uuid for bthome."""
|
||||
mock_bt = [
|
||||
|
@ -1038,8 +1055,9 @@ async def test_discovery_match_by_service_data_uuid_bthome(
|
|||
mock_config_flow.reset_mock()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("macos_adapter")
|
||||
async def test_discovery_match_first_by_service_uuid_and_then_manufacturer_id(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, macos_adapter: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test bluetooth discovery matches twice for service_uuid and then manufacturer_id."""
|
||||
mock_bt = [
|
||||
|
@ -1102,8 +1120,9 @@ async def test_discovery_match_first_by_service_uuid_and_then_manufacturer_id(
|
|||
assert len(mock_config_flow.mock_calls) == 0
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_rediscovery(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test bluetooth discovery can be re-enabled for a given domain."""
|
||||
mock_bt = [
|
||||
|
@ -1149,8 +1168,9 @@ async def test_rediscovery(
|
|||
assert mock_config_flow.mock_calls[1][1][0] == "switchbot"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("macos_adapter")
|
||||
async def test_async_discovered_device_api(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, macos_adapter: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test the async_discovered_device API."""
|
||||
mock_bt = []
|
||||
|
@ -1255,8 +1275,9 @@ async def test_async_discovered_device_api(
|
|||
assert bluetooth.async_address_present(hass, "44:44:33:11:23:45") is True
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_register_callbacks(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test registering a callback."""
|
||||
mock_bt = []
|
||||
|
@ -1336,10 +1357,10 @@ async def test_register_callbacks(
|
|||
assert service_info.manufacturer_id == 89
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_register_callbacks_raises_exception(
|
||||
hass: HomeAssistant,
|
||||
mock_bleak_scanner_start: MagicMock,
|
||||
enable_bluetooth: None,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test registering a callback that raises ValueError."""
|
||||
|
@ -1401,8 +1422,9 @@ async def test_register_callbacks_raises_exception(
|
|||
assert "ValueError" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_register_callback_by_address(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test registering a callback by address."""
|
||||
mock_bt = []
|
||||
|
@ -1492,8 +1514,9 @@ async def test_register_callback_by_address(
|
|||
assert service_info.manufacturer_id == 89
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_register_callback_by_address_connectable_only(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test registering a callback by address connectable only."""
|
||||
mock_bt = []
|
||||
|
@ -1571,8 +1594,9 @@ async def test_register_callback_by_address_connectable_only(
|
|||
assert len(non_connectable_callbacks) == 2
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_register_callback_by_manufacturer_id(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test registering a callback by manufacturer_id."""
|
||||
mock_bt = []
|
||||
|
@ -1626,8 +1650,9 @@ async def test_register_callback_by_manufacturer_id(
|
|||
assert service_info.manufacturer_id == 21
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_register_callback_by_connectable(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test registering a callback by connectable."""
|
||||
mock_bt = []
|
||||
|
@ -1681,8 +1706,9 @@ async def test_register_callback_by_connectable(
|
|||
assert service_info.name == "empty"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_not_filtering_wanted_apple_devices(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test filtering noisy apple devices."""
|
||||
mock_bt = []
|
||||
|
@ -1741,8 +1767,9 @@ async def test_not_filtering_wanted_apple_devices(
|
|||
assert len(callbacks) == 3
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_filtering_noisy_apple_devices(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test filtering noisy apple devices."""
|
||||
mock_bt = []
|
||||
|
@ -1791,8 +1818,9 @@ async def test_filtering_noisy_apple_devices(
|
|||
assert len(callbacks) == 0
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_register_callback_by_address_connectable_manufacturer_id(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test registering a callback by address, manufacturer_id, and connectable."""
|
||||
mock_bt = []
|
||||
|
@ -1845,8 +1873,9 @@ async def test_register_callback_by_address_connectable_manufacturer_id(
|
|||
assert service_info.manufacturer_id == 21
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_register_callback_by_manufacturer_id_and_address(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test registering a callback by manufacturer_id and address."""
|
||||
mock_bt = []
|
||||
|
@ -1910,8 +1939,9 @@ async def test_register_callback_by_manufacturer_id_and_address(
|
|||
assert service_info.manufacturer_id == 21
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_register_callback_by_service_uuid_and_address(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test registering a callback by service_uuid and address."""
|
||||
mock_bt = []
|
||||
|
@ -1983,8 +2013,9 @@ async def test_register_callback_by_service_uuid_and_address(
|
|||
assert service_info.name == "switchbot"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_register_callback_by_service_data_uuid_and_address(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test registering a callback by service_data_uuid and address."""
|
||||
mock_bt = []
|
||||
|
@ -2056,8 +2087,9 @@ async def test_register_callback_by_service_data_uuid_and_address(
|
|||
assert service_info.name == "switchbot"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_register_callback_by_local_name(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test registering a callback by local_name."""
|
||||
mock_bt = []
|
||||
|
@ -2119,11 +2151,9 @@ async def test_register_callback_by_local_name(
|
|||
assert service_info.manufacturer_id == 21
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_register_callback_by_local_name_overly_broad(
|
||||
hass: HomeAssistant,
|
||||
mock_bleak_scanner_start: MagicMock,
|
||||
enable_bluetooth: None,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test registering a callback by local_name that is too broad."""
|
||||
mock_bt = []
|
||||
|
@ -2147,8 +2177,9 @@ async def test_register_callback_by_local_name_overly_broad(
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_register_callback_by_service_data_uuid(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test registering a callback by service_data_uuid."""
|
||||
mock_bt = []
|
||||
|
@ -2202,8 +2233,9 @@ async def test_register_callback_by_service_data_uuid(
|
|||
assert service_info.name == "xiaomi"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_register_callback_survives_reload(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test registering a callback by address survives bluetooth being reloaded."""
|
||||
mock_bt = []
|
||||
|
@ -2265,8 +2297,9 @@ async def test_register_callback_survives_reload(
|
|||
cancel()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_process_advertisements_bail_on_good_advertisement(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test as soon as we see a 'good' advertisement we return it."""
|
||||
done = asyncio.Future()
|
||||
|
@ -2304,8 +2337,9 @@ async def test_process_advertisements_bail_on_good_advertisement(
|
|||
assert result.name == "wohand"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_process_advertisements_ignore_bad_advertisement(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Check that we ignore bad advertisements."""
|
||||
done = asyncio.Event()
|
||||
|
@ -2358,8 +2392,9 @@ async def test_process_advertisements_ignore_bad_advertisement(
|
|||
assert result.service_data["00000d00-0000-1000-8000-00805f9b34fa"] == b"H\x10c"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_process_advertisements_timeout(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test we timeout if no advertisements at all."""
|
||||
|
||||
|
@ -2372,8 +2407,9 @@ async def test_process_advertisements_timeout(
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_wrapped_instance_with_filter(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test consumers can use the wrapped instance with a filter as if it was normal BleakScanner."""
|
||||
with patch(
|
||||
|
@ -2444,8 +2480,9 @@ async def test_wrapped_instance_with_filter(
|
|||
assert len(detected) == 4
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_wrapped_instance_with_service_uuids(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test consumers can use the wrapped instance with a service_uuids list as if it was normal BleakScanner."""
|
||||
with patch(
|
||||
|
@ -2500,8 +2537,9 @@ async def test_wrapped_instance_with_service_uuids(
|
|||
assert len(detected) == 2
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_wrapped_instance_with_service_uuids_with_coro_callback(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test consumers can use the wrapped instance with a service_uuids list as if it was normal BleakScanner.
|
||||
|
||||
|
@ -2559,8 +2597,9 @@ async def test_wrapped_instance_with_service_uuids_with_coro_callback(
|
|||
assert len(detected) == 2
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_wrapped_instance_with_broken_callbacks(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test broken callbacks do not cause the scanner to fail."""
|
||||
with (
|
||||
|
@ -2606,8 +2645,9 @@ async def test_wrapped_instance_with_broken_callbacks(
|
|||
assert len(detected) == 1
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_wrapped_instance_changes_uuids(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test consumers can use the wrapped instance can change the uuids later."""
|
||||
with patch(
|
||||
|
@ -2661,8 +2701,9 @@ async def test_wrapped_instance_changes_uuids(
|
|||
assert len(detected) == 2
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_wrapped_instance_changes_filters(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, enable_bluetooth: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test consumers can use the wrapped instance can change the filter later."""
|
||||
with patch(
|
||||
|
@ -2717,11 +2758,11 @@ async def test_wrapped_instance_changes_filters(
|
|||
assert len(detected) == 2
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_wrapped_instance_unsupported_filter(
|
||||
hass: HomeAssistant,
|
||||
mock_bleak_scanner_start: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
enable_bluetooth: None,
|
||||
) -> None:
|
||||
"""Test we want when their filter is ineffective."""
|
||||
with patch(
|
||||
|
@ -2743,8 +2784,9 @@ async def test_wrapped_instance_unsupported_filter(
|
|||
assert "Only UUIDs filters are supported" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("macos_adapter")
|
||||
async def test_async_ble_device_from_address(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, macos_adapter: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test the async_ble_device_from_address api."""
|
||||
set_manager(None)
|
||||
|
@ -2800,8 +2842,9 @@ async def test_async_ble_device_from_address(
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("macos_adapter")
|
||||
async def test_can_unsetup_bluetooth_single_adapter_macos(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, macos_adapter: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test we can setup and unsetup bluetooth."""
|
||||
entry = MockConfigEntry(domain=bluetooth.DOMAIN, data={}, unique_id=DEFAULT_ADDRESS)
|
||||
|
@ -2815,10 +2858,10 @@ async def test_can_unsetup_bluetooth_single_adapter_macos(
|
|||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("one_adapter")
|
||||
async def test_default_address_config_entries_removed_linux(
|
||||
hass: HomeAssistant,
|
||||
mock_bleak_scanner_start: MagicMock,
|
||||
one_adapter: None,
|
||||
) -> None:
|
||||
"""Test default address entries are removed on linux."""
|
||||
entry = MockConfigEntry(domain=bluetooth.DOMAIN, data={}, unique_id=DEFAULT_ADDRESS)
|
||||
|
@ -2828,11 +2871,9 @@ async def test_default_address_config_entries_removed_linux(
|
|||
assert not hass.config_entries.async_entries(bluetooth.DOMAIN)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth", "one_adapter")
|
||||
async def test_can_unsetup_bluetooth_single_adapter_linux(
|
||||
hass: HomeAssistant,
|
||||
mock_bleak_scanner_start: MagicMock,
|
||||
enable_bluetooth: None,
|
||||
one_adapter: None,
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test we can setup and unsetup bluetooth."""
|
||||
entry = MockConfigEntry(
|
||||
|
@ -2848,11 +2889,10 @@ async def test_can_unsetup_bluetooth_single_adapter_linux(
|
|||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth", "two_adapters")
|
||||
async def test_can_unsetup_bluetooth_multiple_adapters(
|
||||
hass: HomeAssistant,
|
||||
mock_bleak_scanner_start: MagicMock,
|
||||
enable_bluetooth: None,
|
||||
two_adapters: None,
|
||||
) -> None:
|
||||
"""Test we can setup and unsetup bluetooth with multiple adapters."""
|
||||
entry1 = MockConfigEntry(
|
||||
|
@ -2874,11 +2914,10 @@ async def test_can_unsetup_bluetooth_multiple_adapters(
|
|||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth", "two_adapters")
|
||||
async def test_three_adapters_one_missing(
|
||||
hass: HomeAssistant,
|
||||
mock_bleak_scanner_start: MagicMock,
|
||||
enable_bluetooth: None,
|
||||
two_adapters: None,
|
||||
) -> None:
|
||||
"""Test three adapters but one is missing results in a retry on setup."""
|
||||
entry = MockConfigEntry(
|
||||
|
@ -2890,9 +2929,8 @@ async def test_three_adapters_one_missing(
|
|||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_auto_detect_bluetooth_adapters_linux(
|
||||
hass: HomeAssistant, one_adapter: None
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("one_adapter")
|
||||
async def test_auto_detect_bluetooth_adapters_linux(hass: HomeAssistant) -> None:
|
||||
"""Test we auto detect bluetooth adapters on linux."""
|
||||
assert await async_setup_component(hass, bluetooth.DOMAIN, {})
|
||||
await hass.async_block_till_done()
|
||||
|
@ -2900,8 +2938,9 @@ async def test_auto_detect_bluetooth_adapters_linux(
|
|||
assert len(hass.config_entries.flow.async_progress(bluetooth.DOMAIN)) == 1
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("two_adapters")
|
||||
async def test_auto_detect_bluetooth_adapters_linux_multiple(
|
||||
hass: HomeAssistant, two_adapters: None
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test we auto detect bluetooth adapters on linux with multiple adapters."""
|
||||
assert await async_setup_component(hass, bluetooth.DOMAIN, {})
|
||||
|
@ -2959,17 +2998,17 @@ async def test_no_auto_detect_bluetooth_adapters_windows(hass: HomeAssistant) ->
|
|||
assert len(hass.config_entries.flow.async_progress(bluetooth.DOMAIN)) == 0
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_getting_the_scanner_returns_the_wrapped_instance(
|
||||
hass: HomeAssistant, enable_bluetooth: None
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test getting the scanner returns the wrapped instance."""
|
||||
scanner = bluetooth.async_get_scanner(hass)
|
||||
assert isinstance(scanner, HaBleakScannerWrapper)
|
||||
|
||||
|
||||
async def test_scanner_count_connectable(
|
||||
hass: HomeAssistant, enable_bluetooth: None
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_scanner_count_connectable(hass: HomeAssistant) -> None:
|
||||
"""Test getting the connectable scanner count."""
|
||||
scanner = FakeScanner("any", "any")
|
||||
cancel = bluetooth.async_register_scanner(hass, scanner)
|
||||
|
@ -2977,7 +3016,8 @@ async def test_scanner_count_connectable(
|
|||
cancel()
|
||||
|
||||
|
||||
async def test_scanner_count(hass: HomeAssistant, enable_bluetooth: None) -> None:
|
||||
@pytest.mark.usefixtures("enable_bluetooth")
|
||||
async def test_scanner_count(hass: HomeAssistant) -> None:
|
||||
"""Test getting the connectable and non-connectable scanner count."""
|
||||
scanner = FakeScanner("any", "any")
|
||||
cancel = bluetooth.async_register_scanner(hass, scanner)
|
||||
|
@ -2985,8 +3025,9 @@ async def test_scanner_count(hass: HomeAssistant, enable_bluetooth: None) -> Non
|
|||
cancel()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("macos_adapter")
|
||||
async def test_migrate_single_entry_macos(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, macos_adapter: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test we can migrate a single entry on MacOS."""
|
||||
entry = MockConfigEntry(domain=bluetooth.DOMAIN, data={})
|
||||
|
@ -2996,8 +3037,9 @@ async def test_migrate_single_entry_macos(
|
|||
assert entry.unique_id == DEFAULT_ADDRESS
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("one_adapter")
|
||||
async def test_migrate_single_entry_linux(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, one_adapter: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test we can migrate a single entry on Linux."""
|
||||
entry = MockConfigEntry(domain=bluetooth.DOMAIN, data={})
|
||||
|
@ -3007,8 +3049,9 @@ async def test_migrate_single_entry_linux(
|
|||
assert entry.unique_id == "00:00:00:00:00:01"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("one_adapter")
|
||||
async def test_discover_new_usb_adapters(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, one_adapter: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test we can discover new usb adapters."""
|
||||
entry = MockConfigEntry(
|
||||
|
@ -3067,8 +3110,9 @@ async def test_discover_new_usb_adapters(
|
|||
assert len(hass.config_entries.flow.async_progress(DOMAIN)) == 1
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("one_adapter")
|
||||
async def test_discover_new_usb_adapters_with_firmware_fallback_delay(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, one_adapter: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test we can discover new usb adapters with a firmware fallback delay."""
|
||||
entry = MockConfigEntry(
|
||||
|
@ -3146,10 +3190,10 @@ async def test_discover_new_usb_adapters_with_firmware_fallback_delay(
|
|||
assert len(hass.config_entries.flow.async_progress(DOMAIN)) == 1
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("no_adapters")
|
||||
async def test_issue_outdated_haos_removed(
|
||||
hass: HomeAssistant,
|
||||
mock_bleak_scanner_start: MagicMock,
|
||||
no_adapters: None,
|
||||
operating_system_85: None,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
) -> None:
|
||||
|
@ -3163,10 +3207,10 @@ async def test_issue_outdated_haos_removed(
|
|||
assert issue is None
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("one_adapter")
|
||||
async def test_haos_9_or_later(
|
||||
hass: HomeAssistant,
|
||||
mock_bleak_scanner_start: MagicMock,
|
||||
one_adapter: None,
|
||||
operating_system_90: None,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
) -> None:
|
||||
|
@ -3183,8 +3227,9 @@ async def test_haos_9_or_later(
|
|||
assert issue is None
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("one_adapter")
|
||||
async def test_title_updated_if_mac_address(
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock, one_adapter: None
|
||||
hass: HomeAssistant, mock_bleak_scanner_start: MagicMock
|
||||
) -> None:
|
||||
"""Test the title is updated if it is the mac address."""
|
||||
entry = MockConfigEntry(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue