From 793b6aa97da9055df9d23f7deb3a02b139e82a74 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Fri, 9 Feb 2024 10:10:25 +0100 Subject: [PATCH] Allow passing version to ConfigEntry.async_update_entry (#110077) Allow passing minor_version and version to ConfigEntry.async_update_entry --- homeassistant/config_entries.py | 10 +++++++--- tests/test_config_entries.py | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index cfb18505813..770693289b1 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -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 diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index 609f80e1a60..e7115957e13 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -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