From 2beca6b322e44c466e448b9f68464177cb8ff9f4 Mon Sep 17 00:00:00 2001 From: Manu <4445816+tr4nt0r@users.noreply.github.com> Date: Wed, 1 Apr 2026 20:10:39 +0200 Subject: [PATCH] Fix websocket calling `async_release_notes` in update component although unavailable (#167067) --- homeassistant/components/update/__init__.py | 8 +++- tests/components/update/test_init.py | 43 ++++++++++++++++++--- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/update/__init__.py b/homeassistant/components/update/__init__.py index 2d9f13f02ad..200bb346c4d 100644 --- a/homeassistant/components/update/__init__.py +++ b/homeassistant/components/update/__init__.py @@ -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(), diff --git a/tests/components/update/test_init.py b/tests/components/update/test_init.py index 17ffbbc3f25..a606ef43a4c 100644 --- a/tests/components/update/test_init.py +++ b/tests/components/update/test_init.py @@ -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."""