Expose bluetooth availability tracking interval controls to integrations (#100774)
This commit is contained in:
parent
eb020dd66c
commit
f0375eb97e
5 changed files with 244 additions and 3 deletions
|
@ -6,6 +6,7 @@ from unittest.mock import patch
|
|||
import pytest
|
||||
|
||||
from homeassistant.components.bluetooth import (
|
||||
async_get_learned_advertising_interval,
|
||||
async_register_scanner,
|
||||
async_track_unavailable,
|
||||
)
|
||||
|
@ -62,6 +63,10 @@ async def test_advertisment_interval_shorter_than_adapter_stack_timeout(
|
|||
SOURCE_LOCAL,
|
||||
)
|
||||
|
||||
assert async_get_learned_advertising_interval(
|
||||
hass, "44:44:33:11:23:12"
|
||||
) == pytest.approx(2.0)
|
||||
|
||||
switchbot_device_unavailable_cancel = async_track_unavailable(
|
||||
hass, _switchbot_device_unavailable_callback, switchbot_device.address
|
||||
)
|
||||
|
@ -109,6 +114,10 @@ async def test_advertisment_interval_longer_than_adapter_stack_timeout_connectab
|
|||
SOURCE_LOCAL,
|
||||
)
|
||||
|
||||
assert async_get_learned_advertising_interval(
|
||||
hass, "44:44:33:11:23:18"
|
||||
) == pytest.approx(ONE_HOUR_SECONDS)
|
||||
|
||||
switchbot_device_unavailable_cancel = async_track_unavailable(
|
||||
hass, _switchbot_device_unavailable_callback, switchbot_device.address
|
||||
)
|
||||
|
@ -158,6 +167,10 @@ async def test_advertisment_interval_longer_than_adapter_stack_timeout_adapter_c
|
|||
"original",
|
||||
)
|
||||
|
||||
assert async_get_learned_advertising_interval(
|
||||
hass, "44:44:33:11:23:45"
|
||||
) == pytest.approx(2.0)
|
||||
|
||||
for i in range(ADVERTISING_TIMES_NEEDED):
|
||||
inject_advertisement_with_time_and_source(
|
||||
hass,
|
||||
|
@ -167,6 +180,10 @@ async def test_advertisment_interval_longer_than_adapter_stack_timeout_adapter_c
|
|||
"new",
|
||||
)
|
||||
|
||||
assert async_get_learned_advertising_interval(
|
||||
hass, "44:44:33:11:23:45"
|
||||
) == pytest.approx(ONE_HOUR_SECONDS)
|
||||
|
||||
switchbot_device_unavailable_cancel = async_track_unavailable(
|
||||
hass, _switchbot_device_unavailable_callback, switchbot_device.address
|
||||
)
|
||||
|
@ -216,6 +233,10 @@ async def test_advertisment_interval_longer_than_adapter_stack_timeout_not_conne
|
|||
SOURCE_LOCAL,
|
||||
)
|
||||
|
||||
assert async_get_learned_advertising_interval(
|
||||
hass, "44:44:33:11:23:45"
|
||||
) == pytest.approx(ONE_HOUR_SECONDS)
|
||||
|
||||
switchbot_device_unavailable_cancel = async_track_unavailable(
|
||||
hass,
|
||||
_switchbot_device_unavailable_callback,
|
||||
|
@ -270,6 +291,10 @@ async def test_advertisment_interval_shorter_than_adapter_stack_timeout_adapter_
|
|||
"original",
|
||||
)
|
||||
|
||||
assert async_get_learned_advertising_interval(
|
||||
hass, "44:44:33:11:23:5C"
|
||||
) == pytest.approx(ONE_HOUR_SECONDS)
|
||||
|
||||
switchbot_adv_better_rssi = generate_advertisement_data(
|
||||
local_name="wohand",
|
||||
service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"],
|
||||
|
@ -284,6 +309,10 @@ async def test_advertisment_interval_shorter_than_adapter_stack_timeout_adapter_
|
|||
"new",
|
||||
)
|
||||
|
||||
assert async_get_learned_advertising_interval(
|
||||
hass, "44:44:33:11:23:5C"
|
||||
) == pytest.approx(2.0)
|
||||
|
||||
switchbot_device_unavailable_cancel = async_track_unavailable(
|
||||
hass,
|
||||
_switchbot_device_unavailable_callback,
|
||||
|
@ -342,6 +371,10 @@ async def test_advertisment_interval_longer_than_adapter_stack_timeout_adapter_c
|
|||
connectable=False,
|
||||
)
|
||||
|
||||
assert async_get_learned_advertising_interval(
|
||||
hass, "44:44:33:11:23:45"
|
||||
) == pytest.approx(2.0)
|
||||
|
||||
switchbot_better_rssi_adv = generate_advertisement_data(
|
||||
local_name="wohand",
|
||||
service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"],
|
||||
|
@ -357,6 +390,10 @@ async def test_advertisment_interval_longer_than_adapter_stack_timeout_adapter_c
|
|||
connectable=False,
|
||||
)
|
||||
|
||||
assert async_get_learned_advertising_interval(
|
||||
hass, "44:44:33:11:23:45"
|
||||
) == pytest.approx(ONE_HOUR_SECONDS)
|
||||
|
||||
switchbot_device_unavailable_cancel = async_track_unavailable(
|
||||
hass,
|
||||
_switchbot_device_unavailable_callback,
|
||||
|
@ -437,6 +474,10 @@ async def test_advertisment_interval_longer_increasing_than_adapter_stack_timeou
|
|||
"new",
|
||||
)
|
||||
|
||||
assert async_get_learned_advertising_interval(
|
||||
hass, "44:44:33:11:23:45"
|
||||
) == pytest.approx(61.0)
|
||||
|
||||
switchbot_device_unavailable_cancel = async_track_unavailable(
|
||||
hass,
|
||||
_switchbot_device_unavailable_callback,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue