Refactor list_entities_services to reduce local variables

This commit is contained in:
J. Nick Koston 2023-11-28 08:50:07 -06:00
parent d0aaf25577
commit 66e2967694
No known key found for this signature in database
1 changed files with 8 additions and 12 deletions

View File

@ -388,21 +388,17 @@ class APIClient:
async def list_entities_services(
self,
) -> tuple[list[EntityInfo], list[UserService]]:
response_types = LIST_ENTITIES_SERVICES_RESPONSE_TYPES
msg_types = LIST_ENTITIES_MSG_TYPES
def do_append(msg: message.Message) -> bool:
return type(msg) is not ListEntitiesDoneResponse
def do_stop(msg: message.Message) -> bool:
return type(msg) is ListEntitiesDoneResponse
resp = await self._get_connection().send_messages_await_response_complex(
(ListEntitiesRequest(),), do_append, do_stop, msg_types, 60
msgs = await self._get_connection().send_messages_await_response_complex(
(ListEntitiesRequest(),),
lambda msg: type(msg) is not ListEntitiesDoneResponse,
lambda msg: type(msg) is ListEntitiesDoneResponse,
LIST_ENTITIES_MSG_TYPES,
60,
)
entities: list[EntityInfo] = []
services: list[UserService] = []
for msg in resp:
response_types = LIST_ENTITIES_SERVICES_RESPONSE_TYPES
for msg in msgs:
if type(msg) is ListEntitiesServicesResponse:
services.append(UserService.from_pb(msg))
continue