Skip to content

Commit

Permalink
Ensure remote bluetooth adapters are loaded before integrations that …
Browse files Browse the repository at this point in the history
…need them (#85723)
  • Loading branch information
bdraco authored Jan 15, 2023
1 parent cd31624 commit 65ca62c
Show file tree
Hide file tree
Showing 40 changed files with 103 additions and 31 deletions.
2 changes: 2 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ build.json @home-assistant/supervisor
/homeassistant/components/bluesound/ @thrawnarn
/homeassistant/components/bluetooth/ @bdraco
/tests/components/bluetooth/ @bdraco
/homeassistant/components/bluetooth_adapters/ @bdraco
/tests/components/bluetooth_adapters/ @bdraco
/homeassistant/components/bmw_connected_drive/ @gerard33 @rikroe
/tests/components/bmw_connected_drive/ @gerard33 @rikroe
/homeassistant/components/bond/ @bdraco @prystupa @joshs85 @marciogranzotto
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/airthings_ble/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/airthings_ble",
"requirements": ["airthings-ble==0.5.3"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@vincegio"],
"iot_class": "local_polling",
"bluetooth": [
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/aranet/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/aranet",
"requirements": ["aranet4==2.1.3"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@aschmitz"],
"iot_class": "local_push",
"integration_type": "device",
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/bluemaestro/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"requirements": ["bluemaestro-ble==0.2.1"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@bdraco"],
"iot_class": "local_push"
}
20 changes: 20 additions & 0 deletions homeassistant/components/bluetooth_adapters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""The Bluetooth Adapters integration."""
from __future__ import annotations

from homeassistant.core import HomeAssistant
from homeassistant.helpers.typing import ConfigType

DOMAIN = "bluetooth_adapters"


async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up Bluetooth Adapters from a config entry.
This integration is only used as a dependency for other integrations
that need Bluetooth Adapters.
All integrations that provide Bluetooth Adapters must be listed
in after_dependencies in the manifest.json file to ensure
they are loaded before this integration.
"""
return True
11 changes: 11 additions & 0 deletions homeassistant/components/bluetooth_adapters/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"domain": "bluetooth_adapters",
"name": "Bluetooth Adapters",
"documentation": "https://www.home-assistant.io/integrations/bluetooth_adapters",
"dependencies": ["bluetooth"],
"after_dependencies": ["esphome", "shelly", "ruuvi_gateway"],
"quality_scale": "internal",
"codeowners": ["@bdraco"],
"iot_class": "local_push",
"integration_type": "system"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"domain": "bluetooth_le_tracker",
"name": "Bluetooth LE Tracker",
"documentation": "https://www.home-assistant.io/integrations/bluetooth_le_tracker",
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": [],
"iot_class": "local_push",
"loggers": []
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/bthome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"requirements": ["bthome-ble==2.5.0"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@Ernst79"],
"iot_class": "local_push"
}
2 changes: 1 addition & 1 deletion homeassistant/components/eq3btsmart/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "eQ-3 Bluetooth Smart Thermostats",
"documentation": "https://www.home-assistant.io/integrations/eq3btsmart",
"requirements": ["construct==2.10.56", "python-eq3bt==0.2"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@rytilahti"],
"iot_class": "local_polling",
"loggers": ["bleak", "eq3bt"]
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/fjaraskupan/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"codeowners": ["@elupus"],
"iot_class": "local_polling",
"loggers": ["bleak", "fjaraskupan"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"bluetooth": [
{
"connectable": false,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/govee_ble/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
}
],
"requirements": ["govee-ble==0.21.0"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@bdraco", "@PierreAronnax"],
"iot_class": "local_push"
}
2 changes: 1 addition & 1 deletion homeassistant/components/homekit_controller/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"requirements": ["aiohomekit==2.4.4"],
"zeroconf": ["_hap._tcp.local.", "_hap._udp.local."],
"bluetooth": [{ "manufacturer_id": 76, "manufacturer_data_start": [6] }],
"dependencies": ["bluetooth", "zeroconf"],
"dependencies": ["bluetooth_adapters", "zeroconf"],
"codeowners": ["@Jc2k", "@bdraco"],
"iot_class": "local_push",
"loggers": ["aiohomekit", "commentjson"]
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/ibeacon/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"domain": "ibeacon",
"name": "iBeacon Tracker",
"documentation": "https://www.home-assistant.io/integrations/ibeacon",
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"bluetooth": [{ "manufacturer_id": 76, "manufacturer_data_start": [2, 21] }],
"requirements": ["ibeacon_ble==1.0.1"],
"codeowners": ["@bdraco"],
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/inkbird/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{ "local_name": "tps", "connectable": false }
],
"requirements": ["inkbird-ble==0.5.5"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@bdraco"],
"iot_class": "local_push"
}
2 changes: 1 addition & 1 deletion homeassistant/components/kegtron/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"requirements": ["kegtron-ble==0.4.0"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@Ernst79"],
"iot_class": "local_push"
}
2 changes: 1 addition & 1 deletion homeassistant/components/keymitt_ble/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"codeowners": ["@spycle"],
"requirements": ["PyMicroBot==0.0.8"],
"iot_class": "assumed_state",
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"loggers": ["keymitt_ble"]
}
2 changes: 1 addition & 1 deletion homeassistant/components/ld2410_ble/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/ld2410_ble/",
"requirements": ["bluetooth-data-tools==0.3.1", "ld2410-ble==0.1.1"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@930913"],
"bluetooth": [{ "local_name": "HLK-LD2410B_*" }],
"integration_type": "device",
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/led_ble/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/led_ble/",
"requirements": ["bluetooth-data-tools==0.3.1", "led-ble==1.0.0"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@bdraco"],
"bluetooth": [
{ "local_name": "LEDnet*" },
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/melnor/manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"after_dependencies": ["bluetooth"],
"bluetooth": [
{
"manufacturer_data_start": [89],
"manufacturer_id": 13
}
],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@vanstinator"],
"config_flow": true,
"domain": "melnor",
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/moat/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"documentation": "https://www.home-assistant.io/integrations/moat",
"bluetooth": [{ "local_name": "Moat_S*", "connectable": false }],
"requirements": ["moat-ble==0.1.1"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@bdraco"],
"iot_class": "local_push"
}
2 changes: 1 addition & 1 deletion homeassistant/components/oralb/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
],
"requirements": ["oralb-ble==0.17.1"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@bdraco", "@conway20"],
"iot_class": "local_push"
}
2 changes: 1 addition & 1 deletion homeassistant/components/qingping/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"requirements": ["qingping-ble==0.8.2"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@bdraco", "@skgsergio"],
"iot_class": "local_push"
}
1 change: 1 addition & 0 deletions homeassistant/components/ruuvi_gateway/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/ruuvi_gateway",
"codeowners": ["@akx"],
"dependencies": ["bluetooth"],
"requirements": ["aioruuvigateway==0.0.2"],
"iot_class": "local_polling",
"dhcp": [
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/ruuvitag_ble/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"requirements": ["ruuvitag-ble==0.1.1"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@akx"],
"iot_class": "local_push"
}
2 changes: 1 addition & 1 deletion homeassistant/components/sensirion_ble/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"requirements": ["sensirion-ble==0.0.1"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@akx"],
"iot_class": "local_push"
}
2 changes: 1 addition & 1 deletion homeassistant/components/sensorpro/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"requirements": ["sensorpro-ble==0.5.1"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@bdraco"],
"iot_class": "local_push"
}
2 changes: 1 addition & 1 deletion homeassistant/components/sensorpush/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"requirements": ["sensorpush-ble==1.5.2"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@bdraco"],
"iot_class": "local_push"
}
2 changes: 1 addition & 1 deletion homeassistant/components/snooz/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/snooz",
"requirements": ["pysnooz==0.8.3"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@AustinBrunkhorst"],
"bluetooth": [
{
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/switchbot/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"documentation": "https://www.home-assistant.io/integrations/switchbot",
"requirements": ["PySwitchbot==0.36.4"],
"config_flow": true,
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": [
"@bdraco",
"@danielhiversen",
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/thermobeacon/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
{ "local_name": "ThermoBeacon", "connectable": false }
],
"requirements": ["thermobeacon-ble==0.6.0"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@bdraco"],
"iot_class": "local_push"
}
2 changes: 1 addition & 1 deletion homeassistant/components/thermopro/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{ "local_name": "TP35*", "connectable": false },
{ "local_name": "TP39*", "connectable": false }
],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"requirements": ["thermopro-ble==0.4.3"],
"codeowners": ["@bdraco"],
"iot_class": "local_push"
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/tilt_ble/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"requirements": ["tilt-ble==0.2.3"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@apt-itude"],
"iot_class": "local_push"
}
2 changes: 1 addition & 1 deletion homeassistant/components/xiaomi_ble/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"requirements": ["xiaomi-ble==0.14.3"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@Jc2k", "@Ernst79"],
"iot_class": "local_push"
}
2 changes: 1 addition & 1 deletion homeassistant/components/yalexs_ble/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/yalexs_ble",
"requirements": ["yalexs-ble==1.12.5"],
"dependencies": ["bluetooth"],
"dependencies": ["bluetooth_adapters"],
"codeowners": ["@bdraco"],
"bluetooth": [
{
Expand Down
6 changes: 6 additions & 0 deletions script/hassfest/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ def calc_allowed_references(integration: Integration) -> set[str]:
| set(manifest.get("dependencies", []))
| set(manifest.get("after_dependencies", []))
)
# bluetooth_adapters is a wrapper to ensure
# that all the integrations that provide bluetooth
# adapters are setup before loading integrations
# that use them.
if "bluetooth_adapters" in allowed_references:
allowed_references.add("bluetooth")

# Discovery requirements are ok if referenced in manifest
for check_domain, to_check in DISCOVERY_INTEGRATIONS.items():
Expand Down
1 change: 1 addition & 0 deletions tests/components/bluetooth_adapters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Tests for the Bluetooth Adapters integration."""
8 changes: 8 additions & 0 deletions tests/components/bluetooth_adapters/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""bluetooth_adapters session fixtures."""

import pytest


@pytest.fixture(autouse=True)
def mock_bluetooth(enable_bluetooth):
"""Auto mock bluetooth."""
10 changes: 10 additions & 0 deletions tests/components/bluetooth_adapters/test_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Test the Bluetooth Adapters setup."""

from homeassistant.components.bluetooth_adapters import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component


async def test_setup(hass: HomeAssistant) -> None:
"""Ensure we can setup."""
assert await async_setup_component(hass, DOMAIN, {})
7 changes: 6 additions & 1 deletion tests/components/melnor/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Tests for the melnor integration."""

from __future__ import annotations

from unittest.mock import AsyncMock, patch

from bleak.backends.device import BLEDevice
from melnor_bluetooth.device import Device
import pytest

from homeassistant.components.bluetooth.models import BluetoothServiceInfoBleak
from homeassistant.components.melnor.const import DOMAIN
Expand Down Expand Up @@ -52,6 +52,11 @@
)


@pytest.fixture(autouse=True)
def mock_bluetooth(enable_bluetooth):
"""Auto mock bluetooth."""


class MockedValve:
"""Mocked class for a Valve."""

Expand Down
8 changes: 8 additions & 0 deletions tests/components/ruuvi_gateway/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""ruuvi_gateway session fixtures."""

import pytest


@pytest.fixture(autouse=True)
def mock_bluetooth(enable_bluetooth):
"""Auto mock bluetooth."""

0 comments on commit 65ca62c

Please sign in to comment.