From 0f2dbdf4f4068127875273e88896466bb704bc88 Mon Sep 17 00:00:00 2001 From: Artur Pragacz <49985303+arturpragacz@users.noreply.github.com> Date: Thu, 12 Mar 2026 09:53:30 +0100 Subject: [PATCH] Fix logging of unavailable entities in entity call (#165370) --- homeassistant/helpers/service.py | 5 ++--- tests/helpers/test_service.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index bcb1367020c..d7484f214fb 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -782,6 +782,8 @@ async def entity_service_call( all_referenced, ) + entity_candidates = [e for e in entity_candidates if e.available] + if not target_all_entities: assert referenced is not None # Only report on explicit referenced entities @@ -792,9 +794,6 @@ async def entity_service_call( entities: list[Entity] = [] for entity in entity_candidates: - if not entity.available: - continue - # Skip entities that don't have the required device class. if ( entity_device_classes is not None diff --git a/tests/helpers/test_service.py b/tests/helpers/test_service.py index 5ebc6a51721..b8c455ddd15 100644 --- a/tests/helpers/test_service.py +++ b/tests/helpers/test_service.py @@ -2411,6 +2411,28 @@ async def test_entity_service_call_warn_referenced( ) in caplog.text +async def test_entity_service_call_warn_unavailable( + hass: HomeAssistant, + mock_entities: dict[str, MockEntity], + caplog: pytest.LogCaptureFixture, +) -> None: + """Test that explicitly referenced unavailable entities are logged.""" + mock_entities["light.kitchen"] = MockEntity( + entity_id="light.kitchen", available=False + ) + + call = ServiceCall( + hass, + "test_domain", + "test_service", + {"entity_id": ["light.kitchen"]}, + ) + await service.entity_service_call(hass, mock_entities, "", call) + assert ( + "Referenced entities light.kitchen are missing or not currently available" + ) in caplog.text + + async def test_async_extract_entities_warn_referenced( hass: HomeAssistant, caplog: pytest.LogCaptureFixture ) -> None: