mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Fix device reg considered changed (#17764)
* Fix device reg considered changed * Better syntax
This commit is contained in:
parent
b6e8cafdea
commit
b5284aa445
@ -87,8 +87,8 @@ class DeviceRegistry:
|
||||
device.id,
|
||||
add_config_entry_id=config_entry_id,
|
||||
hub_device_id=hub_device_id,
|
||||
merge_connections=connections,
|
||||
merge_identifiers=identifiers,
|
||||
merge_connections=connections or _UNDEF,
|
||||
merge_identifiers=identifiers or _UNDEF,
|
||||
manufacturer=manufacturer,
|
||||
model=model,
|
||||
name=name,
|
||||
@ -128,7 +128,8 @@ class DeviceRegistry:
|
||||
('identifiers', merge_identifiers),
|
||||
):
|
||||
old_value = getattr(old, attr_name)
|
||||
if value is not _UNDEF and value != old_value:
|
||||
# If not undefined, check if `value` contains new items.
|
||||
if value is not _UNDEF and not value.issubset(old_value):
|
||||
changes[attr_name] = old_value | value
|
||||
|
||||
for attr_name, value in (
|
||||
|
@ -1,4 +1,6 @@
|
||||
"""Tests for the Device Registry."""
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.helpers import device_registry
|
||||
@ -239,3 +241,21 @@ async def test_loading_saving_data(hass, registry):
|
||||
|
||||
assert orig_hub == new_hub
|
||||
assert orig_light == new_light
|
||||
|
||||
|
||||
async def test_no_unnecessary_changes(registry):
|
||||
"""Make sure we do not consider devices changes."""
|
||||
entry = registry.async_get_or_create(
|
||||
config_entry_id='1234',
|
||||
connections={('ethernet', '12:34:56:78:90:AB:CD:EF')},
|
||||
identifiers={('hue', '456'), ('bla', '123')},
|
||||
)
|
||||
with patch('homeassistant.helpers.device_registry'
|
||||
'.DeviceRegistry.async_schedule_save') as mock_save:
|
||||
entry2 = registry.async_get_or_create(
|
||||
config_entry_id='1234',
|
||||
identifiers={('hue', '456')},
|
||||
)
|
||||
|
||||
assert entry.id == entry2.id
|
||||
assert len(mock_save.mock_calls) == 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user