mirror of
https://github.com/home-assistant/core.git
synced 2025-07-11 15:27:08 +00:00
Copy area from remote parent device when creating Bluetooth devices (#137340)
This commit is contained in:
parent
efe8a3f530
commit
56e07efe31
@ -5,7 +5,7 @@ from __future__ import annotations
|
|||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
import platform
|
import platform
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from bleak_retry_connector import BleakSlotManager
|
from bleak_retry_connector import BleakSlotManager
|
||||||
from bluetooth_adapters import (
|
from bluetooth_adapters import (
|
||||||
@ -302,7 +302,6 @@ async def async_update_device(
|
|||||||
entry: ConfigEntry,
|
entry: ConfigEntry,
|
||||||
adapter: str,
|
adapter: str,
|
||||||
details: AdapterDetails,
|
details: AdapterDetails,
|
||||||
via_device_domain: str | None = None,
|
|
||||||
via_device_id: str | None = None,
|
via_device_id: str | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Update device registry entry.
|
"""Update device registry entry.
|
||||||
@ -322,10 +321,11 @@ async def async_update_device(
|
|||||||
sw_version=details.get(ADAPTER_SW_VERSION),
|
sw_version=details.get(ADAPTER_SW_VERSION),
|
||||||
hw_version=details.get(ADAPTER_HW_VERSION),
|
hw_version=details.get(ADAPTER_HW_VERSION),
|
||||||
)
|
)
|
||||||
if via_device_id:
|
if via_device_id and (via_device_entry := device_registry.async_get(via_device_id)):
|
||||||
device_registry.async_update_device(
|
kwargs: dict[str, Any] = {"via_device_id": via_device_id}
|
||||||
device_entry.id, via_device_id=via_device_id
|
if not device_entry.area_id and via_device_entry.area_id:
|
||||||
)
|
kwargs["area_id"] = via_device_entry.area_id
|
||||||
|
device_registry.async_update_device(device_entry.id, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
@ -360,7 +360,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
entry,
|
entry,
|
||||||
source_entry.title,
|
source_entry.title,
|
||||||
details,
|
details,
|
||||||
source_domain,
|
|
||||||
entry.data.get(CONF_SOURCE_DEVICE_ID),
|
entry.data.get(CONF_SOURCE_DEVICE_ID),
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
@ -20,7 +20,7 @@ from homeassistant.components.bluetooth.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import area_registry as ar, device_registry as dr
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from . import FakeRemoteScanner, MockBleakClient, _get_manager
|
from . import FakeRemoteScanner, MockBleakClient, _get_manager
|
||||||
@ -537,7 +537,9 @@ async def test_async_step_user_linux_adapter_is_ignored(hass: HomeAssistant) ->
|
|||||||
|
|
||||||
@pytest.mark.usefixtures("enable_bluetooth")
|
@pytest.mark.usefixtures("enable_bluetooth")
|
||||||
async def test_async_step_integration_discovery_remote_adapter(
|
async def test_async_step_integration_discovery_remote_adapter(
|
||||||
hass: HomeAssistant, device_registry: dr.DeviceRegistry
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
area_registry: ar.AreaRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test remote adapter configuration via integration discovery."""
|
"""Test remote adapter configuration via integration discovery."""
|
||||||
entry = MockConfigEntry(domain="test")
|
entry = MockConfigEntry(domain="test")
|
||||||
@ -547,10 +549,12 @@ async def test_async_step_integration_discovery_remote_adapter(
|
|||||||
)
|
)
|
||||||
scanner = FakeRemoteScanner("esp32", "esp32", connector, True)
|
scanner = FakeRemoteScanner("esp32", "esp32", connector, True)
|
||||||
manager = _get_manager()
|
manager = _get_manager()
|
||||||
|
area_entry = area_registry.async_get_or_create("test")
|
||||||
cancel_scanner = manager.async_register_scanner(scanner)
|
cancel_scanner = manager.async_register_scanner(scanner)
|
||||||
device_entry = device_registry.async_get_or_create(
|
device_entry = device_registry.async_get_or_create(
|
||||||
config_entry_id=entry.entry_id,
|
config_entry_id=entry.entry_id,
|
||||||
identifiers={("test", "BB:BB:BB:BB:BB:BB")},
|
identifiers={("test", "BB:BB:BB:BB:BB:BB")},
|
||||||
|
suggested_area=area_entry.id,
|
||||||
)
|
)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
@ -585,6 +589,7 @@ async def test_async_step_integration_discovery_remote_adapter(
|
|||||||
)
|
)
|
||||||
assert ble_device_entry is not None
|
assert ble_device_entry is not None
|
||||||
assert ble_device_entry.via_device_id == device_entry.id
|
assert ble_device_entry.via_device_id == device_entry.id
|
||||||
|
assert ble_device_entry.area_id == area_entry.id
|
||||||
|
|
||||||
await hass.config_entries.async_unload(new_entry.entry_id)
|
await hass.config_entries.async_unload(new_entry.entry_id)
|
||||||
await hass.config_entries.async_unload(entry.entry_id)
|
await hass.config_entries.async_unload(entry.entry_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user