1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-02 00:20:30 +01:00

Fix websocket calling async_release_notes in update component although unavailable (#167067)

This commit is contained in:
Manu
2026-04-01 20:10:39 +02:00
committed by GitHub
parent 0fc62c3150
commit 2beca6b322
2 changed files with 45 additions and 6 deletions

View File

@@ -531,7 +531,13 @@ async def websocket_release_notes(
"Entity does not support release notes",
)
return
if entity.available is False:
connection.send_error(
msg["id"],
websocket_api.ERR_HOME_ASSISTANT_ERROR,
"Entity is not available",
)
return
connection.send_result(
msg["id"],
await entity.async_release_notes(),

View File

@@ -48,6 +48,8 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.helpers.event import async_track_state_change_event
from homeassistant.setup import async_setup_component
from .common import MockUpdateEntity
from tests.common import (
MockConfigEntry,
MockEntityPlatform,
@@ -64,13 +66,9 @@ from tests.typing import WebSocketGenerator
TEST_DOMAIN = "test"
class MockUpdateEntity(UpdateEntity):
"""Mock UpdateEntity to use in tests."""
async def test_update(hass: HomeAssistant) -> None:
"""Test getting data from the mocked update entity."""
update = MockUpdateEntity()
update = UpdateEntity()
update.hass = hass
update.platform = MockEntityPlatform(hass)
@@ -797,6 +795,41 @@ async def test_release_notes_entity_does_not_support_release_notes(
assert result["error"]["message"] == "Entity does not support release notes"
async def test_release_notes_entity_unavailable(
hass: HomeAssistant,
mock_update_entities: list[MockUpdateEntity],
hass_ws_client: WebSocketGenerator,
) -> None:
"""Test getting the release notes for entity that is unavailable."""
entity = MockUpdateEntity(
name="Update unavailable",
unique_id="unavailable",
installed_version="1.0.0",
latest_version="1.0.1",
available=False,
supported_features=UpdateEntityFeature.RELEASE_NOTES,
)
setup_test_component_platform(hass, DOMAIN, [entity])
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
client = await hass_ws_client(hass)
await hass.async_block_till_done()
await client.send_json(
{
"id": 1,
"type": "update/release_notes",
"entity_id": "update.update_unavailable",
}
)
result = await client.receive_json()
assert result["error"]["code"] == "home_assistant_error"
assert result["error"]["message"] == "Entity is not available"
class MockFlow(ConfigFlow):
"""Test flow."""