Allow passing version to ConfigEntry.async_update_entry (#110077)

Allow passing minor_version and version to ConfigEntry.async_update_entry
This commit is contained in:
Erik Montnemery 2024-02-09 10:10:25 +01:00 committed by GitHub
parent 7caf78a926
commit 793b6aa97d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View File

@ -1496,12 +1496,14 @@ class ConfigEntries:
self,
entry: ConfigEntry,
*,
unique_id: str | None | UndefinedType = UNDEFINED,
title: str | UndefinedType = UNDEFINED,
data: Mapping[str, Any] | UndefinedType = UNDEFINED,
minor_version: int | UndefinedType = UNDEFINED,
options: Mapping[str, Any] | UndefinedType = UNDEFINED,
pref_disable_new_entities: bool | UndefinedType = UNDEFINED,
pref_disable_polling: bool | UndefinedType = UNDEFINED,
title: str | UndefinedType = UNDEFINED,
unique_id: str | None | UndefinedType = UNDEFINED,
version: int | UndefinedType = UNDEFINED,
) -> bool:
"""Update a config entry.
@ -1522,9 +1524,11 @@ class ConfigEntries:
changed = True
for attr, value in (
("title", title),
("minor_version", minor_version),
("pref_disable_new_entities", pref_disable_new_entities),
("pref_disable_polling", pref_disable_polling),
("title", title),
("version", version),
):
if value is UNDEFINED or getattr(entry, attr) == value:
continue

View File

@ -3199,13 +3199,18 @@ async def test_updating_entry_with_and_without_changes(
for change in (
{"data": {"second": True, "third": 456}},
{"data": {"second": True}},
{"minor_version": 2},
{"options": {"hello": True}},
{"pref_disable_new_entities": True},
{"pref_disable_polling": True},
{"title": "sometitle"},
{"unique_id": "abcd1234"},
{"version": 2},
):
assert manager.async_update_entry(entry, **change) is True
key = next(iter(change))
value = next(iter(change.values()))
assert getattr(entry, key) == value
assert manager.async_update_entry(entry, **change) is False
assert manager.async_entry_for_domain_unique_id("test", "abc123") is None