Skip to content

Commit bf43c31

Browse files
authored
Handle any exception in messages to keep connection alive (#6)
1 parent 96a242f commit bf43c31

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

letpot/deviceclient.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,19 @@ def _handle_message(
113113
self, message: aiomqtt.Message, callback: Callable[[LetPotDeviceStatus], None]
114114
) -> None:
115115
"""Process incoming messages from the broker."""
116-
if self._converter is not None:
116+
if self._converter is None:
117+
return
118+
119+
try:
117120
status = self._converter.convert_hex_to_status(message.payload)
118121
if status is not None:
119122
self._update_status = None
120123
self.last_status = status
121124
callback(status)
122125
if self._status_event is not None and not self._status_event.is_set():
123126
self._status_event.set()
127+
except Exception: # noqa: BLE001
128+
_LOGGER.warning("Exception while handling message, ignoring", exc_info=True)
124129

125130
async def _publish(self, message: list[int]) -> None:
126131
"""Publish a message to the device command topic."""

0 commit comments

Comments
 (0)