From 75946065f2660cb28f7efa693f2ced4759049b8a Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Sun, 22 Jun 2025 23:55:51 +0200 Subject: [PATCH] Combine executor calls in devolo Home Control (#147216) --- .../devolo_home_control/__init__.py | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/devolo_home_control/__init__.py b/homeassistant/components/devolo_home_control/__init__.py index 20a1edf734d..80320e2a849 100644 --- a/homeassistant/components/devolo_home_control/__init__.py +++ b/homeassistant/components/devolo_home_control/__init__.py @@ -29,21 +29,9 @@ async def async_setup_entry( """Set up the devolo account from a config entry.""" mydevolo = configure_mydevolo(entry.data) - credentials_valid = await hass.async_add_executor_job(mydevolo.credentials_valid) - - if not credentials_valid: - raise ConfigEntryAuthFailed( - translation_domain=DOMAIN, - translation_key="invalid_auth", - ) - - if await hass.async_add_executor_job(mydevolo.maintenance): - raise ConfigEntryNotReady( - translation_domain=DOMAIN, - translation_key="maintenance", - ) - - gateway_ids = await hass.async_add_executor_job(mydevolo.get_gateway_ids) + gateway_ids = await hass.async_add_executor_job( + check_mydevolo_and_get_gateway_ids, mydevolo + ) if entry.unique_id and GATEWAY_SERIAL_PATTERN.match(entry.unique_id): uuid = await hass.async_add_executor_job(mydevolo.uuid) @@ -115,3 +103,19 @@ def configure_mydevolo(conf: Mapping[str, Any]) -> Mydevolo: mydevolo.user = conf[CONF_USERNAME] mydevolo.password = conf[CONF_PASSWORD] return mydevolo + + +def check_mydevolo_and_get_gateway_ids(mydevolo: Mydevolo) -> list[str]: + """Check if the credentials are valid and return user's gateway IDs as long as mydevolo is not in maintenance mode.""" + if not mydevolo.credentials_valid(): + raise ConfigEntryAuthFailed( + translation_domain=DOMAIN, + translation_key="invalid_auth", + ) + if mydevolo.maintenance(): + raise ConfigEntryNotReady( + translation_domain=DOMAIN, + translation_key="maintenance", + ) + + return mydevolo.get_gateway_ids()