From cd6661260c3611fe9d635386a5ad3f00f2bd975d Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 12 Feb 2026 06:05:18 +0100 Subject: [PATCH] Use service helper to extract bring config entry (#162790) --- homeassistant/components/bring/services.py | 20 +++----------------- homeassistant/components/bring/strings.json | 4 ---- tests/components/bring/test_services.py | 7 +++---- 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/homeassistant/components/bring/services.py b/homeassistant/components/bring/services.py index 258bad0c7fa..3d5b20e7b6d 100644 --- a/homeassistant/components/bring/services.py +++ b/homeassistant/components/bring/services.py @@ -1,7 +1,5 @@ """Actions for Bring! integration.""" -from typing import TYPE_CHECKING - from bring_api import ( ActivityType, BringAuthException, @@ -13,7 +11,6 @@ import voluptuous as vol from homeassistant.components.event import ATTR_EVENT_TYPE from homeassistant.components.todo import DOMAIN as TODO_DOMAIN -from homeassistant.config_entries import ConfigEntryState from homeassistant.const import ATTR_ENTITY_ID from homeassistant.core import HomeAssistant, ServiceCall, callback from homeassistant.exceptions import HomeAssistantError, ServiceValidationError @@ -46,19 +43,6 @@ SERVICE_ACTIVITY_STREAM_REACTION_SCHEMA = vol.Schema( ) -def get_config_entry(hass: HomeAssistant, entry_id: str) -> BringConfigEntry: - """Return config entry or raise if not found or not loaded.""" - entry = hass.config_entries.async_get_entry(entry_id) - if TYPE_CHECKING: - assert entry - if entry.state is not ConfigEntryState.LOADED: - raise ServiceValidationError( - translation_domain=DOMAIN, - translation_key="entry_not_loaded", - ) - return entry - - @callback def async_setup_services(hass: HomeAssistant) -> None: """Set up services for Bring! integration.""" @@ -78,7 +62,9 @@ def async_setup_services(hass: HomeAssistant) -> None: ATTR_ENTITY_ID: call.data[ATTR_ENTITY_ID], }, ) - config_entry = get_config_entry(hass, entity.config_entry_id) + config_entry: BringConfigEntry = service.async_get_config_entry( + hass, DOMAIN, entity.config_entry_id + ) coordinator = config_entry.runtime_data.data diff --git a/homeassistant/components/bring/strings.json b/homeassistant/components/bring/strings.json index 3dad23289d8..d14ab495111 100644 --- a/homeassistant/components/bring/strings.json +++ b/homeassistant/components/bring/strings.json @@ -124,10 +124,6 @@ "entity_not_found": { "message": "Failed to send reaction for Bring! — Unknown entity {entity_id}" }, - - "entry_not_loaded": { - "message": "The account associated with this Bring! list is either not loaded or disabled in Home Assistant." - }, "notify_missing_argument": { "message": "This action requires field {field}, please enter a valid value for {field}" }, diff --git a/tests/components/bring/test_services.py b/tests/components/bring/test_services.py index c6e40dff7a5..a58f01fb7ba 100644 --- a/tests/components/bring/test_services.py +++ b/tests/components/bring/test_services.py @@ -112,10 +112,7 @@ async def test_send_reaction_config_entry_not_loaded( assert bring_config_entry.state is ConfigEntryState.NOT_LOADED - with pytest.raises( - ServiceValidationError, - match="The account associated with this Bring! list is either not loaded or disabled in Home Assistant", - ): + with pytest.raises(ServiceValidationError) as err: await hass.services.async_call( DOMAIN, SERVICE_ACTIVITY_STREAM_REACTION, @@ -125,6 +122,8 @@ async def test_send_reaction_config_entry_not_loaded( }, blocking=True, ) + assert err.value.translation_key == "service_config_entry_not_loaded" + assert err.value.translation_placeholders["entry_title"] == "Mock Title" @pytest.mark.usefixtures("mock_bring_client")