From 9c8aa8456eb3eab0028989d112e4dbcbb3a5eee7 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 5 Jun 2024 09:20:48 +0200 Subject: [PATCH] Move enable_bluetooth fixture to decorator (#118849) --- .../private_ble_device/test_device_tracker.py | 33 ++++++++++--------- tests/components/ruuvitag_ble/test_sensor.py | 5 ++- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/tests/components/private_ble_device/test_device_tracker.py b/tests/components/private_ble_device/test_device_tracker.py index b1952557316..8fd1f694d84 100644 --- a/tests/components/private_ble_device/test_device_tracker.py +++ b/tests/components/private_ble_device/test_device_tracker.py @@ -22,7 +22,8 @@ from . import ( from tests.components.bluetooth.test_advertisement_tracker import ONE_HOUR_SECONDS -async def test_tracker_created(hass: HomeAssistant, enable_bluetooth: None) -> None: +@pytest.mark.usefixtures("enable_bluetooth") +async def test_tracker_created(hass: HomeAssistant) -> None: """Test creating a tracker entity when no devices have been seen.""" await async_mock_config_entry(hass) @@ -31,9 +32,8 @@ async def test_tracker_created(hass: HomeAssistant, enable_bluetooth: None) -> N assert state.state == "not_home" -async def test_tracker_ignore_other_rpa( - hass: HomeAssistant, enable_bluetooth: None -) -> None: +@pytest.mark.usefixtures("enable_bluetooth") +async def test_tracker_ignore_other_rpa(hass: HomeAssistant) -> None: """Test that tracker ignores RPA's that don't match us.""" await async_mock_config_entry(hass) await async_inject_broadcast(hass, MAC_STATIC) @@ -43,9 +43,8 @@ async def test_tracker_ignore_other_rpa( assert state.state == "not_home" -async def test_tracker_already_home( - hass: HomeAssistant, enable_bluetooth: None -) -> None: +@pytest.mark.usefixtures("enable_bluetooth") +async def test_tracker_already_home(hass: HomeAssistant) -> None: """Test creating a tracker and the device was already discovered by HA.""" await async_inject_broadcast(hass, MAC_RPA_VALID_1) await async_mock_config_entry(hass) @@ -55,7 +54,8 @@ async def test_tracker_already_home( assert state.state == "home" -async def test_tracker_arrive_home(hass: HomeAssistant, enable_bluetooth: None) -> None: +@pytest.mark.usefixtures("enable_bluetooth") +async def test_tracker_arrive_home(hass: HomeAssistant) -> None: """Test transition from not_home to home.""" await async_mock_config_entry(hass) await async_inject_broadcast(hass, MAC_RPA_VALID_1, b"1") @@ -85,7 +85,8 @@ async def test_tracker_arrive_home(hass: HomeAssistant, enable_bluetooth: None) assert state.attributes["current_address"] == "40:01:02:0a:c4:a6" -async def test_tracker_isolation(hass: HomeAssistant, enable_bluetooth: None) -> None: +@pytest.mark.usefixtures("enable_bluetooth") +async def test_tracker_isolation(hass: HomeAssistant) -> None: """Test creating 2 tracker entities doesn't confuse anything.""" await async_mock_config_entry(hass) await async_mock_config_entry(hass, irk="1" * 32) @@ -102,7 +103,8 @@ async def test_tracker_isolation(hass: HomeAssistant, enable_bluetooth: None) -> assert state.state == "not_home" -async def test_tracker_mac_rotate(hass: HomeAssistant, enable_bluetooth: None) -> None: +@pytest.mark.usefixtures("enable_bluetooth") +async def test_tracker_mac_rotate(hass: HomeAssistant) -> None: """Test MAC address rotation.""" await async_inject_broadcast(hass, MAC_RPA_VALID_1) await async_mock_config_entry(hass) @@ -119,7 +121,8 @@ async def test_tracker_mac_rotate(hass: HomeAssistant, enable_bluetooth: None) - assert state.attributes["current_address"] == MAC_RPA_VALID_2 -async def test_tracker_start_stale(hass: HomeAssistant, enable_bluetooth: None) -> None: +@pytest.mark.usefixtures("enable_bluetooth") +async def test_tracker_start_stale(hass: HomeAssistant) -> None: """Test edge case where we find an existing stale record, and it expires before we see any more.""" time.monotonic() @@ -138,7 +141,8 @@ async def test_tracker_start_stale(hass: HomeAssistant, enable_bluetooth: None) assert state.state == "not_home" -async def test_tracker_leave_home(hass: HomeAssistant, enable_bluetooth: None) -> None: +@pytest.mark.usefixtures("enable_bluetooth") +async def test_tracker_leave_home(hass: HomeAssistant) -> None: """Test tracker notices we have left.""" time.monotonic() @@ -157,9 +161,8 @@ async def test_tracker_leave_home(hass: HomeAssistant, enable_bluetooth: None) - assert state.state == "not_home" -async def test_old_tracker_leave_home( - hass: HomeAssistant, enable_bluetooth: None -) -> None: +@pytest.mark.usefixtures("enable_bluetooth") +async def test_old_tracker_leave_home(hass: HomeAssistant) -> None: """Test tracker ignores an old stale mac address timing out.""" start_time = time.monotonic() diff --git a/tests/components/ruuvitag_ble/test_sensor.py b/tests/components/ruuvitag_ble/test_sensor.py index 12cf0a4c0d6..c33e0453c53 100644 --- a/tests/components/ruuvitag_ble/test_sensor.py +++ b/tests/components/ruuvitag_ble/test_sensor.py @@ -2,6 +2,8 @@ from __future__ import annotations +import pytest + from homeassistant.components.ruuvitag_ble.const import DOMAIN from homeassistant.components.sensor import ATTR_STATE_CLASS from homeassistant.const import ATTR_FRIENDLY_NAME, ATTR_UNIT_OF_MEASUREMENT @@ -13,7 +15,8 @@ from tests.common import MockConfigEntry from tests.components.bluetooth import inject_bluetooth_service_info -async def test_sensors(enable_bluetooth: None, hass: HomeAssistant) -> None: +@pytest.mark.usefixtures("enable_bluetooth") +async def test_sensors(hass: HomeAssistant) -> None: """Test the RuuviTag BLE sensors.""" entry = MockConfigEntry(domain=DOMAIN, unique_id=RUUVITAG_SERVICE_INFO.address) entry.add_to_hass(hass)