mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +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:
|
def __setattr__(self, key: str, value: Any) -> None:
|
||||||
"""Set an attribute."""
|
"""Set an attribute."""
|
||||||
if key in UPDATE_ENTRY_CONFIG_ENTRY_ATTRS:
|
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(
|
raise AttributeError(
|
||||||
"unique_id cannot be changed directly, use async_update_entry instead"
|
f"{key} cannot be changed directly, use async_update_entry instead"
|
||||||
)
|
)
|
||||||
report(
|
if key in FROZEN_CONFIG_ENTRY_ATTRS:
|
||||||
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,
|
|
||||||
)
|
|
||||||
|
|
||||||
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
|
|
||||||
raise AttributeError(f"{key} cannot be changed")
|
raise AttributeError(f"{key} cannot be changed")
|
||||||
|
|
||||||
super().__setattr__(key, value)
|
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
|
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_api: MagicMock
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the Android TV Remote media player receives push updates and state is updated."""
|
"""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)
|
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)
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||||
|
|
||||||
@ -322,7 +323,7 @@ async def test_browse_media(
|
|||||||
mock_api: MagicMock,
|
mock_api: MagicMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the Android TV Remote media player browse media."""
|
"""Test the Android TV Remote media player browse media."""
|
||||||
mock_config_entry.options = {
|
new_options = {
|
||||||
"apps": {
|
"apps": {
|
||||||
"com.google.android.youtube.tv": {
|
"com.google.android.youtube.tv": {
|
||||||
"app_name": "YouTube",
|
"app_name": "YouTube",
|
||||||
@ -332,6 +333,7 @@ async def test_browse_media(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
mock_config_entry.add_to_hass(hass)
|
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)
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
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
|
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_api: MagicMock
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the Android TV Remote receives push updates and state is updated."""
|
"""Test the Android TV Remote receives push updates and state is updated."""
|
||||||
mock_config_entry.options = {
|
new_options = {"apps": {"com.google.android.youtube.tv": {"app_name": "YouTube"}}}
|
||||||
"apps": {"com.google.android.youtube.tv": {"app_name": "YouTube"}}
|
|
||||||
}
|
|
||||||
mock_config_entry.add_to_hass(hass)
|
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)
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
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
|
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_api: MagicMock
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the Android TV Remote toggles."""
|
"""Test the Android TV Remote toggles."""
|
||||||
mock_config_entry.options = {
|
new_options = {"apps": {"com.google.android.youtube.tv": {"app_name": "YouTube"}}}
|
||||||
"apps": {"com.google.android.youtube.tv": {"app_name": "YouTube"}}
|
|
||||||
}
|
|
||||||
mock_config_entry.add_to_hass(hass)
|
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)
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||||
|
|
||||||
|
@ -482,8 +482,10 @@ async def test_message_history_unlimited(
|
|||||||
"ollama.AsyncClient.chat",
|
"ollama.AsyncClient.chat",
|
||||||
return_value={"message": {"role": "assistant", "content": "test response"}},
|
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):
|
for i in range(100):
|
||||||
result = await conversation.async_converse(
|
result = await conversation.async_converse(
|
||||||
hass,
|
hass,
|
||||||
|
@ -5437,14 +5437,9 @@ async def test_report_direct_mutation_of_config_entry(
|
|||||||
entry = MockConfigEntry(domain="test")
|
entry = MockConfigEntry(domain="test")
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
with pytest.raises(AttributeError):
|
||||||
setattr(entry, field, "new_value")
|
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
|
|
||||||
|
|
||||||
|
|
||||||
async def test_updating_non_added_entry_raises(hass: HomeAssistant) -> None:
|
async def test_updating_non_added_entry_raises(hass: HomeAssistant) -> None:
|
||||||
"""Test updating a non added entry raises UnknownEntry."""
|
"""Test updating a non added entry raises UnknownEntry."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user