mirror of
https://github.com/home-assistant/core.git
synced 2025-07-31 17:18:23 +00:00
Enable disabled devices when adding new config entry
This commit is contained in:
parent
31e9de3b95
commit
b2fd8836c9
@ -926,6 +926,12 @@ class DeviceRegistry(BaseRegistry[dict[str, list[dict[str, Any]]]]):
|
|||||||
|
|
||||||
if add_config_entry.entry_id not in old.config_entries:
|
if add_config_entry.entry_id not in old.config_entries:
|
||||||
config_entries = old.config_entries | {add_config_entry.entry_id}
|
config_entries = old.config_entries | {add_config_entry.entry_id}
|
||||||
|
if (
|
||||||
|
old.disabled_by
|
||||||
|
and not add_config_entry.disabled_by
|
||||||
|
and disabled_by is UNDEFINED
|
||||||
|
):
|
||||||
|
disabled_by = None
|
||||||
|
|
||||||
if (
|
if (
|
||||||
remove_config_entry_id is not UNDEFINED
|
remove_config_entry_id is not UNDEFINED
|
||||||
|
@ -3052,3 +3052,39 @@ async def test_primary_config_entry(
|
|||||||
model="model",
|
model="model",
|
||||||
)
|
)
|
||||||
assert device.primary_config_entry == mock_config_entry_1.entry_id
|
assert device.primary_config_entry == mock_config_entry_1.entry_id
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("disabled_by", list(dr.DeviceEntryDisabler))
|
||||||
|
async def test_add_config_entry_to_disabled_device(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
disabled_by: dr.DeviceEntryDisabler,
|
||||||
|
) -> None:
|
||||||
|
"""Test adding config entry to a disabled device."""
|
||||||
|
mock_config_entry_1 = MockConfigEntry(title=None)
|
||||||
|
mock_config_entry_1.add_to_hass(hass)
|
||||||
|
mock_config_entry_2 = MockConfigEntry(
|
||||||
|
disabled_by=config_entries.ConfigEntryDisabler.USER, title=None
|
||||||
|
)
|
||||||
|
mock_config_entry_2.add_to_hass(hass)
|
||||||
|
mock_config_entry_3 = MockConfigEntry(title=None)
|
||||||
|
mock_config_entry_3.add_to_hass(hass)
|
||||||
|
|
||||||
|
device = device_registry.async_get_or_create(
|
||||||
|
config_entry_id=mock_config_entry_1.entry_id,
|
||||||
|
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
||||||
|
disabled_by=disabled_by,
|
||||||
|
)
|
||||||
|
assert device.disabled_by == disabled_by
|
||||||
|
|
||||||
|
device = device_registry.async_update_device(
|
||||||
|
device.id, add_config_entry_id=mock_config_entry_2.entry_id
|
||||||
|
)
|
||||||
|
assert device
|
||||||
|
assert device.disabled_by == disabled_by
|
||||||
|
|
||||||
|
device = device_registry.async_update_device(
|
||||||
|
device.id, add_config_entry_id=mock_config_entry_3.entry_id
|
||||||
|
)
|
||||||
|
assert device
|
||||||
|
assert device.disabled_by is None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user