Skip to content

Commit c28b2ac

Browse files
committed
Cover rebinding past rows still on the pruning grace
1 parent 11846c7 commit c28b2ac

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

tests/test_entity.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,34 @@ def test_rebinds_to_recreated_row_by_uniq_id(self, hass):
328328
assert entity._uid == "*9"
329329
assert entity._data[".id"] == "*9"
330330

331+
def test_rebind_skips_rows_on_the_pruning_grace(self, hass):
332+
"""With two candidate rows the entity must pick the live one."""
333+
desc = _make_entity_description(
334+
data_path="nat",
335+
data_reference="uniq-id",
336+
data_name="name",
337+
)
338+
coord = _make_coordinator(
339+
hass,
340+
data={"nat": {"*1": {".id": "*1", "name": "my rule", "uniq-id": "my rule"}}},
341+
)
342+
entity = _make_entity(coord, desc, uid="*1")
343+
344+
# *3 is a dead row still on the pruning grace, *5 is the live one.
345+
coord.data = {
346+
"nat": {
347+
"*3": {".id": "*3", "name": "my rule", "uniq-id": "my rule"},
348+
"*5": {".id": "*5", "name": "my rule", "uniq-id": "my rule"},
349+
}
350+
}
351+
coord._get_stale_counters = lambda path: {"*3": 1}
352+
353+
with contextlib.suppress(Exception):
354+
entity._handle_coordinator_update()
355+
356+
assert entity._uid == "*5"
357+
assert entity._data[".id"] == "*5"
358+
331359
def test_keeps_last_row_when_no_replacement_exists(self, hass):
332360
"""Without a matching uniq-id the entity keeps its last known row."""
333361
desc = _make_entity_description(

0 commit comments

Comments
 (0)