From 7eaa132189fcb69ffc19666ebd6ae58004929bf5 Mon Sep 17 00:00:00 2001 From: Manu <4445816+tr4nt0r@users.noreply.github.com> Date: Sat, 16 May 2026 21:50:40 +0200 Subject: [PATCH] Return response only if requested in `mastodon.update_profile` action (#170921) --- homeassistant/components/mastodon/services.py | 9 ++++++--- tests/components/mastodon/test_services.py | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/mastodon/services.py b/homeassistant/components/mastodon/services.py index 018b91d80d3..1f6c147dd10 100644 --- a/homeassistant/components/mastodon/services.py +++ b/homeassistant/components/mastodon/services.py @@ -177,7 +177,7 @@ def async_setup_services(hass: HomeAssistant) -> None: SERVICE_UPDATE_PROFILE, _async_update_profile, schema=SERVICE_UPDATE_PROFILE_SCHEMA, - supports_response=SupportsResponse.ONLY, + supports_response=SupportsResponse.OPTIONAL, ) @@ -382,7 +382,7 @@ def _post(hass: HomeAssistant, client: Mastodon, **kwargs: Any) -> None: ) from err -async def _async_update_profile(call: ServiceCall) -> ServiceResponse: +async def _async_update_profile(call: ServiceCall) -> ServiceResponse | None: """Update profile information.""" params = dict(call.data.copy()) @@ -406,7 +406,7 @@ async def _async_update_profile(call: ServiceCall) -> ServiceResponse: if field[ATTR_NAME].strip() ] try: - return await call.hass.async_add_executor_job( + response: Account = await call.hass.async_add_executor_job( lambda: client.account_update_credentials(**params) ) except MastodonUnauthorizedError as error: @@ -421,6 +421,9 @@ async def _async_update_profile(call: ServiceCall) -> ServiceResponse: translation_domain=DOMAIN, translation_key="unable_to_update_profile", ) from err + if call.return_response: + return response + return None async def _resolve_media( diff --git a/tests/components/mastodon/test_services.py b/tests/components/mastodon/test_services.py index 0aee7768fca..4637472b580 100644 --- a/tests/components/mastodon/test_services.py +++ b/tests/components/mastodon/test_services.py @@ -793,12 +793,14 @@ async def test_service_entry_availability( ), ], ) +@pytest.mark.parametrize("return_response", [True, False]) async def test_service_update_profile( hass: HomeAssistant, mock_mastodon_client: AsyncMock, mock_config_entry: MockConfigEntry, payload: dict[str, str], kwargs: dict[str, str | None], + return_response: bool, ) -> None: """Test the update profile service.""" assert await async_setup_component(hass, "media_source", {}) @@ -820,7 +822,7 @@ async def test_service_update_profile( SERVICE_UPDATE_PROFILE, {ATTR_CONFIG_ENTRY_ID: mock_config_entry.entry_id, **payload}, blocking=True, - return_response=True, + return_response=return_response, ) mock_mastodon_client.account_update_credentials.assert_called_with(**kwargs)