diff --git a/kuksa-client/kuksa_client/cli_backend/grpc.py b/kuksa-client/kuksa_client/cli_backend/grpc.py index c74a5ae4..fca49bfa 100644 --- a/kuksa-client/kuksa_client/cli_backend/grpc.py +++ b/kuksa-client/kuksa_client/cli_backend/grpc.py @@ -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": diff --git a/kuksa-client/kuksa_client/grpc/__init__.py b/kuksa-client/kuksa_client/grpc/__init__.py index fa1d24ed..33e82044 100644 --- a/kuksa-client/kuksa_client/grpc/__init__.py +++ b/kuksa-client/kuksa_client/grpc/__init__.py @@ -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 = {} diff --git a/kuksa-client/kuksa_client/grpc/aio.py b/kuksa-client/kuksa_client/grpc/aio.py index d8a90c89..cdf513a0 100644 --- a/kuksa-client/kuksa_client/grpc/aio.py +++ b/kuksa-client/kuksa_client/grpc/aio.py @@ -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") @@ -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]: @@ -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( @@ -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: @@ -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 @@ -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 {}