Skip to content

Commit

Permalink
chore: code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
M0r13n committed Sep 15, 2024
1 parent ec5922a commit a75aa87
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
33 changes: 17 additions & 16 deletions pyais/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def wrapper(tb: 'TagBlock') -> typing.Any:


class TagBlockGroup:
"""Tag Block Group represents the 3-int group sequence
"""Tag Block Group represents the 3-int group sequence
optionally included as part of the NMEA Tag Block
it consists of 3, comma-seperated integers X-Y-Z where:
Expand All @@ -165,20 +165,20 @@ class TagBlockGroup:
- Z = Unique GroupID for this group of messages."""

__slots__ = (
'msg_id',
'total',
'sentence_num',
'sentence_tot',
'group_id'
)

def __init__(self, msg_id: int, total: int, group_id: int):
self.msg_id = msg_id
self.total = total
self.sentence_num = msg_id
self.sentence_tot = total
self.group_id = group_id

@staticmethod
def from_str(raw: str):
def from_str(raw: str) -> 'TagBlockGroup':
"""Constructs a new NMEAGroup from it's string representation"""
[ msg_id, msg_total, group_id ] = raw.split("-", 3)
[msg_id, msg_total, group_id] = raw.split("-", 3)

return TagBlockGroup(
int(msg_id),
Expand All @@ -189,17 +189,18 @@ def from_str(raw: str):
@property
def is_fragmented(self) -> bool:
"""Returns whether or not this group expects several parts."""
return self.msg_total > 1
def __str__(self):
return self.sentence_tot > 1

def __str__(self) -> str:
"""Returns this NMEA group instance in it's string representation."""
return f"{self.msg_id}-{self.total}-{self.group_id}"
def __eq__(self, other) -> bool:
if isinstance(other, NMEAGroup):
return self.msg_id == other.msg_id and self.total == other.total and self.group_id == other.group_id
return f"{self.sentence_num}-{self.sentence_tot}-{self.group_id}"

def __eq__(self, other: object) -> bool:
if isinstance(other, TagBlockGroup):
return self.sentence_num == other.sentence_num and self.sentence_tot == other.sentence_tot and self.group_id == other.group_id
return False


class TagBlock:

__slots__ = (
Expand Down Expand Up @@ -275,7 +276,7 @@ def actual_checksum(self) -> int:
@error_if_uninitialized
def expected_checksum(self) -> int:
return self._expected_checksum

@property
@error_if_uninitialized
def group(self) -> typing.Optional[TagBlockGroup]:
Expand Down
7 changes: 3 additions & 4 deletions tests/test_tag_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ def test_tag_block_with_group(self):
msg = NMEASentenceFactory.produce(raw)
tb = msg.tag_block
tb.init()

self.assertEqual(tb.receiver_timestamp, '1428451253')
self.assertIsNotNone(tb.group)
self.assertEqual(tb.group.msg_id, 1)
self.assertEqual(tb.group.total, 2)
self.assertEqual(tb.group.sentence_num, 1)
self.assertEqual(tb.group.sentence_tot, 2)
self.assertEqual(tb.group.group_id, 4512)


def test_tag_block_with_multiple_unknown_fields(self):
raw = b'\\s:rORBCOMM000,q:u,c:1426032001,T:2015-03-11 00.00.01,i:<T>A:12344 F:+30000</T>*07\\!BSVDM,1,1,,A,13nN34?000QFpgRWnQLLSPpF00SO,0*06'
msg = NMEASentenceFactory.produce(raw)
Expand Down

0 comments on commit a75aa87

Please sign in to comment.