From f03dc5bb363ae219c83f74da4660fbc040092d60 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 3 Jun 2025 09:23:58 +0200 Subject: [PATCH 1/6] Deprecate verify_domain_control service helper --- ...5-06-03-deprecate-verify-domain-control.md | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 blog/2025-06-03-deprecate-verify-domain-control.md diff --git a/blog/2025-06-03-deprecate-verify-domain-control.md b/blog/2025-06-03-deprecate-verify-domain-control.md new file mode 100644 index 00000000000..1ea9c0d75af --- /dev/null +++ b/blog/2025-06-03-deprecate-verify-domain-control.md @@ -0,0 +1,64 @@ +--- +author: epenet +authorURL: https://github.com/epenet +title: "Deprecate verify_domain_control service helper" +--- + +### Summary of changes + +The `homeassistant.helpers.service.verify_domain_control` helper function is deprecated, +and has been replaced with `verify_domain_entity_control`. + +Since release `2025.1` (via core PR https://github.com/home-assistant/core/pull/133062), +a reference to `HomeAssistant` is available as a property of the `ServiceCall` object, +and it became redundant to pass `hass` object to `verify_domain_control`. + +To update your integration: +1. Replace the decorator as shown in the first example below +2. (Optional) Move the nested functions to be module-level as shown in the second example below +3. Test the changes + +The old `verify_domain_control` function will be removed in Home Assistant 2026.7. + + +### Examples + +Minimum change is to simply adjust the decorator + +```python +# Old +# def register_services(hass: HomeAssistant) -> None: +# @verify_domain_control(hass, DOMAIN) +# async def do_action(hass: HomeAssistant, call: ServiceCall) -> None: +# ... +# hass.services.async_register(...) + +# New +def register_services(hass: HomeAssistant) -> None: + @verify_domain_entity_control(DOMAIN) + async def do_action(call: ServiceCall) -> None: + ... + + hass.services.async_register(...) +``` + +To reduce code complexity, it is now recommended to move the service functions to be module-level functions + +```python +# Old +# def register_services(hass: HomeAssistant) -> None: +# @verify_domain_control(hass, DOMAIN) +# async def do_action(call: ServiceCall) -> None: +# entries = hass.config_entries.async_entries(DOMAIN) +# ... +# hass.services.async_register(...) + +# New +@verify_domain_entity_control(DOMAIN) +async def do_action(call: ServiceCall) -> None: + entries = call.hass.config_entries.async_entries(DOMAIN) + ... + +def register_services(hass: HomeAssistant) -> None: + hass.services.async_register(...) +``` From cfd99affa5086506bae8188976f9e65281cc2ee9 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 3 Jun 2025 09:26:49 +0200 Subject: [PATCH 2/6] Tweak --- blog/2025-06-03-deprecate-verify-domain-control.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/blog/2025-06-03-deprecate-verify-domain-control.md b/blog/2025-06-03-deprecate-verify-domain-control.md index 1ea9c0d75af..20732cda019 100644 --- a/blog/2025-06-03-deprecate-verify-domain-control.md +++ b/blog/2025-06-03-deprecate-verify-domain-control.md @@ -29,7 +29,8 @@ Minimum change is to simply adjust the decorator # Old # def register_services(hass: HomeAssistant) -> None: # @verify_domain_control(hass, DOMAIN) -# async def do_action(hass: HomeAssistant, call: ServiceCall) -> None: +# async def do_action(call: ServiceCall) -> None: +# entries = hass.config_entries.async_entries(DOMAIN) # ... # hass.services.async_register(...) @@ -37,6 +38,7 @@ Minimum change is to simply adjust the decorator def register_services(hass: HomeAssistant) -> None: @verify_domain_entity_control(DOMAIN) async def do_action(call: ServiceCall) -> None: + entries = hass.config_entries.async_entries(DOMAIN) ... hass.services.async_register(...) From dbc3b1283ed5960ec7bebb6ea65d6c60c1da60d1 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 3 Jun 2025 09:30:45 +0200 Subject: [PATCH 3/6] Apply suggestions from code review Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- blog/2025-06-03-deprecate-verify-domain-control.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blog/2025-06-03-deprecate-verify-domain-control.md b/blog/2025-06-03-deprecate-verify-domain-control.md index 20732cda019..2af4dac368f 100644 --- a/blog/2025-06-03-deprecate-verify-domain-control.md +++ b/blog/2025-06-03-deprecate-verify-domain-control.md @@ -9,7 +9,7 @@ title: "Deprecate verify_domain_control service helper" The `homeassistant.helpers.service.verify_domain_control` helper function is deprecated, and has been replaced with `verify_domain_entity_control`. -Since release `2025.1` (via core PR https://github.com/home-assistant/core/pull/133062), +Since release `2025.1` (via core PR [#133062](https://github.com/home-assistant/core/pull/133062)), a reference to `HomeAssistant` is available as a property of the `ServiceCall` object, and it became redundant to pass `hass` object to `verify_domain_control`. From e2389036aad6fe91ac2193e17c806dbccc487b71 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 3 Jun 2025 09:32:35 +0200 Subject: [PATCH 4/6] Update 2025-06-03-deprecate-verify-domain-control.md --- blog/2025-06-03-deprecate-verify-domain-control.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/blog/2025-06-03-deprecate-verify-domain-control.md b/blog/2025-06-03-deprecate-verify-domain-control.md index 2af4dac368f..8ec66d12dde 100644 --- a/blog/2025-06-03-deprecate-verify-domain-control.md +++ b/blog/2025-06-03-deprecate-verify-domain-control.md @@ -14,16 +14,16 @@ a reference to `HomeAssistant` is available as a property of the `ServiceCall` o and it became redundant to pass `hass` object to `verify_domain_control`. To update your integration: -1. Replace the decorator as shown in the first example below -2. (Optional) Move the nested functions to be module-level as shown in the second example below -3. Test the changes +1. Replace the decorator (as shown in the first example below). +2. Move the nested functions to be module-level (Optional - as shown in the second example below). +3. Test the changes. The old `verify_domain_control` function will be removed in Home Assistant 2026.7. ### Examples -Minimum change is to simply adjust the decorator +The minimum change is to adjust the decorator ```python # Old @@ -44,7 +44,7 @@ def register_services(hass: HomeAssistant) -> None: hass.services.async_register(...) ``` -To reduce code complexity, it is now recommended to move the service functions to be module-level functions +Move the service functions to module-level functions to reduce code complexity. ```python # Old From ba727f2404646345978af0725c1f198855f4f7d0 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 3 Jun 2025 09:33:17 +0200 Subject: [PATCH 5/6] Update 2025-06-03-deprecate-verify-domain-control.md --- blog/2025-06-03-deprecate-verify-domain-control.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blog/2025-06-03-deprecate-verify-domain-control.md b/blog/2025-06-03-deprecate-verify-domain-control.md index 8ec66d12dde..78c919e9f65 100644 --- a/blog/2025-06-03-deprecate-verify-domain-control.md +++ b/blog/2025-06-03-deprecate-verify-domain-control.md @@ -6,7 +6,7 @@ title: "Deprecate verify_domain_control service helper" ### Summary of changes -The `homeassistant.helpers.service.verify_domain_control` helper function is deprecated, +The `homeassistant.helpers.service.verify_domain_control` service helper is deprecated, and has been replaced with `verify_domain_entity_control`. Since release `2025.1` (via core PR [#133062](https://github.com/home-assistant/core/pull/133062)), @@ -18,7 +18,7 @@ To update your integration: 2. Move the nested functions to be module-level (Optional - as shown in the second example below). 3. Test the changes. -The old `verify_domain_control` function will be removed in Home Assistant 2026.7. +The old `verify_domain_control` decorator will be removed in Home Assistant 2026.7. ### Examples From a108d3d7a23a9c65895732af95f0edc2cb7ef711 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 3 Jun 2025 10:08:23 +0200 Subject: [PATCH 6/6] Update blog/2025-06-03-deprecate-verify-domain-control.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- blog/2025-06-03-deprecate-verify-domain-control.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blog/2025-06-03-deprecate-verify-domain-control.md b/blog/2025-06-03-deprecate-verify-domain-control.md index 78c919e9f65..f6ec8a0291b 100644 --- a/blog/2025-06-03-deprecate-verify-domain-control.md +++ b/blog/2025-06-03-deprecate-verify-domain-control.md @@ -11,7 +11,7 @@ and has been replaced with `verify_domain_entity_control`. Since release `2025.1` (via core PR [#133062](https://github.com/home-assistant/core/pull/133062)), a reference to `HomeAssistant` is available as a property of the `ServiceCall` object, -and it became redundant to pass `hass` object to `verify_domain_control`. +and it became redundant to pass the `hass` object to `verify_domain_control`. To update your integration: 1. Replace the decorator (as shown in the first example below).