Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Use pair response instead of a list
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaeling committed Sep 21, 2023
1 parent 7705170 commit 967b8c7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
8 changes: 4 additions & 4 deletions kuksa-client/kuksa_client/cli_backend/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions kuksa-client/kuksa_client/grpc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions kuksa-client/kuksa_client/grpc/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
5 changes: 2 additions & 3 deletions kuksa-client/tests/test_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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')]

Expand Down

0 comments on commit 967b8c7

Please sign in to comment.