diff --git a/kuksa-client/kuksa_client/cli_backend/grpc.py b/kuksa-client/kuksa_client/cli_backend/grpc.py index 608e5ab0a..2113733b0 100644 --- a/kuksa-client/kuksa_client/cli_backend/grpc.py +++ b/kuksa-client/kuksa_client/cli_backend/grpc.py @@ -31,14 +31,24 @@ from kuksa_client import cli_backend import kuksa_client.grpc import kuksa_client.grpc.aio -from kuksa_client.grpc import EntryUpdate - +from kuksa_client.grpc import EntryUpdate, DataType +from kuksa.val.v1 import types_pb2 def callback_wrapper(callback: Callable[[str], None]) -> Callable[[Iterable[EntryUpdate]], None]: def wrapper(updates: Iterable[EntryUpdate]) -> None: callback(json.dumps([update.to_dict() for update in updates])) return wrapper +class DatabrokerEncoder(json.JSONEncoder): + def default(self, obj): + if isinstance(obj, (types_pb2.StringArray, types_pb2.BoolArray, types_pb2.Uint32Array, types_pb2.Uint64Array, types_pb2.FloatArray, types_pb2.Int32Array, types_pb2.Int64Array, types_pb2.DoubleArray)): + string_values = [] + for value in obj.values: + value = str(value) + string_values.append(value) + return {'values': string_values} + return super().default(obj) + class Backend(cli_backend.Backend): def __init__(self, config): @@ -109,9 +119,21 @@ def setValues(self, updates: Dict[str, Any], attribute="value", timeout=5): entry_updates = [] for path, value in updates.items(): if field is kuksa_client.grpc.Field.VALUE: + values = value.strip('[]').split(',') + array = [] + if len(values) > 1 : + for val in values: + array.append(val) + value = array entry = kuksa_client.grpc.DataEntry( path=path, value=kuksa_client.grpc.Datapoint(value=value)) elif field is kuksa_client.grpc.Field.ACTUATOR_TARGET: + values = value.strip('[]').split(',') + array = [] + if len(values) > 1 : + for val in values: + array.append(val) + value = array entry = kuksa_client.grpc.DataEntry( path=path, actuator_target=kuksa_client.grpc.Datapoint( value=value), @@ -191,7 +213,7 @@ def _sendReceiveMsg(self, req, timeout): if error: respJson = json.dumps(error, indent=4) elif resp: - respJson = json.dumps(resp, indent=4) + respJson = json.dumps(resp, indent=4, cls=DatabrokerEncoder) else: respJson = "OK" except queue.Empty: