mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Late review for honeywell (#100299)
* Late review for honeywell * Actually test same id different domain * Update homeassistant/components/honeywell/climate.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update climate.py * Refactor dont_remove --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
547f32818c
commit
c265d3f3cc
@ -111,18 +111,23 @@ def remove_stale_devices(
|
||||
device_entries = dr.async_entries_for_config_entry(
|
||||
device_registry, config_entry.entry_id
|
||||
)
|
||||
all_device_ids: list = []
|
||||
all_device_ids: set = set()
|
||||
for device in devices.values():
|
||||
all_device_ids.append(device.deviceid)
|
||||
all_device_ids.add(device.deviceid)
|
||||
|
||||
for device_entry in device_entries:
|
||||
device_id: str | None = None
|
||||
remove = True
|
||||
|
||||
for identifier in device_entry.identifiers:
|
||||
if identifier[0] != DOMAIN:
|
||||
remove = False
|
||||
continue
|
||||
|
||||
device_id = identifier[1]
|
||||
break
|
||||
|
||||
if device_id is None or device_id not in all_device_ids:
|
||||
if remove and (device_id is None or device_id not in all_device_ids):
|
||||
# If device_id is None an invalid device entry was found for this config entry.
|
||||
# If the device_id is not in existing device ids it's a stale device entry.
|
||||
# Remove config entry from this device entry in either case.
|
||||
|
@ -130,7 +130,15 @@ async def test_remove_stale_device(
|
||||
) -> None:
|
||||
"""Test that the stale device is removed."""
|
||||
location.devices_by_id[another_device.deviceid] = another_device
|
||||
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device_registry.async_get_or_create(
|
||||
config_entry_id=config_entry.entry_id,
|
||||
identifiers={("OtherDomain", 7654321)},
|
||||
)
|
||||
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
@ -142,9 +150,12 @@ async def test_remove_stale_device(
|
||||
device_entry = dr.async_entries_for_config_entry(
|
||||
device_registry, config_entry.entry_id
|
||||
)
|
||||
assert len(device_entry) == 2
|
||||
assert len(device_entry) == 3
|
||||
assert any((DOMAIN, 1234567) in device.identifiers for device in device_entry)
|
||||
assert any((DOMAIN, 7654321) in device.identifiers for device in device_entry)
|
||||
assert any(
|
||||
("OtherDomain", 7654321) in device.identifiers for device in device_entry
|
||||
)
|
||||
|
||||
assert await config_entry.async_unload(hass)
|
||||
await hass.async_block_till_done()
|
||||
@ -162,5 +173,8 @@ async def test_remove_stale_device(
|
||||
device_entry = dr.async_entries_for_config_entry(
|
||||
device_registry, config_entry.entry_id
|
||||
)
|
||||
assert len(device_entry) == 1
|
||||
assert len(device_entry) == 2
|
||||
assert any((DOMAIN, 1234567) in device.identifiers for device in device_entry)
|
||||
assert any(
|
||||
("OtherDomain", 7654321) in device.identifiers for device in device_entry
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user