Do not pass default value for `clean_start` on_connect
parent
4594f7e07d
commit
75806736cf
|
@ -669,15 +669,14 @@ class MQTT:
|
|||
result: int | None = None
|
||||
self._available_future = client_available
|
||||
self._should_reconnect = True
|
||||
try:
|
||||
async with self._connection_lock, self._async_connect_in_executor():
|
||||
result = await self.hass.async_add_executor_job(
|
||||
self._mqttc.connect,
|
||||
connect_args: list[Any] = [
|
||||
self.conf[CONF_BROKER],
|
||||
self.conf.get(CONF_PORT, DEFAULT_PORT),
|
||||
self.conf.get(CONF_KEEPALIVE, DEFAULT_KEEPALIVE),
|
||||
"", # bind_address default
|
||||
0, # bind_port default
|
||||
]
|
||||
if self.is_mqttv5:
|
||||
# See:
|
||||
# https://eclipse.dev/paho/files/paho.mqtt.python/html/client.html
|
||||
# `clean_start` (bool) – (MQTT v5.0 only) `True`, `False` or
|
||||
|
@ -687,7 +686,12 @@ class MQTT:
|
|||
# subscriptions) is cleared on successful connect when the
|
||||
# clean_start flag is set. For MQTT v3.1.1, the clean_session
|
||||
# argument of Client should be used for similar result.
|
||||
True if self.is_mqttv5 else mqtt.MQTT_CLEAN_START_FIRST_ONLY,
|
||||
connect_args.append(True) # clean_start
|
||||
try:
|
||||
async with self._connection_lock, self._async_connect_in_executor():
|
||||
result = await self.hass.async_add_executor_job(
|
||||
self._mqttc.connect, # type: ignore[arg-type]
|
||||
*connect_args,
|
||||
)
|
||||
except (OSError, mqtt.WebsocketConnectionError) as err:
|
||||
_LOGGER.error("Failed to connect to MQTT server due to exception: %s", err)
|
||||
|
|
|
@ -1387,14 +1387,14 @@ async def test_setup_mqtt_client_clean_session_and_protocol(
|
|||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "3.1",
|
||||
},
|
||||
call("mock-broker", 1883, 60, "", 0, 3),
|
||||
call("mock-broker", 1883, 60, "", 0),
|
||||
),
|
||||
(
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "3.1.1",
|
||||
},
|
||||
call("mock-broker", 1883, 60, "", 0, 3),
|
||||
call("mock-broker", 1883, 60, "", 0),
|
||||
),
|
||||
(
|
||||
{
|
||||
|
@ -1412,7 +1412,10 @@ async def test_setup_mqtt_client_clean_start(
|
|||
mqtt_client_mock: MqttMockPahoClient,
|
||||
connect_args: tuple[Any],
|
||||
) -> None:
|
||||
"""Test MQTT client protocol connects with `clean_start` set correctly."""
|
||||
"""Test MQTT client protocol connects with `clean_start` set correctly.
|
||||
|
||||
When MQTT v5 is used, we set `clean_start` to `True` on connect.
|
||||
"""
|
||||
await mqtt_mock_entry()
|
||||
|
||||
# check if clean_start was set correctly
|
||||
|
|
Loading…
Reference in New Issue