From 967b8c7c80d0aa1265ac14f35997d1a5567b9a08 Mon Sep 17 00:00:00 2001 From: rafaeling Date: Thu, 21 Sep 2023 12:38:58 +0200 Subject: [PATCH] Use pair response instead of a list --- kuksa-client/kuksa_client/cli_backend/grpc.py | 8 ++++---- kuksa-client/kuksa_client/grpc/__init__.py | 6 +++--- kuksa-client/kuksa_client/grpc/aio.py | 3 +-- kuksa-client/tests/test_grpc.py | 5 ++--- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/kuksa-client/kuksa_client/cli_backend/grpc.py b/kuksa-client/kuksa_client/cli_backend/grpc.py index fca49bfa..645c327d 100644 --- a/kuksa-client/kuksa_client/cli_backend/grpc.py +++ b/kuksa-client/kuksa_client/cli_backend/grpc.py @@ -227,10 +227,10 @@ async def _grpcHandler(self, vss_client: kuksa_client.grpc.aio.VSSClient): continue try: if call == "get": - resp = await vss_client.get(**requestArgs) - if resp is not None: - entries = [entry.to_dict() for entry in resp[0]] - errors = [error for error in resp[1]] + entries, errors = await vss_client.get(**requestArgs) + if entries is not None: + entries = [entry.to_dict() for entry in entries] + errors = [error for error in errors] resp = entries + errors elif call == "set": resp = await vss_client.set(**requestArgs) diff --git a/kuksa-client/kuksa_client/grpc/__init__.py b/kuksa-client/kuksa_client/grpc/__init__.py index 33e82044..0e47ec72 100644 --- a/kuksa-client/kuksa_client/grpc/__init__.py +++ b/kuksa-client/kuksa_client/grpc/__init__.py @@ -573,14 +573,14 @@ def _prepare_get_request(self, entries: Iterable[EntryRequest]) -> val_pb2.GetRe logger.debug("%s: %s", type(req).__name__, req) return req - def _process_get_response(self, response: val_pb2.GetResponse) -> [List[DataEntry], List[str]]: + def _process_get_response(self, response: val_pb2.GetResponse) -> (List[DataEntry], List[str]): logger.debug("%s: %s", type(response).__name__, response) if not response.entries: self._raise_if_invalid(response) entries = [DataEntry.from_message(entry) for entry in response.entries] errors = [json_format.MessageToDict( err, preserving_proto_field_name=True) for err in response.errors] - return [entries, errors] + return (entries, errors) def _get_paths_with_required_type(self, updates: Collection[EntryUpdate]) -> Dict[str, DataType]: paths_with_required_type = {} @@ -874,7 +874,7 @@ def subscribe_metadata( yield {update.entry.path: update.entry.metadata for update in updates} @check_connected - def get(self, entries: Iterable[EntryRequest], **rpc_kwargs) -> List[DataEntry]: + def get(self, entries: Iterable[EntryRequest], **rpc_kwargs) -> (List[DataEntry], List[str]): """ Parameters: rpc_kwargs diff --git a/kuksa-client/kuksa_client/grpc/aio.py b/kuksa-client/kuksa_client/grpc/aio.py index a190937a..8256d92d 100644 --- a/kuksa-client/kuksa_client/grpc/aio.py +++ b/kuksa-client/kuksa_client/grpc/aio.py @@ -378,8 +378,7 @@ async def get_value_types(self, paths: Collection[str], **rpc_kwargs) -> Dict[st path=path, view=View.METADATA, fields=( Field.METADATA_DATA_TYPE,), ) for path in paths) - response = await self.get(entries=entry_requests, **rpc_kwargs) - entries = response[0] + entries, errors = await self.get(entries=entry_requests, **rpc_kwargs) return {entry.path: DataType(entry.metadata.data_type) for entry in entries} return {} diff --git a/kuksa-client/tests/test_grpc.py b/kuksa-client/tests/test_grpc.py index 1a78acf9..88085ce9 100644 --- a/kuksa-client/tests/test_grpc.py +++ b/kuksa-client/tests/test_grpc.py @@ -681,7 +681,7 @@ async def test_get_some_entries(self, unused_tcp_port, val_servicer): EntryRequest('Dummy.With.Allowed.Values', View.METADATA, (Field.METADATA_VALUE_RESTRICTION,)), ))) - entries = response[0] + entries, errors = response assert entries == [ DataEntry('Vehicle.Speed', value=Datapoint( 42.0, datetime.datetime( @@ -795,13 +795,12 @@ async def test_get_unset_entries(self, unused_tcp_port, val_servicer): types_pb2.DataEntry(path='Vehicle.ADAS.ABS.IsActive'), ]) async with VSSClient('127.0.0.1', unused_tcp_port, ensure_startup_connection=False) as client: - response = await client.get(entries=( + entries, errors = await client.get(entries=( EntryRequest('Vehicle.Speed', View.CURRENT_VALUE, (Field.VALUE,)), EntryRequest('Vehicle.ADAS.ABS.IsActive', View.TARGET_VALUE, (Field.ACTUATOR_TARGET,)), )) - entries = response[0] assert entries == [DataEntry('Vehicle.Speed'), DataEntry( 'Vehicle.ADAS.ABS.IsActive')]