Skip to content

Commit 3558155

Browse files
committed
Use seq_id in priority sorting if available
1 parent ceae980 commit 3558155

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

plugwise_usb/messages/__init__.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,31 +79,31 @@ def calculate_checksum(data: bytes) -> bytes:
7979
def __gt__(self, other: PlugwiseMessage) -> bool:
8080
"""Greater than."""
8181
if self.priority.value == other.priority.value:
82+
if self.seq_id is not None and other.seq_id is not None:
83+
return self.seq_id < other.seq_id
8284
return self.timestamp > other.timestamp
83-
if self.priority.value < other.priority.value:
84-
return True
85-
return False
85+
return self.priority.value < other.priority.value
8686

8787
def __lt__(self, other: PlugwiseMessage) -> bool:
8888
"""Less than."""
8989
if self.priority.value == other.priority.value:
90+
if self.seq_id is not None and other.seq_id is not None:
91+
return self.seq_id > other.seq_id
9092
return self.timestamp < other.timestamp
91-
if self.priority.value > other.priority.value:
92-
return True
93-
return False
93+
return self.priority.value > other.priority.value
9494

9595
def __ge__(self, other: PlugwiseMessage) -> bool:
9696
"""Greater than or equal."""
9797
if self.priority.value == other.priority.value:
98+
if self.seq_id is not None and other.seq_id is not None:
99+
return self.seq_id < other.seq_id
98100
return self.timestamp >= other.timestamp
99-
if self.priority.value < other.priority.value:
100-
return True
101-
return False
101+
return self.priority.value < other.priority.value
102102

103103
def __le__(self, other: PlugwiseMessage) -> bool:
104104
"""Less than or equal."""
105105
if self.priority.value == other.priority.value:
106+
if self.seq_id is not None and other.seq_id is not None:
107+
return self.seq_id <= other.seq_id
106108
return self.timestamp <= other.timestamp
107-
if self.priority.value > other.priority.value:
108-
return True
109-
return False
109+
return self.priority.value > other.priority.value

0 commit comments

Comments
 (0)