mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Fix blocking call in Pterodactyl (#142518)
* Fix blocking call * Group blocking calls into a single executor job, catch StopIteration
This commit is contained in:
parent
6c1f9e39c4
commit
3aae280de5
@ -63,15 +63,24 @@ class PterodactylAPI:
|
|||||||
self.pterodactyl = None
|
self.pterodactyl = None
|
||||||
self.identifiers = []
|
self.identifiers = []
|
||||||
|
|
||||||
|
def get_game_servers(self) -> list[str]:
|
||||||
|
"""Get all game servers."""
|
||||||
|
paginated_response = self.pterodactyl.client.servers.list_servers() # type: ignore[union-attr]
|
||||||
|
|
||||||
|
return paginated_response.collect()
|
||||||
|
|
||||||
async def async_init(self):
|
async def async_init(self):
|
||||||
"""Initialize the Pterodactyl API."""
|
"""Initialize the Pterodactyl API."""
|
||||||
self.pterodactyl = PterodactylClient(self.host, self.api_key)
|
self.pterodactyl = PterodactylClient(self.host, self.api_key)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
paginated_response = await self.hass.async_add_executor_job(
|
game_servers = await self.hass.async_add_executor_job(self.get_game_servers)
|
||||||
self.pterodactyl.client.servers.list_servers
|
except (
|
||||||
)
|
BadRequestError,
|
||||||
except (BadRequestError, PterodactylApiError, ConnectionError) as error:
|
PterodactylApiError,
|
||||||
|
ConnectionError,
|
||||||
|
StopIteration,
|
||||||
|
) as error:
|
||||||
raise PterodactylConnectionError(error) from error
|
raise PterodactylConnectionError(error) from error
|
||||||
except HTTPError as error:
|
except HTTPError as error:
|
||||||
if error.response.status_code == 401:
|
if error.response.status_code == 401:
|
||||||
@ -79,7 +88,6 @@ class PterodactylAPI:
|
|||||||
|
|
||||||
raise PterodactylConnectionError(error) from error
|
raise PterodactylConnectionError(error) from error
|
||||||
else:
|
else:
|
||||||
game_servers = paginated_response.collect()
|
|
||||||
for game_server in game_servers:
|
for game_server in game_servers:
|
||||||
self.identifiers.append(game_server["attributes"]["identifier"])
|
self.identifiers.append(game_server["attributes"]["identifier"])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user