Handle WebsocketConnectionError during mqtt auto reconnect (#133697)

followup to #133610 to handle the exception in the auto reconnect
path as well

fixes #132985
This commit is contained in:
J. Nick Koston
2024-12-21 00:18:47 -10:00
committed by GitHub
parent 989a3d1e24
commit 4e316429d3
2 changed files with 13 additions and 2 deletions

View File

@@ -695,12 +695,15 @@ class MQTT:
async def _reconnect_loop(self) -> None:
"""Reconnect to the MQTT server."""
# pylint: disable-next=import-outside-toplevel
import paho.mqtt.client as mqtt
while True:
if not self.connected:
try:
async with self._connection_lock, self._async_connect_in_executor():
await self.hass.async_add_executor_job(self._mqttc.reconnect)
except OSError as err:
except (OSError, mqtt.WebsocketConnectionError) as err:
_LOGGER.debug(
"Error re-connecting to MQTT server due to exception: %s", err
)