From 3563fc39d1b299e995428a59202cd52d19590a52 Mon Sep 17 00:00:00 2001 From: lukasmittag Date: Tue, 1 Oct 2024 15:49:14 +0200 Subject: [PATCH] Adapt to failure value removal in proto file --- kuksa-client/kuksa_client/grpc/__init__.py | 36 ++++++++++------------ 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/kuksa-client/kuksa_client/grpc/__init__.py b/kuksa-client/kuksa_client/grpc/__init__.py index e9822bc..84c5ede 100644 --- a/kuksa-client/kuksa_client/grpc/__init__.py +++ b/kuksa-client/kuksa_client/grpc/__init__.py @@ -690,28 +690,24 @@ def from_message(cls, message: val_v1.EntryUpdate): @classmethod def from_tuple(cls, path: str, dp: types_v2.Datapoint): - if dp.failure: - print(f"An error for {path} occurred: {dp.failure}") - return cls(None) + # we assume here that only one field of Value is set -> we use the first entry. + # This should always be the case. + data = dp.value.ListFields() + field_descriptor, value = data[0] + field_name = field_descriptor.name + value = getattr(dp.value, field_name) + if dp.timestamp.seconds == 0 and dp.timestamp.nanos == 0: + timestamp = None else: - # we assume here that only one field of Value is set -> we use the first entry. - # This should always be the case. - data = dp.value.ListFields() - field_descriptor, value = data[0] - field_name = field_descriptor.name - value = getattr(dp.value, field_name) - if dp.timestamp.seconds == 0 and dp.timestamp.nanos == 0: - timestamp = None - else: - timestamp = dp.timestamp.ToDatetime( - tzinfo=datetime.timezone.utc, - ) - return cls( - entry=DataEntry( - path=path, value=Datapoint(value=value, timestamp=timestamp) - ), - fields=[Field(value=types_v1.FIELD_VALUE)], + timestamp = dp.timestamp.ToDatetime( + tzinfo=datetime.timezone.utc, ) + return cls( + entry=DataEntry( + path=path, value=Datapoint(value=value, timestamp=timestamp) + ), + fields=[Field(value=types_v1.FIELD_VALUE)], + ) def to_message(self) -> val_v1.EntryUpdate: message = val_v1.EntryUpdate(entry=self.entry.to_message())