mirror of
https://github.com/home-assistant/core.git
synced 2025-04-22 16:27:56 +00:00
End deprecation setting attributes directly on config entry (#123729)
* End deprecation setting attr directly on config entry * Update ollama test * Fix android_tv
This commit is contained in:
parent
7c15075231
commit
436ac72b82
@ -434,26 +434,10 @@ class ConfigEntry(Generic[_DataT]):
|
||||
def __setattr__(self, key: str, value: Any) -> None:
|
||||
"""Set an attribute."""
|
||||
if key in UPDATE_ENTRY_CONFIG_ENTRY_ATTRS:
|
||||
if key == "unique_id":
|
||||
# Setting unique_id directly will corrupt internal state
|
||||
# There is no deprecation period for this key
|
||||
# as changing them will corrupt internal state
|
||||
# so we raise an error here
|
||||
raise AttributeError(
|
||||
"unique_id cannot be changed directly, use async_update_entry instead"
|
||||
)
|
||||
report(
|
||||
f'sets "{key}" directly to update a config entry. This is deprecated and will'
|
||||
" stop working in Home Assistant 2024.9, it should be updated to use"
|
||||
" async_update_entry instead",
|
||||
error_if_core=False,
|
||||
raise AttributeError(
|
||||
f"{key} cannot be changed directly, use async_update_entry instead"
|
||||
)
|
||||
|
||||
elif key in FROZEN_CONFIG_ENTRY_ATTRS:
|
||||
# These attributes are frozen and cannot be changed
|
||||
# There is no deprecation period for these
|
||||
# as changing them will corrupt internal state
|
||||
# so we raise an error here
|
||||
if key in FROZEN_CONFIG_ENTRY_ATTRS:
|
||||
raise AttributeError(f"{key} cannot be changed")
|
||||
|
||||
super().__setattr__(key, value)
|
||||
|
@ -20,10 +20,11 @@ async def test_media_player_receives_push_updates(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_api: MagicMock
|
||||
) -> None:
|
||||
"""Test the Android TV Remote media player receives push updates and state is updated."""
|
||||
mock_config_entry.options = {
|
||||
"apps": {"com.google.android.youtube.tv": {"app_name": "YouTube"}}
|
||||
}
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
hass.config_entries.async_update_entry(
|
||||
mock_config_entry,
|
||||
options={"apps": {"com.google.android.youtube.tv": {"app_name": "YouTube"}}},
|
||||
)
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
@ -322,7 +323,7 @@ async def test_browse_media(
|
||||
mock_api: MagicMock,
|
||||
) -> None:
|
||||
"""Test the Android TV Remote media player browse media."""
|
||||
mock_config_entry.options = {
|
||||
new_options = {
|
||||
"apps": {
|
||||
"com.google.android.youtube.tv": {
|
||||
"app_name": "YouTube",
|
||||
@ -332,6 +333,7 @@ async def test_browse_media(
|
||||
}
|
||||
}
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
hass.config_entries.async_update_entry(mock_config_entry, options=new_options)
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
|
@ -19,10 +19,9 @@ async def test_remote_receives_push_updates(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_api: MagicMock
|
||||
) -> None:
|
||||
"""Test the Android TV Remote receives push updates and state is updated."""
|
||||
mock_config_entry.options = {
|
||||
"apps": {"com.google.android.youtube.tv": {"app_name": "YouTube"}}
|
||||
}
|
||||
new_options = {"apps": {"com.google.android.youtube.tv": {"app_name": "YouTube"}}}
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
hass.config_entries.async_update_entry(mock_config_entry, options=new_options)
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
@ -53,10 +52,9 @@ async def test_remote_toggles(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_api: MagicMock
|
||||
) -> None:
|
||||
"""Test the Android TV Remote toggles."""
|
||||
mock_config_entry.options = {
|
||||
"apps": {"com.google.android.youtube.tv": {"app_name": "YouTube"}}
|
||||
}
|
||||
new_options = {"apps": {"com.google.android.youtube.tv": {"app_name": "YouTube"}}}
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
hass.config_entries.async_update_entry(mock_config_entry, options=new_options)
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
|
@ -482,8 +482,10 @@ async def test_message_history_unlimited(
|
||||
"ollama.AsyncClient.chat",
|
||||
return_value={"message": {"role": "assistant", "content": "test response"}},
|
||||
),
|
||||
patch.object(mock_config_entry, "options", {ollama.CONF_MAX_HISTORY: 0}),
|
||||
):
|
||||
hass.config_entries.async_update_entry(
|
||||
mock_config_entry, options={ollama.CONF_MAX_HISTORY: 0}
|
||||
)
|
||||
for i in range(100):
|
||||
result = await conversation.async_converse(
|
||||
hass,
|
||||
|
@ -5437,13 +5437,8 @@ async def test_report_direct_mutation_of_config_entry(
|
||||
entry = MockConfigEntry(domain="test")
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
setattr(entry, field, "new_value")
|
||||
|
||||
assert (
|
||||
f'Detected code that sets "{field}" directly to update a config entry. '
|
||||
"This is deprecated and will stop working in Home Assistant 2024.9, "
|
||||
"it should be updated to use async_update_entry instead. Please report this issue."
|
||||
) in caplog.text
|
||||
with pytest.raises(AttributeError):
|
||||
setattr(entry, field, "new_value")
|
||||
|
||||
|
||||
async def test_updating_non_added_entry_raises(hass: HomeAssistant) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user