mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Handle Modalias missing from the bluetooth adapter details on older BlueZ (#78715)
This commit is contained in:
parent
1f92804211
commit
9655f30146
@ -58,7 +58,7 @@ class AdapterDetails(TypedDict, total=False):
|
|||||||
|
|
||||||
address: str
|
address: str
|
||||||
sw_version: str
|
sw_version: str
|
||||||
hw_version: str
|
hw_version: str | None
|
||||||
passive_scan: bool
|
passive_scan: bool
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ async def async_get_bluetooth_adapters() -> dict[str, AdapterDetails]:
|
|||||||
adapters[adapter] = AdapterDetails(
|
adapters[adapter] = AdapterDetails(
|
||||||
address=adapter1["Address"],
|
address=adapter1["Address"],
|
||||||
sw_version=adapter1["Name"], # This is actually the BlueZ version
|
sw_version=adapter1["Name"], # This is actually the BlueZ version
|
||||||
hw_version=adapter1["Modalias"],
|
hw_version=adapter1.get("Modalias"),
|
||||||
passive_scan="org.bluez.AdvertisementMonitorManager1" in details,
|
passive_scan="org.bluez.AdvertisementMonitorManager1" in details,
|
||||||
)
|
)
|
||||||
return adapters
|
return adapters
|
||||||
|
@ -97,3 +97,27 @@ def two_adapters_fixture(bluez_dbus_mock):
|
|||||||
},
|
},
|
||||||
):
|
):
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(name="one_adapter_old_bluez")
|
||||||
|
def one_adapter_old_bluez(bluez_dbus_mock):
|
||||||
|
"""Fixture that mocks two adapters on Linux."""
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.bluetooth.platform.system", return_value="Linux"
|
||||||
|
), patch(
|
||||||
|
"homeassistant.components.bluetooth.scanner.platform.system",
|
||||||
|
return_value="Linux",
|
||||||
|
), patch(
|
||||||
|
"homeassistant.components.bluetooth.util.platform.system", return_value="Linux"
|
||||||
|
), patch(
|
||||||
|
"bluetooth_adapters.get_bluetooth_adapter_details",
|
||||||
|
return_value={
|
||||||
|
"hci0": {
|
||||||
|
"org.bluez.Adapter1": {
|
||||||
|
"Address": "00:00:00:00:00:01",
|
||||||
|
"Name": "BlueZ 4.43",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
):
|
||||||
|
yield
|
||||||
|
@ -116,6 +116,53 @@ async def test_setup_and_stop_passive(hass, mock_bleak_scanner_start, one_adapte
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_setup_and_stop_old_bluez(
|
||||||
|
hass, mock_bleak_scanner_start, one_adapter_old_bluez
|
||||||
|
):
|
||||||
|
"""Test we and setup and stop the scanner the passive scanner with older bluez."""
|
||||||
|
entry = MockConfigEntry(
|
||||||
|
domain=bluetooth.DOMAIN,
|
||||||
|
data={},
|
||||||
|
options={},
|
||||||
|
unique_id="00:00:00:00:00:01",
|
||||||
|
)
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
init_kwargs = None
|
||||||
|
|
||||||
|
class MockBleakScanner:
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
"""Init the scanner."""
|
||||||
|
nonlocal init_kwargs
|
||||||
|
init_kwargs = kwargs
|
||||||
|
|
||||||
|
async def start(self, *args, **kwargs):
|
||||||
|
"""Start the scanner."""
|
||||||
|
|
||||||
|
async def stop(self, *args, **kwargs):
|
||||||
|
"""Stop the scanner."""
|
||||||
|
|
||||||
|
def register_detection_callback(self, *args, **kwargs):
|
||||||
|
"""Register a callback."""
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.bluetooth.scanner.OriginalBleakScanner",
|
||||||
|
MockBleakScanner,
|
||||||
|
):
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass, bluetooth.DOMAIN, {bluetooth.DOMAIN: {}}
|
||||||
|
)
|
||||||
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert init_kwargs == {
|
||||||
|
"adapter": "hci0",
|
||||||
|
"scanning_mode": "active",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_and_stop_no_bluetooth(hass, caplog, macos_adapter):
|
async def test_setup_and_stop_no_bluetooth(hass, caplog, macos_adapter):
|
||||||
"""Test we fail gracefully when bluetooth is not available."""
|
"""Test we fail gracefully when bluetooth is not available."""
|
||||||
mock_bt = [
|
mock_bt = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user