Skip to content

Commit

Permalink
handle invalid ascii sequence in serial lines errors #11
Browse files Browse the repository at this point in the history
  • Loading branch information
hekmon committed Jun 13, 2023
1 parent d16acde commit 917a0ef
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions custom_components/linkytic/serial_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,18 @@ def __init__(
expected: bytes,
) -> None:
"""Initialize the checksum exception."""
self.tag = tag.decode("ascii")
self.timestamp = timestamp.decode("ascii") if timestamp else None
self.value = value.decode("ascii")
try:
self.tag = tag.decode("ascii")
except UnicodeDecodeError:
self.tag = "<invalid ascii sequence>"
try:
self.timestamp = timestamp.decode("ascii") if timestamp else None
except UnicodeDecodeError:
self.timestamp = "<invalid ascii sequence>"
try:
self.value = value.decode("ascii")
except UnicodeDecodeError:
self.value = "<invalid ascii sequence>"
self.sum1 = s1
self.s1_truncated = s1_truncated
self.computed = computed
Expand Down

0 comments on commit 917a0ef

Please sign in to comment.