diff --git a/kobrax_client.py b/kobrax_client.py index a234e73..eccfbbc 100644 --- a/kobrax_client.py +++ b/kobrax_client.py @@ -371,7 +371,12 @@ class KobraXClient: def _subscribe(self, topic: str): with self._lock: pid = self._pid - self._pid += 1 + # MQTT packet IDs are a 16-bit field (1-65535, 0 reserved) - wrap + # instead of growing unbounded, otherwise a long-lived bridge with + # frequent reconnects eventually overflows pid.to_bytes(2, "big") + # (OverflowError: int too big to convert), breaking every future + # connect attempt including the manual "Connect" button. + self._pid = 1 if self._pid >= 0xFFFF else self._pid + 1 if self._sock is not None: self._sock.sendall(_build_subscribe(topic, pid)) log.info("SUB %s", topic)