From 2ce3cf205aae8a5ed17d89d5ffacaad09ba23319 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 11 Nov 2026 00:20:59 +0100 Subject: [PATCH] Return NONE from supports_response for missing services (#191851) Co-authored-by: Artur Pragacz <49985303+arturpragacz@users.noreply.github.com> --- homeassistant/core.py | 4 +++- tests/test_core.py | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/homeassistant/core.py b/homeassistant/core.py index 4bbe2dff977f..3d1ac6fca070 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -2752,7 +2752,9 @@ class ServiceRegistry: the context. Will return NONE if the service does not exist as there is other error handling when calling the service if it does not exist. """ - if not (handler := self._services[domain.lower()][service.lower()]): + if ( + handler := self._services.get(domain.lower(), {}).get(service.lower()) + ) is None: return SupportsResponse.NONE return handler.supports_response diff --git a/tests/test_core.py b/tests/test_core.py index 043cf5250b97..122d7620318a 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -13,7 +13,7 @@ import re import threading import time from typing import Any -from unittest.mock import MagicMock, patch +from unittest.mock import AsyncMock, MagicMock, patch from freezegun import freeze_time import probatio @@ -2018,6 +2018,37 @@ async def test_serviceregistry_callback_service_raise_exception( await hass.async_block_till_done() +@pytest.mark.parametrize( + ("domain", "service", "expected"), + [ + pytest.param( + "test_domain", "test_service", SupportsResponse.ONLY, id="registered" + ), + pytest.param( + "TEST_DOMAIN", "TEST_SERVICE", SupportsResponse.ONLY, id="mixed_case" + ), + pytest.param( + "test_domain", "other_service", SupportsResponse.NONE, id="missing_service" + ), + pytest.param( + "other_domain", "test_service", SupportsResponse.NONE, id="missing_domain" + ), + ], +) +async def test_serviceregistry_supports_response( + hass: HomeAssistant, domain: str, service: str, expected: SupportsResponse +) -> None: + """Test the response support of registered and missing services.""" + hass.services.async_register( + "test_domain", + "test_service", + AsyncMock(return_value={}), + supports_response=SupportsResponse.ONLY, + ) + + assert hass.services.supports_response(domain, service) is expected + + @pytest.mark.parametrize( "supports_response", [