Skip to content

Commit

Permalink
Adapt to failure value removal in proto file
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmittag committed Oct 1, 2024
1 parent 3ac17a4 commit 3563fc3
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions kuksa-client/kuksa_client/grpc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 3563fc3

Please sign in to comment.