mirror of
https://github.com/home-assistant/core.git
synced 2025-08-05 05:35:11 +02:00
Fixes
This commit is contained in:
@@ -3384,6 +3384,34 @@ class ConfigSubentryFlow(
|
||||
|
||||
return result
|
||||
|
||||
@callback
|
||||
def _async_update(
|
||||
self,
|
||||
entry: ConfigEntry,
|
||||
subentry: ConfigSubentry,
|
||||
*,
|
||||
unique_id: str | None | UndefinedType = UNDEFINED,
|
||||
title: str | UndefinedType = UNDEFINED,
|
||||
data: Mapping[str, Any] | UndefinedType = UNDEFINED,
|
||||
data_updates: Mapping[str, Any] | UndefinedType = UNDEFINED,
|
||||
) -> bool:
|
||||
"""Update config subentry and return result.
|
||||
|
||||
Internal to be used by update_and_abort and update_reload_and_abort methods only.
|
||||
"""
|
||||
|
||||
if data_updates is not UNDEFINED:
|
||||
if data is not UNDEFINED:
|
||||
raise ValueError("Cannot set both data and data_updates")
|
||||
data = subentry.data | data_updates
|
||||
return self.hass.config_entries.async_update_subentry(
|
||||
entry=entry,
|
||||
subentry=subentry,
|
||||
unique_id=unique_id,
|
||||
title=title,
|
||||
data=data,
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_update_and_abort(
|
||||
self,
|
||||
@@ -3403,16 +3431,13 @@ class ConfigSubentryFlow(
|
||||
:param title: replace the title of the subentry
|
||||
:param unique_id: replace the unique_id of the subentry
|
||||
"""
|
||||
if data_updates is not UNDEFINED:
|
||||
if data is not UNDEFINED:
|
||||
raise ValueError("Cannot set both data and data_updates")
|
||||
data = subentry.data | data_updates
|
||||
self.hass.config_entries.async_update_subentry(
|
||||
self._async_update(
|
||||
entry=entry,
|
||||
subentry=subentry,
|
||||
unique_id=unique_id,
|
||||
title=title,
|
||||
data=data,
|
||||
data_updates=data_updates,
|
||||
)
|
||||
return self.async_abort(reason="reconfigure_successful")
|
||||
|
||||
@@ -3438,7 +3463,7 @@ class ConfigSubentryFlow(
|
||||
:param reload_even_if_entry_is_unchanged: set this to `False` if the entry
|
||||
should not be reloaded if it is unchanged
|
||||
"""
|
||||
result = self.async_update_and_abort(
|
||||
result = self._async_update(
|
||||
entry=entry,
|
||||
subentry=subentry,
|
||||
unique_id=unique_id,
|
||||
@@ -3446,9 +3471,9 @@ class ConfigSubentryFlow(
|
||||
data=data,
|
||||
data_updates=data_updates,
|
||||
)
|
||||
if reload_even_if_entry_is_unchanged or result:
|
||||
if reload_even_if_entry_is_unchanged or result is True:
|
||||
self.hass.config_entries.async_schedule_reload(entry.entry_id)
|
||||
return result
|
||||
return self.async_abort(reason="reconfigure_successful")
|
||||
|
||||
@property
|
||||
def _entry_id(self) -> str:
|
||||
|
@@ -6527,6 +6527,7 @@ async def test_update_subentry_and_abort(
|
||||
"expected_data",
|
||||
"raises",
|
||||
"reload", # True is default
|
||||
"setup_call_count",
|
||||
),
|
||||
[
|
||||
(
|
||||
@@ -6540,6 +6541,7 @@ async def test_update_subentry_and_abort(
|
||||
{"vendor": "data2"},
|
||||
None,
|
||||
True,
|
||||
2,
|
||||
),
|
||||
(
|
||||
{
|
||||
@@ -6552,6 +6554,7 @@ async def test_update_subentry_and_abort(
|
||||
{"vendor": "data"},
|
||||
None,
|
||||
True,
|
||||
2,
|
||||
),
|
||||
(
|
||||
{
|
||||
@@ -6564,6 +6567,7 @@ async def test_update_subentry_and_abort(
|
||||
{"vendor": "data"},
|
||||
None,
|
||||
False,
|
||||
1,
|
||||
),
|
||||
(
|
||||
{},
|
||||
@@ -6572,6 +6576,7 @@ async def test_update_subentry_and_abort(
|
||||
{"vendor": "data"},
|
||||
None,
|
||||
True,
|
||||
2,
|
||||
),
|
||||
(
|
||||
{
|
||||
@@ -6582,6 +6587,7 @@ async def test_update_subentry_and_abort(
|
||||
{"buyer": "me"},
|
||||
None,
|
||||
True,
|
||||
2,
|
||||
),
|
||||
(
|
||||
{"data_updates": {"buyer": "me"}},
|
||||
@@ -6590,6 +6596,7 @@ async def test_update_subentry_and_abort(
|
||||
{"vendor": "data", "buyer": "me"},
|
||||
None,
|
||||
True,
|
||||
2,
|
||||
),
|
||||
(
|
||||
{
|
||||
@@ -6603,6 +6610,7 @@ async def test_update_subentry_and_abort(
|
||||
{"vendor": "data"},
|
||||
ValueError,
|
||||
True,
|
||||
1,
|
||||
),
|
||||
],
|
||||
ids=[
|
||||
@@ -6623,6 +6631,7 @@ async def test_update_subentry_reload_and_abort(
|
||||
kwargs: dict[str, Any],
|
||||
raises: type[Exception] | None,
|
||||
reload: bool,
|
||||
setup_call_count: int,
|
||||
) -> None:
|
||||
"""Test updating an entry and reloading."""
|
||||
subentry_id = "blabla"
|
||||
@@ -6686,11 +6695,10 @@ async def test_update_subentry_reload_and_abort(
|
||||
assert subentry.title == expected_title
|
||||
assert subentry.unique_id == expected_unique_id
|
||||
assert subentry.data == expected_data
|
||||
assert setup_entry.call_count == setup_call_count
|
||||
if raises:
|
||||
assert setup_entry.call_count == 1
|
||||
assert isinstance(err, raises)
|
||||
else:
|
||||
assert setup_entry.call_count == 2
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "reconfigure_successful"
|
||||
|
||||
|
Reference in New Issue
Block a user