From 6ac025c0b3f465815668a38062a09ee014e4480d Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 2 Jun 2025 15:57:18 +0000 Subject: [PATCH] Use deprecated_function --- .../components/simplisafe/__init__.py | 7 +++--- homeassistant/helpers/service.py | 2 ++ tests/helpers/test_service.py | 23 ++++++++++++------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/simplisafe/__init__.py b/homeassistant/components/simplisafe/__init__.py index cabfc57d967..5384d228a58 100644 --- a/homeassistant/components/simplisafe/__init__.py +++ b/homeassistant/components/simplisafe/__init__.py @@ -290,7 +290,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up SimpliSafe as config entry.""" _async_standardize_config_entry(hass, entry) - _verify_domain_control = verify_domain_entity_control(DOMAIN) websession = aiohttp_client.async_get_clientsession(hass) try: @@ -334,19 +333,19 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: return wrapper - @_verify_domain_control + @verify_domain_entity_control(DOMAIN) @extract_system async def async_remove_pin(call: ServiceCall, system: SystemType) -> None: """Remove a PIN.""" await system.async_remove_pin(call.data[ATTR_PIN_LABEL_OR_VALUE]) - @_verify_domain_control + @verify_domain_entity_control(DOMAIN) @extract_system async def async_set_pin(call: ServiceCall, system: SystemType) -> None: """Set a PIN.""" await system.async_set_pin(call.data[ATTR_PIN_LABEL], call.data[ATTR_PIN_VALUE]) - @_verify_domain_control + @verify_domain_entity_control(DOMAIN) @extract_system async def async_set_system_properties( call: ServiceCall, system: SystemType diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index 5bd000fd09b..a1a9574a0a6 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -63,6 +63,7 @@ from . import ( template, translation, ) +from .deprecation import deprecated_function from .group import expand_entity_ids from .selector import TargetSelector from .typing import ConfigType, TemplateVarsType, VolDictType, VolSchemaType @@ -1149,6 +1150,7 @@ def async_register_admin_service( @bind_hass @callback +@deprecated_function("verify_domain_entity_control", breaks_in_ha_version="2026.7") def verify_domain_control( hass: HomeAssistant, domain: str ) -> Callable[[Callable[[ServiceCall], Any]], Callable[[ServiceCall], Any]]: diff --git a/tests/helpers/test_service.py b/tests/helpers/test_service.py index c46a6905b55..a399535c574 100644 --- a/tests/helpers/test_service.py +++ b/tests/helpers/test_service.py @@ -1676,7 +1676,9 @@ async def test_register_admin_service_return_response( assert result == {"test-reply": "test-value1"} -async def test_domain_control_not_async(hass: HomeAssistant, mock_entities) -> None: +async def test_domain_control_not_async( + hass: HomeAssistant, mock_entities, caplog: pytest.LogCaptureFixture +) -> None: """Test domain verification in a service call with an unknown user.""" # Note: deprecated - replaced by test_domain_entity_control_not_async calls = [] @@ -1688,6 +1690,11 @@ async def test_domain_control_not_async(hass: HomeAssistant, mock_entities) -> N with pytest.raises(exceptions.HomeAssistantError): service.verify_domain_control(hass, "test_domain")(mock_service_log) + assert ( + "verify_domain_control is a deprecated function which will be removed in " + "HA Core 2026.7. Use verify_domain_entity_control instead" + ) in caplog.text + async def test_domain_control_unknown(hass: HomeAssistant, mock_entities) -> None: """Test domain verification in a service call with an unknown user.""" @@ -1854,7 +1861,7 @@ async def test_domain_entity_control_not_async( calls.append(call) with pytest.raises(exceptions.HomeAssistantError): - service.verify_domain_entity_control(hass, "test_domain")(mock_service_log) + service.verify_domain_entity_control("test_domain")(mock_service_log) async def test_domain_entity_control_unknown( @@ -1871,9 +1878,9 @@ async def test_domain_entity_control_unknown( "homeassistant.helpers.entity_registry.async_get", return_value=Mock(entities=mock_entities), ): - protected_mock_service = service.verify_domain_entity_control( - hass, "test_domain" - )(mock_service_log) + protected_mock_service = service.verify_domain_entity_control("test_domain")( + mock_service_log + ) hass.services.async_register( "test_domain", "test_service", protected_mock_service, schema=None @@ -1911,7 +1918,7 @@ async def test_domain_entity_control_unauthorized( """Define a protected service.""" calls.append(call) - protected_mock_service = service.verify_domain_entity_control(hass, "test_domain")( + protected_mock_service = service.verify_domain_entity_control("test_domain")( mock_service_log ) @@ -1952,7 +1959,7 @@ async def test_domain_entity_control_admin( """Define a protected service.""" calls.append(call) - protected_mock_service = service.verify_domain_entity_control(hass, "test_domain")( + protected_mock_service = service.verify_domain_entity_control("test_domain")( mock_service_log ) @@ -1990,7 +1997,7 @@ async def test_domain_entity_control_no_user(hass: HomeAssistant) -> None: """Define a protected service.""" calls.append(call) - protected_mock_service = service.verify_domain_entity_control(hass, "test_domain")( + protected_mock_service = service.verify_domain_entity_control("test_domain")( mock_service_log )