Skip to content

Commit

Permalink
Another small adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
igorapple committed Jan 23, 2025
1 parent cccb04a commit 0edb0fb
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions uds/database/data_record/text_data_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .raw_data_record import RawDataRecord


class TextDataRecord(AbstractDataRecord, RawDataRecord):
class TextDataRecord(RawDataRecord, AbstractDataRecord):
"""Implementation for Text Data Record."""

def __init__(self, name: str, length: int, mapping: Dict[int, str] = None) -> None:
Expand All @@ -19,7 +19,7 @@ def __init__(self, name: str, length: int, mapping: Dict[int, str] = None) -> No
:raise TypeError: Provided value of name is not str type.
"""
super().__init__(name)
super().__init__(name, length)
self.length = length
self.mapping = mapping

Expand Down Expand Up @@ -67,8 +67,8 @@ def decode(self, raw_value: int) -> DecodedDataRecord: # noqa: F841
"""
if raw_value in self.mapping:
physical_value = self.mapping[raw_value]
return DecodedDataRecord(name=self.name, raw_value=physical_value, physical_value=raw_value)
return DecodedDataRecord(name=self.name, raw_value=raw_value, physical_value=raw_value)
return DecodedDataRecord(name=self.__name, raw_value=physical_value, physical_value=raw_value)
return DecodedDataRecord(name=self.__name, raw_value=raw_value, physical_value=raw_value)

def encode(self, physical_value: DataRecordPhysicalValueAlias) -> int: # noqa: F841
"""
Expand All @@ -80,7 +80,9 @@ def encode(self, physical_value: DataRecordPhysicalValueAlias) -> int: # noqa:
"""
if isinstance(physical_value, int):
return physical_value
if isinstance(physical_value, str):
elif isinstance(physical_value, str):
if physical_value in self.__reversed_mapping:
return self.__reversed_mapping[physical_value]
raise KeyError("physical_value not found in provided mapping.")
else:
raise TypeError("physical_value has not expected type.")

0 comments on commit 0edb0fb

Please sign in to comment.