From a75aa87b1b01a3d2a3943e0b857ac1b023c22ec7 Mon Sep 17 00:00:00 2001 From: Leon Morten Richter Date: Sun, 15 Sep 2024 09:47:37 +0200 Subject: [PATCH] chore: code quality --- pyais/messages.py | 33 +++++++++++++++++---------------- tests/test_tag_block.py | 7 +++---- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/pyais/messages.py b/pyais/messages.py index 0ed9a9f..56a13e3 100644 --- a/pyais/messages.py +++ b/pyais/messages.py @@ -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: @@ -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), @@ -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__ = ( @@ -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]: diff --git a/tests/test_tag_block.py b/tests/test_tag_block.py index a3c6923..d6cd84e 100644 --- a/tests/test_tag_block.py +++ b/tests/test_tag_block.py @@ -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:A:12344 F:+30000*07\\!BSVDM,1,1,,A,13nN34?000QFpgRWnQLLSPpF00SO,0*06' msg = NMEASentenceFactory.produce(raw)