Fix handling of device registry defaults (#39688)
parent
3a36a789ad
commit
863b63d75e
|
@ -239,15 +239,14 @@ class DeviceRegistry:
|
|||
device = deleted_device.to_device_entry()
|
||||
self._add_device(device)
|
||||
|
||||
else:
|
||||
if default_manufacturer and not device.manufacturer:
|
||||
manufacturer = default_manufacturer
|
||||
if default_manufacturer is not _UNDEF and device.manufacturer is None:
|
||||
manufacturer = default_manufacturer
|
||||
|
||||
if default_model and not device.model:
|
||||
model = default_model
|
||||
if default_model is not _UNDEF and device.model is None:
|
||||
model = default_model
|
||||
|
||||
if default_name and not device.name:
|
||||
name = default_name
|
||||
if default_name is not _UNDEF and device.name is None:
|
||||
name = default_name
|
||||
|
||||
if via_device is not None:
|
||||
via = self.async_get_device({via_device}, set())
|
||||
|
|
|
@ -841,8 +841,8 @@ async def test_restore_simple_device(hass, registry, update_events):
|
|||
assert update_events[3]["device_id"] == entry3.id
|
||||
|
||||
|
||||
async def test_get_or_create_sets_default_values(hass, registry):
|
||||
"""Make sure we do not duplicate entries."""
|
||||
async def test_get_or_create_empty_then_set_default_values(hass, registry):
|
||||
"""Test creating an entry, then setting default name, model, manufacturer."""
|
||||
entry = registry.async_get_or_create(
|
||||
identifiers={("bridgeid", "0123")}, config_entry_id="1234"
|
||||
)
|
||||
|
@ -871,3 +871,60 @@ async def test_get_or_create_sets_default_values(hass, registry):
|
|||
assert entry.name == "default name 1"
|
||||
assert entry.model == "default model 1"
|
||||
assert entry.manufacturer == "default manufacturer 1"
|
||||
|
||||
|
||||
async def test_get_or_create_empty_then_update(hass, registry):
|
||||
"""Test creating an entry, then setting name, model, manufacturer."""
|
||||
entry = registry.async_get_or_create(
|
||||
identifiers={("bridgeid", "0123")}, config_entry_id="1234"
|
||||
)
|
||||
assert entry.name is None
|
||||
assert entry.model is None
|
||||
assert entry.manufacturer is None
|
||||
|
||||
entry = registry.async_get_or_create(
|
||||
config_entry_id="1234",
|
||||
identifiers={("bridgeid", "0123")},
|
||||
name="name 1",
|
||||
model="model 1",
|
||||
manufacturer="manufacturer 1",
|
||||
)
|
||||
assert entry.name == "name 1"
|
||||
assert entry.model == "model 1"
|
||||
assert entry.manufacturer == "manufacturer 1"
|
||||
|
||||
entry = registry.async_get_or_create(
|
||||
config_entry_id="1234",
|
||||
identifiers={("bridgeid", "0123")},
|
||||
default_name="default name 1",
|
||||
default_model="default model 1",
|
||||
default_manufacturer="default manufacturer 1",
|
||||
)
|
||||
assert entry.name == "name 1"
|
||||
assert entry.model == "model 1"
|
||||
assert entry.manufacturer == "manufacturer 1"
|
||||
|
||||
|
||||
async def test_get_or_create_sets_default_values(hass, registry):
|
||||
"""Test creating an entry, then setting default name, model, manufacturer."""
|
||||
entry = registry.async_get_or_create(
|
||||
config_entry_id="1234",
|
||||
identifiers={("bridgeid", "0123")},
|
||||
default_name="default name 1",
|
||||
default_model="default model 1",
|
||||
default_manufacturer="default manufacturer 1",
|
||||
)
|
||||
assert entry.name == "default name 1"
|
||||
assert entry.model == "default model 1"
|
||||
assert entry.manufacturer == "default manufacturer 1"
|
||||
|
||||
entry = registry.async_get_or_create(
|
||||
config_entry_id="1234",
|
||||
identifiers={("bridgeid", "0123")},
|
||||
default_name="default name 2",
|
||||
default_model="default model 2",
|
||||
default_manufacturer="default manufacturer 2",
|
||||
)
|
||||
assert entry.name == "default name 1"
|
||||
assert entry.model == "default model 1"
|
||||
assert entry.manufacturer == "default manufacturer 1"
|
||||
|
|
Loading…
Reference in New Issue