mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Combine executor calls in devolo Home Control (#147216)
This commit is contained in:
parent
3734c4e91d
commit
75946065f2
@ -29,21 +29,9 @@ async def async_setup_entry(
|
|||||||
"""Set up the devolo account from a config entry."""
|
"""Set up the devolo account from a config entry."""
|
||||||
mydevolo = configure_mydevolo(entry.data)
|
mydevolo = configure_mydevolo(entry.data)
|
||||||
|
|
||||||
credentials_valid = await hass.async_add_executor_job(mydevolo.credentials_valid)
|
gateway_ids = await hass.async_add_executor_job(
|
||||||
|
check_mydevolo_and_get_gateway_ids, mydevolo
|
||||||
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)
|
|
||||||
|
|
||||||
if entry.unique_id and GATEWAY_SERIAL_PATTERN.match(entry.unique_id):
|
if entry.unique_id and GATEWAY_SERIAL_PATTERN.match(entry.unique_id):
|
||||||
uuid = await hass.async_add_executor_job(mydevolo.uuid)
|
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.user = conf[CONF_USERNAME]
|
||||||
mydevolo.password = conf[CONF_PASSWORD]
|
mydevolo.password = conf[CONF_PASSWORD]
|
||||||
return mydevolo
|
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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user