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

Commit

Permalink
Fix kuksa-client getValues output
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaeling committed Sep 20, 2023
1 parent f9f75f1 commit 6389a24
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
5 changes: 3 additions & 2 deletions kuksa-client/kuksa_client/cli_backend/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ async def _grpcHandler(self, vss_client: kuksa_client.grpc.aio.VSSClient):
if call == "get":
resp = await vss_client.get(**requestArgs)
if resp is not None:
resp = [entry.to_dict() for entry in resp]
resp = resp[0] if len(resp) == 1 else resp
entries = [entry.to_dict() for entry in resp[0]]
errors = [error for error in resp[1]]
resp = entries + errors
elif call == "set":
resp = await vss_client.set(**requestArgs)
elif call == "authorize":
Expand Down
10 changes: 7 additions & 3 deletions kuksa-client/kuksa_client/grpc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +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]:
def _process_get_response(self, response: val_pb2.GetResponse) -> [List[DataEntry], List[str]]:
logger.debug("%s: %s", type(response).__name__, response)
self._raise_if_invalid(response)
return [DataEntry.from_message(entry) for entry in response.entries]
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]

def _get_paths_with_required_type(self, updates: Collection[EntryUpdate]) -> Dict[str, DataType]:
paths_with_required_type = {}
Expand Down
16 changes: 10 additions & 6 deletions kuksa-client/kuksa_client/grpc/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async def connect(self, target_host=None):
options = [('grpc.ssl_target_name_override', self.tls_server_name)]
channel = grpc.aio.secure_channel(target_host, creds, options)
else:
logger.debug(f"Not providing explicit TLS server name")
logger.debug("Not providing explicit TLS server name")
channel = grpc.aio.secure_channel(target_host, creds)
else:
logger.info("Establishing insecure channel")
Expand Down Expand Up @@ -113,11 +113,12 @@ async def get_current_values(self, paths: Iterable[str], **rpc_kwargs) -> Dict[s
])
speed_value = current_values['Vehicle.Speed'].value
"""
entries = await self.get(
response = await self.get(
entries=(EntryRequest(path, View.CURRENT_VALUE, (Field.VALUE,))
for path in paths),
**rpc_kwargs,
)
entries = response[0]
return {entry.path: entry.value for entry in entries}

async def get_target_values(self, paths: Iterable[str], **rpc_kwargs) -> Dict[str, Datapoint]:
Expand All @@ -131,10 +132,11 @@ async def get_target_values(self, paths: Iterable[str], **rpc_kwargs) -> Dict[st
])
is_abs_to_become_active = target_values['Vehicle.ADAS.ABS.IsActive'].value
"""
entries = await self.get(entries=(
response = await self.get(entries=(
EntryRequest(path, View.TARGET_VALUE, (Field.ACTUATOR_TARGET,),
**rpc_kwargs,
) for path in paths))
entries = response[0]
return {entry.path: entry.actuator_target for entry in entries}

async def get_metadata(
Expand All @@ -151,11 +153,12 @@ async def get_metadata(
], MetadataField.UNIT)
speed_unit = metadata['Vehicle.Speed'].unit
"""
entries = await self.get(
response = await self.get(
entries=(EntryRequest(path, View.METADATA, (Field(field.value),))
for path in paths),
**rpc_kwargs,
)
entries = response[0]
return {entry.path: entry.metadata for entry in entries}

async def set_current_values(self, updates: Dict[str, Datapoint], **rpc_kwargs) -> None:
Expand Down Expand Up @@ -363,7 +366,7 @@ async def get_server_info(self, **rpc_kwargs) -> Optional[ServerInfo]:
except AioRpcError as exc:
if exc.code() == grpc.StatusCode.UNAUTHENTICATED:
logger.info("Unauthenticated channel started")
else:
else:
raise VSSClientError.from_grpc_error(exc) from exc
return None

Expand All @@ -378,7 +381,8 @@ 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)
entries = await self.get(entries=entry_requests, **rpc_kwargs)
response = await self.get(entries=entry_requests, **rpc_kwargs)
entries = response[0]
return {entry.path: DataType(entry.metadata.data_type) for entry in entries}
return {}

Expand Down

0 comments on commit 6389a24

Please sign in to comment.