From 25d902fd3e99e2b3edc85aebada7a78156e9b978 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 11 Feb 2026 17:24:44 +0100 Subject: [PATCH] Use service helper to extract google_photos config entry (#162792) --- .../components/google_photos/services.py | 15 +++++---------- .../components/google_photos/strings.json | 6 ------ tests/components/google_photos/test_services.py | 6 +++--- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/google_photos/services.py b/homeassistant/components/google_photos/services.py index 3141ce25822..aaedd38cc7e 100644 --- a/homeassistant/components/google_photos/services.py +++ b/homeassistant/components/google_photos/services.py @@ -18,8 +18,8 @@ from homeassistant.core import ( SupportsResponse, callback, ) -from homeassistant.exceptions import HomeAssistantError, ServiceValidationError -from homeassistant.helpers import config_validation as cv +from homeassistant.exceptions import HomeAssistantError +from homeassistant.helpers import config_validation as cv, service from .const import DOMAIN, UPLOAD_SCOPE from .coordinator import GooglePhotosConfigEntry @@ -80,15 +80,10 @@ def _read_file_contents( async def _async_handle_upload(call: ServiceCall) -> ServiceResponse: """Generate content from text and optionally images.""" - config_entry: GooglePhotosConfigEntry | None = ( - call.hass.config_entries.async_get_entry(call.data[CONF_CONFIG_ENTRY_ID]) + config_entry: GooglePhotosConfigEntry = service.async_get_config_entry( + call.hass, DOMAIN, call.data[CONF_CONFIG_ENTRY_ID] ) - if not config_entry: - raise ServiceValidationError( - translation_domain=DOMAIN, - translation_key="integration_not_found", - translation_placeholders={"target": DOMAIN}, - ) + scopes = config_entry.data["token"]["scope"].split(" ") if UPLOAD_SCOPE not in scopes: raise HomeAssistantError( diff --git a/homeassistant/components/google_photos/strings.json b/homeassistant/components/google_photos/strings.json index ecb3e57bb68..63984ecc7c1 100644 --- a/homeassistant/components/google_photos/strings.json +++ b/homeassistant/components/google_photos/strings.json @@ -62,18 +62,12 @@ "filename_is_not_image": { "message": "`{filename}` is not an image" }, - "integration_not_found": { - "message": "Integration \"{target}\" not found in registry." - }, "missing_upload_permission": { "message": "Home Assistant was not granted permission to upload to Google Photos" }, "no_access_to_path": { "message": "Cannot read {filename}, no access to path; `allowlist_external_dirs` may need to be adjusted in `configuration.yaml`" }, - "not_loaded": { - "message": "{target} is not loaded." - }, "upload_error": { "message": "Failed to upload content: {message}" } diff --git a/tests/components/google_photos/test_services.py b/tests/components/google_photos/test_services.py index c944eb2063a..902a24a1f25 100644 --- a/tests/components/google_photos/test_services.py +++ b/tests/components/google_photos/test_services.py @@ -146,7 +146,7 @@ async def test_upload_service_config_entry_not_found( config_entry: MockConfigEntry, ) -> None: """Test upload service call with a config entry that does not exist.""" - with pytest.raises(HomeAssistantError, match="not found in registry"): + with pytest.raises(HomeAssistantError, match="service_config_entry_not_found"): await hass.services.async_call( DOMAIN, UPLOAD_SERVICE, @@ -171,12 +171,12 @@ async def test_config_entry_not_loaded( assert config_entry.state is ConfigEntryState.NOT_LOADED - with pytest.raises(HomeAssistantError, match="not found in registry"): + with pytest.raises(HomeAssistantError, match="service_config_entry_not_loaded"): await hass.services.async_call( DOMAIN, UPLOAD_SERVICE, { - CONF_CONFIG_ENTRY_ID: config_entry.unique_id, + CONF_CONFIG_ENTRY_ID: config_entry.entry_id, CONF_FILENAME: TEST_FILENAME, CONF_ALBUM: ALBUM_TITLE, },