Return NONE from supports_response for missing services (#191851)

Co-authored-by: Artur Pragacz <49985303+arturpragacz@users.noreply.github.com>
This commit is contained in:
epenet
2026-11-11 00:20:59 +01:00
committed by GitHub
co-authored by Artur Pragacz
parent 13b4ea19c9
commit 2ce3cf205a
2 changed files with 35 additions and 2 deletions
+3 -1
View File
@@ -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
+32 -1
View File
@@ -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",
[