mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Add bluetooth integration (#74653)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
@@ -6,6 +6,7 @@ from time import monotonic
|
||||
|
||||
from . import (
|
||||
application_credentials,
|
||||
bluetooth,
|
||||
codeowners,
|
||||
config_flow,
|
||||
coverage,
|
||||
@@ -27,6 +28,7 @@ from .model import Config, Integration
|
||||
|
||||
INTEGRATION_PLUGINS = [
|
||||
application_credentials,
|
||||
bluetooth,
|
||||
codeowners,
|
||||
config_flow,
|
||||
dependencies,
|
||||
|
||||
65
script/hassfest/bluetooth.py
Normal file
65
script/hassfest/bluetooth.py
Normal file
@@ -0,0 +1,65 @@
|
||||
"""Generate bluetooth file."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from .model import Config, Integration
|
||||
|
||||
BASE = """
|
||||
\"\"\"Automatically generated by hassfest.
|
||||
|
||||
To update, run python3 -m script.hassfest
|
||||
\"\"\"
|
||||
from __future__ import annotations
|
||||
|
||||
# fmt: off
|
||||
|
||||
BLUETOOTH: list[dict[str, str | int]] = {}
|
||||
""".strip()
|
||||
|
||||
|
||||
def generate_and_validate(integrations: list[dict[str, str]]):
|
||||
"""Validate and generate bluetooth data."""
|
||||
match_list = []
|
||||
|
||||
for domain in sorted(integrations):
|
||||
integration = integrations[domain]
|
||||
|
||||
if not integration.manifest or not integration.config_flow:
|
||||
continue
|
||||
|
||||
match_types = integration.manifest.get("bluetooth", [])
|
||||
|
||||
if not match_types:
|
||||
continue
|
||||
|
||||
for entry in match_types:
|
||||
match_list.append({"domain": domain, **entry})
|
||||
|
||||
return BASE.format(json.dumps(match_list, indent=4))
|
||||
|
||||
|
||||
def validate(integrations: dict[str, Integration], config: Config):
|
||||
"""Validate bluetooth file."""
|
||||
bluetooth_path = config.root / "homeassistant/generated/bluetooth.py"
|
||||
config.cache["bluetooth"] = content = generate_and_validate(integrations)
|
||||
|
||||
if config.specific_integrations:
|
||||
return
|
||||
|
||||
with open(str(bluetooth_path)) as fp:
|
||||
current = fp.read().strip()
|
||||
if current != content:
|
||||
config.add_error(
|
||||
"bluetooth",
|
||||
"File bluetooth.py is not up to date. Run python3 -m script.hassfest",
|
||||
fixable=True,
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
def generate(integrations: dict[str, Integration], config: Config):
|
||||
"""Generate bluetooth file."""
|
||||
bluetooth_path = config.root / "homeassistant/generated/bluetooth.py"
|
||||
with open(str(bluetooth_path), "w") as fp:
|
||||
fp.write(f"{config.cache['bluetooth']}\n")
|
||||
@@ -35,6 +35,7 @@ def validate_integration(config: Config, integration: Integration):
|
||||
|
||||
needs_unique_id = integration.domain not in UNIQUE_ID_IGNORE and (
|
||||
"async_step_discovery" in config_flow
|
||||
or "async_step_bluetooth" in config_flow
|
||||
or "async_step_hassio" in config_flow
|
||||
or "async_step_homekit" in config_flow
|
||||
or "async_step_mqtt" in config_flow
|
||||
|
||||
@@ -190,6 +190,16 @@ MANIFEST_SCHEMA = vol.Schema(
|
||||
vol.Optional("ssdp"): vol.Schema(
|
||||
vol.All([vol.All(vol.Schema({}, extra=vol.ALLOW_EXTRA), vol.Length(min=1))])
|
||||
),
|
||||
vol.Optional("bluetooth"): [
|
||||
vol.Schema(
|
||||
{
|
||||
vol.Optional("service_uuid"): vol.All(str, verify_lowercase),
|
||||
vol.Optional("local_name"): vol.All(str),
|
||||
vol.Optional("manufacturer_id"): int,
|
||||
vol.Optional("manufacturer_data_first_byte"): int,
|
||||
}
|
||||
)
|
||||
],
|
||||
vol.Optional("homekit"): vol.Schema({vol.Optional("models"): [str]}),
|
||||
vol.Optional("dhcp"): [
|
||||
vol.Schema(
|
||||
|
||||
Reference in New Issue
Block a user