mirror of
https://github.com/home-assistant/core.git
synced 2026-05-21 16:00:12 +01:00
Return response only if requested in mastodon.update_profile action (#170921)
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user