mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Break out the ESPHome Bluetooth scanner connection logic into bleak-esphome (#105908)
This commit is contained in:
46
tests/components/esphome/test_bluetooth.py
Normal file
46
tests/components/esphome/test_bluetooth.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""Test the ESPHome bluetooth integration."""
|
||||
|
||||
from homeassistant.components import bluetooth
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .conftest import MockESPHomeDevice
|
||||
|
||||
|
||||
async def test_bluetooth_connect_with_raw_adv(
|
||||
hass: HomeAssistant, mock_bluetooth_entry_with_raw_adv: MockESPHomeDevice
|
||||
) -> None:
|
||||
"""Test bluetooth connect with raw advertisements."""
|
||||
scanner = bluetooth.async_scanner_by_source(hass, "11:22:33:44:55:aa")
|
||||
assert scanner is not None
|
||||
assert scanner.connectable is True
|
||||
assert scanner.scanning is True
|
||||
assert scanner.connector.can_connect() is False # no connection slots
|
||||
await mock_bluetooth_entry_with_raw_adv.mock_disconnect(True)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
scanner = bluetooth.async_scanner_by_source(hass, "11:22:33:44:55:aa")
|
||||
assert scanner is None
|
||||
await mock_bluetooth_entry_with_raw_adv.mock_connect()
|
||||
await hass.async_block_till_done()
|
||||
scanner = bluetooth.async_scanner_by_source(hass, "11:22:33:44:55:aa")
|
||||
assert scanner.scanning is True
|
||||
|
||||
|
||||
async def test_bluetooth_connect_with_legacy_adv(
|
||||
hass: HomeAssistant, mock_bluetooth_entry_with_legacy_adv: MockESPHomeDevice
|
||||
) -> None:
|
||||
"""Test bluetooth connect with legacy advertisements."""
|
||||
scanner = bluetooth.async_scanner_by_source(hass, "11:22:33:44:55:aa")
|
||||
assert scanner is not None
|
||||
assert scanner.connectable is True
|
||||
assert scanner.scanning is True
|
||||
assert scanner.connector.can_connect() is False # no connection slots
|
||||
await mock_bluetooth_entry_with_legacy_adv.mock_disconnect(True)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
scanner = bluetooth.async_scanner_by_source(hass, "11:22:33:44:55:aa")
|
||||
assert scanner is None
|
||||
await mock_bluetooth_entry_with_legacy_adv.mock_connect()
|
||||
await hass.async_block_till_done()
|
||||
scanner = bluetooth.async_scanner_by_source(hass, "11:22:33:44:55:aa")
|
||||
assert scanner.scanning is True
|
||||
Reference in New Issue
Block a user