mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Remove MQTT protocol 3.1 and 3.1.1 support (#195316)
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
import asyncio
|
||||
from collections.abc import Callable
|
||||
from contextlib import suppress
|
||||
import logging
|
||||
from typing import Any, cast
|
||||
|
||||
@@ -11,14 +10,7 @@ import probatio
|
||||
from homeassistant import config as conf_util
|
||||
from homeassistant.components import websocket_api
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_DISCOVERY,
|
||||
CONF_PLATFORM,
|
||||
CONF_PORT,
|
||||
CONF_PROTOCOL,
|
||||
SERVICE_RELOAD,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.const import CONF_DISCOVERY, CONF_PLATFORM, SERVICE_RELOAD, Platform
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import Unauthorized
|
||||
from homeassistant.helpers import (
|
||||
@@ -28,7 +20,6 @@ from homeassistant.helpers import (
|
||||
)
|
||||
from homeassistant.helpers.device_registry import AnyDeviceEntry
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.loader import async_get_loaded_integration
|
||||
from homeassistant.setup import SetupPhases, async_pause_setup
|
||||
@@ -44,7 +35,6 @@ from .client import (
|
||||
async_subscribe_internal,
|
||||
publish,
|
||||
subscribe,
|
||||
try_connection,
|
||||
)
|
||||
from .config import MQTT_BASE_SCHEMA, MQTT_RO_SCHEMA, MQTT_RW_SCHEMA
|
||||
from .config_integration import CONFIG_SCHEMA_BASE
|
||||
@@ -73,15 +63,12 @@ from .const import (
|
||||
CONFIG_ENTRY_VERSION,
|
||||
DEFAULT_DISCOVERY,
|
||||
DEFAULT_ENCODING,
|
||||
DEFAULT_PORT,
|
||||
DEFAULT_PREFIX,
|
||||
DEFAULT_QOS,
|
||||
DEFAULT_RETAIN,
|
||||
DOMAIN,
|
||||
ENTITY_PLATFORMS,
|
||||
MQTT_CONNECTION_STATE,
|
||||
PROTOCOL_5,
|
||||
PROTOCOL_311,
|
||||
SERVICE_PUBLISH,
|
||||
TEMPLATE_ERRORS,
|
||||
MqttService,
|
||||
@@ -319,54 +306,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
"""Load a config entry."""
|
||||
mqtt_data: MqttData
|
||||
|
||||
if (protocol := entry.data.get(CONF_PROTOCOL, PROTOCOL_311)) != PROTOCOL_5:
|
||||
# Automatically migrate the broker protocol to v5 if possible
|
||||
# Can be removed with HA Core 2027.1
|
||||
new_entry_data = entry.data.copy()
|
||||
new_entry_data[CONF_PROTOCOL] = PROTOCOL_5
|
||||
# Create temporary certificate files from entry
|
||||
await async_create_certificate_temp_files(hass, new_entry_data)
|
||||
# Try the connection with protocol version 5
|
||||
# And update the protocol if successful
|
||||
migrated: bool | None = None
|
||||
# When the certificates cannot be loaded, the client setup below fails
|
||||
# and is retried, and the migration is tried again then
|
||||
with suppress(OSError):
|
||||
migrated = await hass.async_add_executor_job(
|
||||
try_connection,
|
||||
{CONF_PORT: DEFAULT_PORT} | new_entry_data,
|
||||
)
|
||||
if migrated:
|
||||
hass.config_entries.async_update_entry(
|
||||
entry,
|
||||
data=new_entry_data,
|
||||
)
|
||||
ir.async_delete_issue(hass, DOMAIN, "protocol_5_migration")
|
||||
_LOGGER.info(
|
||||
"The MQTT protocol version was successfully updated to version 5"
|
||||
)
|
||||
elif migrated is not None:
|
||||
broker: str = entry.data[CONF_BROKER]
|
||||
async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
"protocol_5_migration",
|
||||
config_entry_id=entry.entry_id,
|
||||
issue_domain=DOMAIN,
|
||||
is_fixable=False,
|
||||
breaks_in_ha_version="2027.1.0",
|
||||
severity=IssueSeverity.WARNING,
|
||||
learn_more_url="https://www.home-assistant.io/integrations/mqtt/"
|
||||
"#mqtt-protocol",
|
||||
data={
|
||||
"entry_id": entry.entry_id,
|
||||
"broker": broker,
|
||||
"protocol": protocol,
|
||||
},
|
||||
translation_placeholders={"broker": broker, "protocol": protocol},
|
||||
translation_key="protocol_5_migration",
|
||||
)
|
||||
|
||||
async def _setup_client() -> tuple[MqttData, dict[str, Any]]:
|
||||
"""Set up the MQTT client."""
|
||||
# Fetch configuration
|
||||
|
||||
@@ -26,7 +26,6 @@ from homeassistant.const import (
|
||||
CONF_CLIENT_ID,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_PROTOCOL,
|
||||
CONF_USERNAME,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
)
|
||||
@@ -39,11 +38,8 @@ from homeassistant.core import (
|
||||
callback,
|
||||
get_hassjob_callable_job_type,
|
||||
)
|
||||
from homeassistant.exceptions import (
|
||||
ConfigEntryNotReady,
|
||||
HomeAssistantError,
|
||||
ServiceValidationError,
|
||||
)
|
||||
from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
async_dispatcher_connect,
|
||||
async_dispatcher_send,
|
||||
@@ -83,9 +79,6 @@ from .const import (
|
||||
DOMAIN,
|
||||
MQTT_CONNECTION_STATE,
|
||||
MQTT_PROCESSED_SUBSCRIPTIONS,
|
||||
PROTOCOL_5,
|
||||
PROTOCOL_31,
|
||||
PROTOCOL_311,
|
||||
TRANSPORT_WEBSOCKETS,
|
||||
)
|
||||
from .models import (
|
||||
@@ -108,6 +101,8 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
MQTT_TIMEOUT = 5
|
||||
|
||||
UNSUPPORTED_PROTOCOL_VERSION_ISSUE_ID = "unsupported_protocol_version"
|
||||
|
||||
MIN_BUFFER_SIZE = 131072 # Minimum buffer size to use if preferred size fails
|
||||
PREFERRED_BUFFER_SIZE = 8 * 1024 * 1024 # Set receive buffer size to 8MiB
|
||||
|
||||
@@ -370,42 +365,14 @@ class MqttClientSetup:
|
||||
because it accesses files, so it does IO.
|
||||
"""
|
||||
config = self._config
|
||||
clean_session: bool | None = None
|
||||
# If no protocol setting is set in the config entry data
|
||||
# we assume the config was migrated from YAML, and the
|
||||
# protocol version is defaulting to legacy version 3.1.1.
|
||||
if (protocol := config.get(CONF_PROTOCOL, PROTOCOL_311)) == PROTOCOL_31:
|
||||
proto = mqtt.MQTTv31
|
||||
clean_session = True
|
||||
elif protocol == PROTOCOL_5:
|
||||
proto = mqtt.MQTTv5
|
||||
else:
|
||||
proto = mqtt.MQTTv311
|
||||
clean_session = True
|
||||
|
||||
if (client_id := config.get(CONF_CLIENT_ID)) is None:
|
||||
# PAHO MQTT relies on the MQTT server to generate random client ID
|
||||
# for protocol version 3.1, however, that feature is not mandatory
|
||||
# so we generate our own.
|
||||
# Paho sends an empty client ID, which some brokers reject
|
||||
client_id = mqtt._base62(uuid4().int, padding=22) # noqa: SLF001
|
||||
transport: str = config.get(CONF_TRANSPORT, DEFAULT_TRANSPORT)
|
||||
self._client = AsyncMQTTClient(
|
||||
callback_api_version=mqtt.CallbackAPIVersion.VERSION2,
|
||||
client_id=client_id,
|
||||
# See: https://eclipse.dev/paho/files/paho.mqtt.python/html/client.html
|
||||
# clean_session (bool defaults to None)
|
||||
# a boolean that determines the client type.
|
||||
# If True, the broker will remove all information about this client when it
|
||||
# disconnects. If False, the client is a persistent client and subscription
|
||||
# information and queued messages will be retained when the client
|
||||
# disconnects. Note that a client will never discard its own outgoing
|
||||
# messages on disconnect. Calling connect() or reconnect() will cause the
|
||||
# messages to be resent. Use reinitialise() to reset a client to its
|
||||
# original state. The clean_session argument only applies to MQTT versions
|
||||
# v3.1.1 and v3.1. It is not accepted if the MQTT version is v5.0 - use the
|
||||
# clean_start argument on connect() instead.
|
||||
clean_session=clean_session,
|
||||
protocol=proto,
|
||||
protocol=mqtt.MQTTv5,
|
||||
transport=transport, # type: ignore[arg-type]
|
||||
reconnect_on_failure=False,
|
||||
)
|
||||
@@ -507,10 +474,6 @@ class MQTT:
|
||||
self.loop = hass.loop
|
||||
self.config_entry = config_entry
|
||||
self.conf = conf
|
||||
# If no protocol setting is set in the config entry data
|
||||
# we assume the config was migrated from YAML, and the
|
||||
# protocol version is defaulting to legacy version 3.1.1.
|
||||
self.is_mqttv5 = conf.get(CONF_PROTOCOL, PROTOCOL_311) == PROTOCOL_5
|
||||
|
||||
self._simple_subscriptions: defaultdict[str, set[Subscription]] = defaultdict(
|
||||
set
|
||||
@@ -802,15 +765,6 @@ class MQTT:
|
||||
)
|
||||
properties = mqtt.Properties(mqtt.PacketTypes.PUBLISH) # type: ignore[no-untyped-call]
|
||||
if message_expiry_interval is not None:
|
||||
if not self.is_mqttv5:
|
||||
raise ServiceValidationError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="mqtt_message_expiry_interval_not_supported",
|
||||
translation_placeholders={
|
||||
"topic": topic,
|
||||
"protocol": self.conf.get(CONF_PROTOCOL, PROTOCOL_311),
|
||||
},
|
||||
)
|
||||
properties.MessageExpiryInterval = message_expiry_interval
|
||||
msg_info = self._mqttc.publish(topic, payload, qos, retain, properties)
|
||||
_LOGGER.debug(
|
||||
@@ -836,16 +790,7 @@ class MQTT:
|
||||
host=self.conf[CONF_BROKER],
|
||||
port=self.conf.get(CONF_PORT, DEFAULT_PORT),
|
||||
keepalive=self.conf.get(CONF_KEEPALIVE, DEFAULT_KEEPALIVE),
|
||||
# See:
|
||||
# https://eclipse.dev/paho/files/paho.mqtt.python/html/client.html
|
||||
# `clean_start` (bool) - (MQTT v5.0 only) `True`, `False` or
|
||||
# `MQTT_CLEAN_START_FIRST_ONLY`. Sets the MQTT v5.0 clean_start flag
|
||||
# always, never or on the first successful connect only,
|
||||
# respectively. MQTT session data (such as outstanding messages and
|
||||
# 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.
|
||||
clean_start=True if self.is_mqttv5 else mqtt.MQTT_CLEAN_START_FIRST_ONLY,
|
||||
clean_start=True,
|
||||
)
|
||||
try:
|
||||
async with self._connection_lock, self._async_connect_in_executor():
|
||||
@@ -1123,13 +1068,12 @@ class MQTT:
|
||||
async def _async_perform_subscriptions(self) -> None:
|
||||
"""Perform MQTT client subscriptions."""
|
||||
# Section 3.3.1.3 in the specification:
|
||||
# http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html
|
||||
# When sending a PUBLISH Packet to a Client the Server MUST
|
||||
# set the RETAIN flag to 1 if a message is sent as a result of a
|
||||
# new subscription being made by a Client [MQTT-3.3.1-8].
|
||||
# It MUST set the RETAIN flag to 0 when a PUBLISH Packet is sent to
|
||||
# a Client because it matches an established subscription regardless
|
||||
# of how the flag was set in the message it received [MQTT-3.3.1-9].
|
||||
# https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html
|
||||
# With the default subscription options, the Server sends retained
|
||||
# messages with the RETAIN flag set to 1 when a new subscription is
|
||||
# made [MQTT-3.3.1-9]. It MUST set the RETAIN flag to 0 when forwarding
|
||||
# a message that matches an established subscription, regardless of
|
||||
# how the flag was set in the message it received [MQTT-3.3.1-12].
|
||||
#
|
||||
# Since we do not know if a published value is retained we need to
|
||||
# (re)subscribe, to ensure retained messages are replayed
|
||||
@@ -1257,26 +1201,23 @@ class MQTT:
|
||||
Resubscribe to all topics we were subscribed to and publish birth
|
||||
message.
|
||||
"""
|
||||
if self.is_mqttv5:
|
||||
# Check if the server explicitly disabled Subscription Identifiers
|
||||
if (
|
||||
properties is not None
|
||||
and hasattr(properties, "SubscriptionIdentifierAvailable")
|
||||
and properties.SubscriptionIdentifierAvailable == 0
|
||||
):
|
||||
_LOGGER.warning(
|
||||
"Your MQTT broker reports it does not support "
|
||||
"Subscription Identifiers, see "
|
||||
"https://docs.oasis-open.org/"
|
||||
"mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901092. "
|
||||
"Please use a supported MQTT broker; got broker properties: %s",
|
||||
properties,
|
||||
)
|
||||
self._supports_subscription_identifiers = False
|
||||
else:
|
||||
self._supports_subscription_identifiers = True
|
||||
else:
|
||||
# Check if the server explicitly disabled Subscription Identifiers
|
||||
if (
|
||||
properties is not None
|
||||
and hasattr(properties, "SubscriptionIdentifierAvailable")
|
||||
and properties.SubscriptionIdentifierAvailable == 0
|
||||
):
|
||||
_LOGGER.warning(
|
||||
"Your MQTT broker reports it does not support "
|
||||
"Subscription Identifiers, see "
|
||||
"https://docs.oasis-open.org/"
|
||||
"mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901092. "
|
||||
"Please use a supported MQTT broker; got broker properties: %s",
|
||||
properties,
|
||||
)
|
||||
self._supports_subscription_identifiers = False
|
||||
else:
|
||||
self._supports_subscription_identifiers = True
|
||||
|
||||
if reason_code.is_failure:
|
||||
# 24: Continue authentication
|
||||
@@ -1288,6 +1229,22 @@ class MQTT:
|
||||
self._should_reconnect = False
|
||||
self.hass.async_create_task(self.async_disconnect())
|
||||
self.config_entry.async_start_reauth(self.hass)
|
||||
# 132: Unsupported protocol version, the broker does not support MQTT v5
|
||||
elif reason_code.value == 132:
|
||||
self._should_reconnect = False
|
||||
self.hass.async_create_task(self.async_disconnect())
|
||||
ir.async_create_issue(
|
||||
self.hass,
|
||||
DOMAIN,
|
||||
UNSUPPORTED_PROTOCOL_VERSION_ISSUE_ID,
|
||||
config_entry_id=self.config_entry.entry_id,
|
||||
is_fixable=False,
|
||||
severity=ir.IssueSeverity.ERROR,
|
||||
learn_more_url="https://www.home-assistant.io/integrations/mqtt/"
|
||||
"#mqtt-protocol",
|
||||
translation_key=UNSUPPORTED_PROTOCOL_VERSION_ISSUE_ID,
|
||||
translation_placeholders={"broker": self.conf[CONF_BROKER]},
|
||||
)
|
||||
_LOGGER.error(
|
||||
"Unable to connect to the MQTT broker: %s",
|
||||
reason_code.getName(), # type: ignore[no-untyped-call]
|
||||
@@ -1295,6 +1252,7 @@ class MQTT:
|
||||
self._async_connection_result(False)
|
||||
return
|
||||
|
||||
ir.async_delete_issue(self.hass, DOMAIN, UNSUPPORTED_PROTOCOL_VERSION_ISSUE_ID)
|
||||
self.connected = True
|
||||
async_dispatcher_send(self.hass, MQTT_CONNECTION_STATE, True)
|
||||
_LOGGER.debug(
|
||||
|
||||
@@ -87,7 +87,6 @@ from homeassistant.const import (
|
||||
CONF_PAYLOAD_ON,
|
||||
CONF_PLATFORM,
|
||||
CONF_PORT,
|
||||
CONF_PROTOCOL,
|
||||
CONF_STATE_TEMPLATE,
|
||||
CONF_TEMPERATURE_UNIT,
|
||||
CONF_UNIQUE_ID,
|
||||
@@ -401,7 +400,6 @@ from .const import (
|
||||
DEFAULT_POSITION_CLOSED,
|
||||
DEFAULT_POSITION_OPEN,
|
||||
DEFAULT_PREFIX,
|
||||
DEFAULT_PROTOCOL,
|
||||
DEFAULT_QOS,
|
||||
DEFAULT_SPEED_RANGE_MAX,
|
||||
DEFAULT_SPEED_RANGE_MIN,
|
||||
@@ -420,7 +418,6 @@ from .const import (
|
||||
DOMAIN,
|
||||
REMOTE_CODE,
|
||||
REMOTE_CODE_TEXT,
|
||||
SUPPORTED_PROTOCOLS,
|
||||
TRANSPORT_TCP,
|
||||
TRANSPORT_WEBSOCKETS,
|
||||
VALUES_ON_COMMAND_TYPE,
|
||||
@@ -563,12 +560,6 @@ PORT_SELECTOR = probatio.All(
|
||||
NumberSelector(NumberSelectorConfig(mode=NumberSelectorMode.BOX, min=1, max=65535)),
|
||||
probatio.Coerce(int),
|
||||
)
|
||||
PROTOCOL_SELECTOR = SelectSelector(
|
||||
SelectSelectorConfig(
|
||||
options=SUPPORTED_PROTOCOLS,
|
||||
mode=SelectSelectorMode.DROPDOWN,
|
||||
)
|
||||
)
|
||||
PUBLISH_TOPIC_SELECTOR = TextSelector(TextSelectorConfig(type=TextSelectorType.TEXT))
|
||||
SUPPORTED_TRANSPORTS = [
|
||||
SelectOptionDict(value=TRANSPORT_TCP, label="TCP"),
|
||||
@@ -4018,7 +4009,6 @@ CONFIG_DATAFLOW_SCHEMA = probatio.Schema(
|
||||
{
|
||||
probatio.Required(CONF_BROKER): TEXT_SELECTOR,
|
||||
probatio.Required(CONF_PORT, default=DEFAULT_PORT): PORT_SELECTOR,
|
||||
probatio.Required(CONF_PROTOCOL, default=DEFAULT_PROTOCOL): PROTOCOL_SELECTOR,
|
||||
probatio.Optional(CONF_USERNAME): TEXT_SELECTOR,
|
||||
probatio.Optional(probatio.Secret(CONF_PASSWORD)): PASSWORD_SELECTOR,
|
||||
probatio.Required(OTHER_SETTINGS): section(
|
||||
@@ -4143,7 +4133,6 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
config: dict[str, Any] = {
|
||||
CONF_BROKER: addon_discovery_config[CONF_HOST],
|
||||
CONF_PORT: addon_discovery_config[CONF_PORT],
|
||||
CONF_PROTOCOL: DEFAULT_PROTOCOL,
|
||||
CONF_USERNAME: addon_discovery_config.get(CONF_USERNAME),
|
||||
CONF_PASSWORD: addon_discovery_config.get(CONF_PASSWORD),
|
||||
}
|
||||
@@ -4414,7 +4403,6 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
if user_input is not None:
|
||||
data: dict[str, Any] = self._hassio_discovery.copy()
|
||||
data[CONF_BROKER] = data.pop(CONF_HOST)
|
||||
data[CONF_PROTOCOL] = DEFAULT_PROTOCOL
|
||||
can_connect = await self.hass.async_add_executor_job(
|
||||
try_connection,
|
||||
data,
|
||||
@@ -4426,7 +4414,6 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
data={
|
||||
CONF_BROKER: data[CONF_BROKER],
|
||||
CONF_PORT: data[CONF_PORT],
|
||||
CONF_PROTOCOL: DEFAULT_PROTOCOL,
|
||||
CONF_USERNAME: data.get(CONF_USERNAME),
|
||||
CONF_PASSWORD: data.get(CONF_PASSWORD),
|
||||
},
|
||||
|
||||
@@ -351,17 +351,11 @@ ALARM_CONTROL_PANEL_SUPPORTED_FEATURES = {
|
||||
REMOTE_CODE = "REMOTE_CODE"
|
||||
REMOTE_CODE_TEXT = "REMOTE_CODE_TEXT"
|
||||
|
||||
PROTOCOL_31 = "3.1"
|
||||
PROTOCOL_311 = "3.1.1"
|
||||
PROTOCOL_5 = "5"
|
||||
SUPPORTED_PROTOCOLS = [PROTOCOL_5, PROTOCOL_311, PROTOCOL_31]
|
||||
|
||||
TRANSPORT_TCP = "tcp"
|
||||
TRANSPORT_WEBSOCKETS = "websockets"
|
||||
|
||||
DEFAULT_PORT = 1883
|
||||
DEFAULT_KEEPALIVE = 60
|
||||
DEFAULT_PROTOCOL = PROTOCOL_5
|
||||
DEFAULT_TRANSPORT = TRANSPORT_TCP
|
||||
|
||||
DEFAULT_BIRTH = {
|
||||
|
||||
@@ -35,14 +35,12 @@
|
||||
"broker": "Broker",
|
||||
"password": "[%key:common::config_flow::data::password%]",
|
||||
"port": "[%key:common::config_flow::data::port%]",
|
||||
"protocol": "MQTT protocol",
|
||||
"username": "[%key:common::config_flow::data::username%]"
|
||||
},
|
||||
"data_description": {
|
||||
"broker": "The hostname or IP address of your MQTT broker.",
|
||||
"password": "The password to log in to your MQTT broker.",
|
||||
"port": "The port your MQTT broker listens to. For example 1883.",
|
||||
"protocol": "The MQTT protocol version that is used. Note that Home Assistant will silently change to version 5 if your broker supports it.",
|
||||
"username": "The username to log in to your MQTT broker."
|
||||
},
|
||||
"description": "Please enter the connection information of your MQTT broker.",
|
||||
@@ -1125,9 +1123,6 @@
|
||||
"mqtt_max_subscription_id_reached": {
|
||||
"message": "MQTT Subscription ID limit reached. Cannot generate more IDs to subscribe."
|
||||
},
|
||||
"mqtt_message_expiry_interval_not_supported": {
|
||||
"message": "Publishing to topic {topic} with a Message Expiry Interval is not supported for protocol version {protocol}."
|
||||
},
|
||||
"mqtt_not_enabled_cannot_subscribe": {
|
||||
"message": "Cannot subscribe to topic \"{topic}\" because MQTT is not enabled, make sure MQTT is set up correctly."
|
||||
},
|
||||
@@ -1195,10 +1190,6 @@
|
||||
"description": "Home Assistant detected an invalid config for a manually configured item.\n\nPlatform domain: **{domain}**\nConfiguration file: **{config_file}**\nNear line: **{line}**\nConfiguration found:\n```yaml\n{config}\n```\nError: **{error}**.\n\nMake sure the configuration is valid and [reload](/config/tools/yaml) the manually configured MQTT items or restart Home Assistant to fix this issue.",
|
||||
"title": "Invalid config found for MQTT {domain} item"
|
||||
},
|
||||
"protocol_5_migration": {
|
||||
"description": "The automatic migration to MQTT protocol version 5 failed. The currently configured protocol version for MQTT broker {broker} is {protocol}, but this protocol version is deprecated, and support for it will be removed.\n\nMake sure your broker supports protocol version 5. Update your MQTT broker's connection settings, and restart Home Assistant to fix this issue.",
|
||||
"title": "MQTT protocol migration failed"
|
||||
},
|
||||
"subentry_migration_discovery": {
|
||||
"fix_flow": {
|
||||
"step": {
|
||||
@@ -1221,6 +1212,10 @@
|
||||
},
|
||||
"title": "MQTT device \"{name}\" subentry migration to YAML"
|
||||
},
|
||||
"unsupported_protocol_version": {
|
||||
"description": "MQTT broker {broker} does not support MQTT protocol version 5, so Home Assistant cannot connect to it. Home Assistant only supports MQTT protocol version 5.\n\nUpdate your MQTT broker, or switch to a broker that supports MQTT protocol version 5, like the Mosquitto broker app. Then reload the MQTT integration or restart Home Assistant to fix this issue.",
|
||||
"title": "MQTT broker does not support MQTT protocol version 5"
|
||||
},
|
||||
"yaml_setup_without_active_setup": {
|
||||
"description": "Home Assistant detected manually configured MQTT items, but these items cannot be loaded because MQTT is not set up correctly. Make sure the MQTT broker is set up correctly, or remove the MQTT configuration from your `configuration.yaml` file and restart Home Assistant to fix this issue.",
|
||||
"title": "MQTT is not set up correctly"
|
||||
@@ -1438,7 +1433,7 @@
|
||||
"name": "Evaluate payload"
|
||||
},
|
||||
"message_expiry_interval": {
|
||||
"description": "Expires a publish message after the interval in case the device subscriber was temporarily offline, or the message was set as a retained message. Only supported with MQTT protocol version 5.0.",
|
||||
"description": "Expires a publish message after the interval in case the device subscriber was temporarily offline, or the message was set as a retained message.",
|
||||
"name": "Message Expiry Interval"
|
||||
},
|
||||
"payload": {
|
||||
|
||||
@@ -1247,10 +1247,7 @@ async def _mqtt_mock_entry(
|
||||
from homeassistant.components import mqtt # noqa: PLC0415
|
||||
|
||||
if mqtt_config_entry_data is None:
|
||||
mqtt_config_entry_data = {
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
mqtt.CONF_PROTOCOL: "5",
|
||||
}
|
||||
mqtt_config_entry_data = {mqtt.CONF_BROKER: "mock-broker"}
|
||||
if mqtt_config_entry_options is None:
|
||||
mqtt_config_entry_options = {mqtt.CONF_BIRTH_MESSAGE: {}}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from collections.abc import AsyncGenerator, Generator
|
||||
from pathlib import Path
|
||||
from random import getrandbits
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
from pytest_homeassistant.common import MockConfigEntry
|
||||
@@ -33,24 +33,6 @@ def patch_hass_config(mock_hass_config: None) -> None:
|
||||
"""Patch configuration.yaml."""
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_v5_protocol_check() -> bool:
|
||||
"""Fixture to mock a v5 protocol test result."""
|
||||
return True
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_try_connection_protocol_check(
|
||||
hass: HomeAssistant, mock_v5_protocol_check: bool
|
||||
) -> Generator[MagicMock]:
|
||||
"""Patch try_connection."""
|
||||
with patch(
|
||||
"homeassistant.components.mqtt.try_connection",
|
||||
return_value=mock_v5_protocol_check,
|
||||
) as mock_try_connection:
|
||||
yield mock_try_connection
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def temp_dir_prefix() -> str:
|
||||
"""Set an alternate temp dir prefix."""
|
||||
|
||||
@@ -45,13 +45,12 @@ from homeassistant.components.mqtt.models import (
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntryDisabler, ConfigEntryState
|
||||
from homeassistant.const import (
|
||||
CONF_PROTOCOL,
|
||||
EVENT_HOMEASSISTANT_STARTED,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import CALLBACK_TYPE, CoreState, HomeAssistant, callback
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
@@ -161,7 +160,6 @@ async def test_mqtt_await_ack_at_disconnect(hass: HomeAssistant) -> None:
|
||||
ENTRY_DEFAULT_BIRTH_MESSAGE,
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "5",
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -248,62 +246,6 @@ async def test_publish(
|
||||
assert publish_mock.call_args[0][4].json() == {"MessageExpiryInterval": 60}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mock_v5_protocol_check", [False])
|
||||
@pytest.mark.parametrize(
|
||||
("mqtt_config_entry_options", "mqtt_config_entry_data", "protocol"),
|
||||
[
|
||||
(
|
||||
ENTRY_DEFAULT_BIRTH_MESSAGE,
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "3.1.1",
|
||||
},
|
||||
"3.1.1",
|
||||
),
|
||||
(
|
||||
ENTRY_DEFAULT_BIRTH_MESSAGE,
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "3.1",
|
||||
},
|
||||
"3.1",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_message_expiry_interval_fails_for_legacy_protocols(
|
||||
hass: HomeAssistant,
|
||||
setup_with_birth_msg_client_mock: MqttMockPahoClient,
|
||||
protocol: str,
|
||||
) -> None:
|
||||
"""Test publishing with Message Expiry Interval fails if protocol != 5."""
|
||||
publish_mock: MagicMock = setup_with_birth_msg_client_mock.publish
|
||||
await mqtt.async_publish(hass, "test-topic", "test-payload")
|
||||
await hass.async_block_till_done()
|
||||
assert publish_mock.called
|
||||
assert publish_mock.call_args[0] == (
|
||||
"test-topic",
|
||||
"test-payload",
|
||||
0,
|
||||
False,
|
||||
ANY,
|
||||
)
|
||||
publish_mock.reset_mock()
|
||||
|
||||
# test with message expiry interval
|
||||
with pytest.raises(ServiceValidationError) as exc:
|
||||
await mqtt.async_publish(
|
||||
hass, "test-topic", "test-payload", 2, True, message_expiry_interval=60
|
||||
)
|
||||
assert exc.value.translation_domain == DOMAIN
|
||||
assert exc.value.translation_key == "mqtt_message_expiry_interval_not_supported"
|
||||
assert exc.value.translation_placeholders == {
|
||||
"topic": "test-topic",
|
||||
"protocol": protocol,
|
||||
}
|
||||
|
||||
publish_mock.assert_not_called()
|
||||
|
||||
|
||||
async def test_convert_outgoing_payload(hass: HomeAssistant) -> None:
|
||||
"""Test the converting of outgoing MQTT payloads without template."""
|
||||
command_template = mqtt.MqttCommandTemplate(None)
|
||||
@@ -1125,24 +1067,6 @@ async def test_not_calling_subscribe_when_unsubscribed_within_cooldown(
|
||||
assert not mqtt_client_mock.subscribe.called
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mqtt_config_entry_data",
|
||||
[
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "3.1",
|
||||
},
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "3.1.1",
|
||||
},
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "5",
|
||||
},
|
||||
],
|
||||
ids=["v3.1", "v3.1.1", "v5"],
|
||||
)
|
||||
async def test_unsubscribe_race(
|
||||
hass: HomeAssistant,
|
||||
mock_debouncer: asyncio.Event,
|
||||
@@ -1198,24 +1122,6 @@ async def test_unsubscribe_race(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mqtt_config_entry_data",
|
||||
[
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "3.1",
|
||||
},
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "3.1.1",
|
||||
},
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "5",
|
||||
},
|
||||
],
|
||||
ids=["v3.1", "v3.1.1", "v5"],
|
||||
)
|
||||
@pytest.mark.parametrize("mqtt_config_entry_options", [ENTRY_DEFAULT_BIRTH_MESSAGE])
|
||||
async def test_wildcard_unsubscribe_race(
|
||||
hass: HomeAssistant,
|
||||
@@ -1275,7 +1181,7 @@ async def test_wildcard_unsubscribe_race(
|
||||
("mqtt_config_entry_data", "mqtt_config_entry_options"),
|
||||
[
|
||||
(
|
||||
{mqtt.CONF_BROKER: "mock-broker", CONF_PROTOCOL: "5"},
|
||||
{mqtt.CONF_BROKER: "mock-broker"},
|
||||
ENTRY_DEFAULT_BIRTH_MESSAGE,
|
||||
)
|
||||
],
|
||||
@@ -1403,7 +1309,7 @@ async def test_restore_subscriptions_on_reconnect(
|
||||
("mqtt_config_entry_data", "mqtt_config_entry_options"),
|
||||
[
|
||||
(
|
||||
{mqtt.CONF_BROKER: "mock-broker", mqtt.CONF_PROTOCOL: "5"},
|
||||
{mqtt.CONF_BROKER: "mock-broker"},
|
||||
{mqtt.CONF_DISCOVERY: False},
|
||||
)
|
||||
],
|
||||
@@ -1516,9 +1422,7 @@ async def test_logs_error_if_no_connect_broker(
|
||||
assert "Unable to connect to the MQTT broker: Server unavailable" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mqtt_config_entry_data", [{mqtt.CONF_BROKER: "mock-broker", CONF_PROTOCOL: "5"}]
|
||||
)
|
||||
@pytest.mark.parametrize("mqtt_config_entry_data", [{mqtt.CONF_BROKER: "mock-broker"}])
|
||||
async def test_logs_error_if_broker_does_not_support_subscription_identifiers(
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
@@ -1565,6 +1469,53 @@ async def test_triggers_reauth_flow_if_auth_fails(
|
||||
assert flows[0]["context"]["source"] == "reauth"
|
||||
|
||||
|
||||
async def test_repair_issue_if_broker_does_not_support_mqtt_v5(
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
setup_with_birth_msg_client_mock: MqttMockPahoClient,
|
||||
) -> None:
|
||||
"""Test a repair issue is raised if the broker does not support MQTT v5."""
|
||||
mqtt_client_mock = setup_with_birth_msg_client_mock
|
||||
mqtt_client_mock.reconnect.reset_mock()
|
||||
mqtt_client_mock.on_disconnect(Mock(), None, 0, MockMqttReasonCode(), None)
|
||||
mqtt_client_mock.on_connect(
|
||||
Mock(),
|
||||
None,
|
||||
None,
|
||||
MockMqttReasonCode(
|
||||
value=132, is_failure=True, name="Unsupported protocol version"
|
||||
),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
# The reconnect loop is stopped
|
||||
async_fire_time_changed(
|
||||
hass, utcnow() + timedelta(seconds=RECONNECT_INTERVAL_SECONDS)
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mqtt_client_mock.reconnect.assert_not_called()
|
||||
assert (
|
||||
"Unable to connect to the MQTT broker: Unsupported protocol version"
|
||||
in caplog.text
|
||||
)
|
||||
issue = issue_registry.async_get_issue(mqtt.DOMAIN, "unsupported_protocol_version")
|
||||
assert issue is not None
|
||||
assert issue.severity is ir.IssueSeverity.ERROR
|
||||
assert issue.translation_placeholders == {"broker": "test-broker"}
|
||||
entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
|
||||
assert issue.config_entry_id == entry.entry_id
|
||||
# No reauth is started
|
||||
assert not hass.config_entries.flow.async_progress()
|
||||
|
||||
# The issue is removed after a successful connection
|
||||
mqtt_client_mock.on_connect(Mock(), None, None, MockMqttReasonCode())
|
||||
await hass.async_block_till_done()
|
||||
assert (
|
||||
issue_registry.async_get_issue(mqtt.DOMAIN, "unsupported_protocol_version")
|
||||
is None
|
||||
)
|
||||
|
||||
|
||||
@patch("homeassistant.components.mqtt.client.TIMEOUT_ACK", 0.3)
|
||||
async def test_handle_mqtt_on_callback(
|
||||
hass: HomeAssistant,
|
||||
@@ -1698,94 +1649,29 @@ async def test_handle_message_callback(
|
||||
assert callbacks[0].payload == "test-payload"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mock_v5_protocol_check", [False])
|
||||
@pytest.mark.parametrize(
|
||||
("mqtt_config_entry_data", "protocol", "clean_session"),
|
||||
[
|
||||
(
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "3.1",
|
||||
},
|
||||
3,
|
||||
True,
|
||||
),
|
||||
(
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "3.1.1",
|
||||
},
|
||||
4,
|
||||
True,
|
||||
),
|
||||
(
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "5",
|
||||
},
|
||||
5,
|
||||
None,
|
||||
),
|
||||
],
|
||||
ids=["v3.1", "v3.1.1", "v5"],
|
||||
)
|
||||
async def test_setup_mqtt_client_clean_session_and_protocol(
|
||||
async def test_setup_mqtt_client_protocol(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
protocol: int,
|
||||
clean_session: bool | None,
|
||||
) -> None:
|
||||
"""Test MQTT client clean_session and protocol setup."""
|
||||
"""Test MQTT client is set up with protocol version 5."""
|
||||
with patch("homeassistant.components.mqtt.client.AsyncMQTTClient") as mock_client:
|
||||
await mqtt_mock_entry()
|
||||
|
||||
# check if clean_session was correctly
|
||||
assert mock_client.call_args[1]["clean_session"] == clean_session
|
||||
|
||||
# check if protocol setup was correctly
|
||||
assert mock_client.call_args[1]["protocol"] == protocol
|
||||
assert mock_client.call_args[1]["protocol"] == 5
|
||||
assert "clean_session" not in mock_client.call_args[1]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mock_v5_protocol_check", [False])
|
||||
@pytest.mark.parametrize(
|
||||
("mqtt_config_entry_data", "connect_args"),
|
||||
[
|
||||
(
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "3.1",
|
||||
},
|
||||
call(host="mock-broker", port=1883, keepalive=60, clean_start=3),
|
||||
),
|
||||
(
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "3.1.1",
|
||||
},
|
||||
call(host="mock-broker", port=1883, keepalive=60, clean_start=3),
|
||||
),
|
||||
(
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "5",
|
||||
},
|
||||
call(host="mock-broker", port=1883, keepalive=60, clean_start=True),
|
||||
),
|
||||
],
|
||||
ids=["v3.1", "v3.1.1", "v5"],
|
||||
)
|
||||
async def test_setup_mqtt_client_clean_start(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
connect_args: tuple[Any],
|
||||
) -> None:
|
||||
"""Test MQTT client protocol connects with `clean_start` set correctly."""
|
||||
"""Test MQTT client connects with `clean_start` set."""
|
||||
await mqtt_mock_entry()
|
||||
|
||||
# check if clean_start was set correctly
|
||||
assert len(mqtt_client_mock.connect.mock_calls) == 1
|
||||
assert mqtt_client_mock.connect.mock_calls[0] == connect_args
|
||||
assert mqtt_client_mock.connect.mock_calls == [
|
||||
call(host="mock-broker", port=1883, keepalive=60, clean_start=True)
|
||||
]
|
||||
|
||||
|
||||
@patch("homeassistant.components.mqtt.client.TIMEOUT_ACK", 0.2)
|
||||
@@ -2012,30 +1898,17 @@ async def test_setup_uses_certificate_files(
|
||||
pytest.param(ssl.SSLError("KEY_VALUES_MISMATCH"), id="mismatching_key"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"protocol",
|
||||
[
|
||||
pytest.param("5", id="protocol_5"),
|
||||
# Setup first tries to migrate the protocol
|
||||
pytest.param("3.1.1", id="protocol_311_migration"),
|
||||
],
|
||||
)
|
||||
async def test_setup_certificates_cannot_be_loaded(
|
||||
hass: HomeAssistant,
|
||||
mqtt_client_mock: MqttMockPahoClient,
|
||||
mock_try_connection_protocol_check: MagicMock,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
error: OSError,
|
||||
protocol: str,
|
||||
) -> None:
|
||||
"""Test setup is retried when the certificate files cannot be loaded."""
|
||||
mqtt_client_mock.tls_set.side_effect = error
|
||||
mock_try_connection_protocol_check.side_effect = error
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: protocol,
|
||||
CONF_CERTIFICATE_FILE: "/ssl/mqtt/ca.crt",
|
||||
CONF_CLIENT_CERT_FILE: "/ssl/mqtt/client.crt",
|
||||
CONF_CLIENT_KEY_FILE: "/ssl/mqtt/client.key",
|
||||
@@ -2059,8 +1932,6 @@ async def test_setup_certificates_cannot_be_loaded(
|
||||
)
|
||||
# The listeners of the client that failed to set up are removed
|
||||
assert mock_cleanup.call_count == 1
|
||||
# The protocol migration is tried again when the setup is retried
|
||||
assert issue_registry.async_get_issue(DOMAIN, "protocol_5_migration") is None
|
||||
|
||||
# Publishing is refused cleanly while the setup is retried
|
||||
with pytest.raises(
|
||||
@@ -2085,7 +1956,6 @@ async def test_setup_certificates_cannot_be_loaded(
|
||||
unsubscribe_removed()
|
||||
|
||||
mqtt_client_mock.tls_set.side_effect = None
|
||||
mock_try_connection_protocol_check.side_effect = None
|
||||
await hass.config_entries.async_reload(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
@@ -2795,7 +2665,6 @@ async def test_loop_write_failure(
|
||||
(
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "5",
|
||||
},
|
||||
ENTRY_DEFAULT_BIRTH_MESSAGE,
|
||||
),
|
||||
|
||||
@@ -94,13 +94,7 @@ from homeassistant.config_entries import (
|
||||
ConfigSubentry,
|
||||
ConfigSubentryData,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_CLIENT_ID,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_PROTOCOL,
|
||||
CONF_USERNAME,
|
||||
)
|
||||
from homeassistant.const import CONF_CLIENT_ID, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
from homeassistant.helpers import (
|
||||
@@ -124,8 +118,7 @@ ADD_ON_DISCOVERY_INFO = {
|
||||
|
||||
MOCK_BROKER_FORM_DATA = {
|
||||
mqtt.CONF_BROKER: "127.0.0.1",
|
||||
mqtt.CONF_PORT: "1883",
|
||||
mqtt.CONF_PROTOCOL: "5",
|
||||
CONF_PORT: "1883",
|
||||
OTHER_SETTINGS: {
|
||||
mqtt.CONF_TRANSPORT: "tcp",
|
||||
SET_CLIENT_CERT: False,
|
||||
@@ -135,7 +128,6 @@ MOCK_BROKER_FORM_DATA = {
|
||||
MOCK_BROKER_ENTRY_DATA = {
|
||||
"broker": "127.0.0.1",
|
||||
"port": 1883,
|
||||
"protocol": "5",
|
||||
"transport": "tcp",
|
||||
}
|
||||
|
||||
@@ -676,7 +668,6 @@ async def test_hassio_confirm(
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["result"].data == {
|
||||
"broker": "core-mosquitto",
|
||||
"protocol": "5",
|
||||
"port": 1883,
|
||||
"username": "mock-user",
|
||||
"password": "mock-pass",
|
||||
@@ -774,7 +765,6 @@ async def test_addon_flow_with_supervisor_addon_running(
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["result"].data == {
|
||||
"broker": "core-mosquitto",
|
||||
"protocol": "5",
|
||||
"port": 1883,
|
||||
"username": "mock-user",
|
||||
"password": "mock-pass",
|
||||
@@ -841,7 +831,6 @@ async def test_addon_flow_with_supervisor_addon_installed(
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["result"].data == {
|
||||
"broker": "core-mosquitto",
|
||||
"protocol": "5",
|
||||
"port": 1883,
|
||||
"username": "mock-user",
|
||||
"password": "mock-pass",
|
||||
@@ -1080,7 +1069,6 @@ async def test_addon_flow_with_supervisor_addon_not_installed(
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["result"].data == {
|
||||
"broker": "core-mosquitto",
|
||||
"protocol": "5",
|
||||
"port": 1883,
|
||||
"username": "mock-user",
|
||||
"password": "mock-pass",
|
||||
@@ -1177,7 +1165,6 @@ async def test_option_flow(
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
assert config_entry.data == {
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "5",
|
||||
}
|
||||
assert config_entry.options == {
|
||||
mqtt.CONF_DISCOVERY: True,
|
||||
@@ -1268,7 +1255,6 @@ async def test_bad_certificate_validation(
|
||||
test_input = {
|
||||
mqtt.CONF_BROKER: "another-broker",
|
||||
CONF_PORT: 2345,
|
||||
mqtt.CONF_PROTOCOL: "5",
|
||||
OTHER_SETTINGS: {
|
||||
mqtt.CONF_CERTIFICATE: file_id[mqtt.CONF_CERTIFICATE],
|
||||
mqtt.CONF_CLIENT_CERT: file_id[mqtt.CONF_CLIENT_CERT],
|
||||
@@ -1796,7 +1782,6 @@ async def test_step_hassio_reauth(
|
||||
mock_try_connection.assert_called_once_with(
|
||||
{
|
||||
"broker": "core-mosquitto",
|
||||
CONF_PROTOCOL: "5",
|
||||
"port": 1883,
|
||||
"username": "mock-user",
|
||||
"password": "mock-pass",
|
||||
@@ -2044,7 +2029,6 @@ async def test_reconfigure_with_tls_client_key_formats(
|
||||
config_entry,
|
||||
data={
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PROTOCOL: "5",
|
||||
CONF_PORT: 1234,
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "pass",
|
||||
@@ -2068,13 +2052,11 @@ async def test_reconfigure_with_tls_client_key_formats(
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: PWD_NOT_CHANGED,
|
||||
mqtt.CONF_TLS_INSECURE: None,
|
||||
CONF_PROTOCOL: "5",
|
||||
}
|
||||
suggested_other_settings = {
|
||||
"username": None,
|
||||
"password": None,
|
||||
"tls_insecure": True,
|
||||
"protocol": None,
|
||||
OTHER_SETTINGS: None,
|
||||
}
|
||||
|
||||
@@ -2097,7 +2079,6 @@ async def test_reconfigure_with_tls_client_key_formats(
|
||||
user_input={
|
||||
mqtt.CONF_BROKER: "another-broker",
|
||||
CONF_PORT: 2345,
|
||||
CONF_PROTOCOL: "5",
|
||||
CONF_USERNAME: "us3r",
|
||||
CONF_PASSWORD: "p4ss",
|
||||
OTHER_SETTINGS: {
|
||||
@@ -2190,7 +2171,6 @@ async def test_setup_with_advanced_settings(
|
||||
CONF_PORT: 2345,
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "secret",
|
||||
CONF_PROTOCOL: "5",
|
||||
OTHER_SETTINGS: {
|
||||
mqtt.CONF_KEEPALIVE: 30,
|
||||
SET_CA_CERT: "auto",
|
||||
@@ -2207,8 +2187,6 @@ async def test_setup_with_advanced_settings(
|
||||
},
|
||||
)
|
||||
|
||||
assert result["data_schema"].schema[CONF_PROTOCOL]
|
||||
|
||||
for key in (
|
||||
CONF_CLIENT_ID,
|
||||
mqtt.CONF_KEEPALIVE,
|
||||
@@ -2234,7 +2212,6 @@ async def test_setup_with_advanced_settings(
|
||||
user_input={
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 2345,
|
||||
CONF_PROTOCOL: "5",
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "secret",
|
||||
OTHER_SETTINGS: {
|
||||
@@ -2259,7 +2236,6 @@ async def test_setup_with_advanced_settings(
|
||||
# Check config entry result
|
||||
assert config_entry.data == {
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PROTOCOL: "5",
|
||||
CONF_PORT: 2345,
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "secret",
|
||||
@@ -2332,7 +2308,6 @@ async def test_setup_with_certificates(
|
||||
user_input={
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 2345,
|
||||
CONF_PROTOCOL: "5",
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "secret",
|
||||
OTHER_SETTINGS: {
|
||||
@@ -2355,7 +2330,6 @@ async def test_setup_with_certificates(
|
||||
user_input={
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 2345,
|
||||
CONF_PROTOCOL: "5",
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "secret",
|
||||
OTHER_SETTINGS: {
|
||||
@@ -2385,7 +2359,6 @@ async def test_setup_with_certificates(
|
||||
user_input={
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 1234,
|
||||
CONF_PROTOCOL: "5",
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "secret",
|
||||
OTHER_SETTINGS: {
|
||||
@@ -2407,7 +2380,6 @@ async def test_setup_with_certificates(
|
||||
# Check config entry data is set
|
||||
assert result["data"] == {
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PROTOCOL: "5",
|
||||
CONF_PORT: 1234,
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "secret",
|
||||
@@ -2436,7 +2408,6 @@ async def test_change_websockets_transport_to_tcp(
|
||||
data={
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 1234,
|
||||
CONF_PROTOCOL: "5",
|
||||
mqtt.CONF_TRANSPORT: "websockets",
|
||||
mqtt.CONF_WS_HEADERS: {"header_1": "custom_header1"},
|
||||
mqtt.CONF_WS_PATH: "/some_path",
|
||||
@@ -2455,7 +2426,6 @@ async def test_change_websockets_transport_to_tcp(
|
||||
user_input={
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 1234,
|
||||
CONF_PROTOCOL: "5",
|
||||
OTHER_SETTINGS: {
|
||||
SET_CA_CERT: "off",
|
||||
SET_CLIENT_CERT: False,
|
||||
@@ -2472,7 +2442,6 @@ async def test_change_websockets_transport_to_tcp(
|
||||
assert config_entry.data == {
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 1234,
|
||||
CONF_PROTOCOL: "5",
|
||||
mqtt.CONF_TRANSPORT: "tcp",
|
||||
}
|
||||
|
||||
@@ -2533,7 +2502,6 @@ async def test_reconfigure_flow_form(
|
||||
user_input={
|
||||
mqtt.CONF_BROKER: "10.10.10,10",
|
||||
CONF_PORT: 1234,
|
||||
CONF_PROTOCOL: "5",
|
||||
OTHER_SETTINGS: {
|
||||
SET_CA_CERT: "custom",
|
||||
SET_CLIENT_CERT: True,
|
||||
@@ -2549,7 +2517,6 @@ async def test_reconfigure_flow_form(
|
||||
assert entry.data == {
|
||||
mqtt.CONF_BROKER: "10.10.10,10",
|
||||
CONF_PORT: 1234,
|
||||
CONF_PROTOCOL: "5",
|
||||
mqtt.CONF_TRANSPORT: "websockets",
|
||||
mqtt.CONF_WS_HEADERS: {"header_1": "custom_header1"},
|
||||
mqtt.CONF_WS_PATH: "/some_new_path",
|
||||
@@ -2574,7 +2541,6 @@ async def test_reconfigure_with_certificate_files(
|
||||
data={
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 8883,
|
||||
CONF_PROTOCOL: "5",
|
||||
mqtt.CONF_CERTIFICATE: MOCK_GENERIC_CERT.decode(encoding="utf-8"),
|
||||
mqtt.CONF_CLIENT_CERT: MOCK_GENERIC_CERT.decode(encoding="utf-8"),
|
||||
mqtt.CONF_CLIENT_KEY: MOCK_CLIENT_KEY.decode(encoding="utf-8"),
|
||||
@@ -2591,7 +2557,6 @@ async def test_reconfigure_with_certificate_files(
|
||||
user_input={
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 8883,
|
||||
CONF_PROTOCOL: "5",
|
||||
OTHER_SETTINGS: {
|
||||
SET_CA_CERT: "custom",
|
||||
SET_CLIENT_CERT: True,
|
||||
@@ -2607,7 +2572,6 @@ async def test_reconfigure_with_certificate_files(
|
||||
assert config_entry.data == {
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 8883,
|
||||
CONF_PROTOCOL: "5",
|
||||
mqtt.CONF_TRANSPORT: "tcp",
|
||||
CONF_CERTIFICATE_FILE: mock_certificate_files[CONF_CERTIFICATE_FILE],
|
||||
CONF_CLIENT_CERT_FILE: mock_certificate_files[CONF_CLIENT_CERT_FILE],
|
||||
@@ -2653,7 +2617,7 @@ async def test_reconfigure_reloads_entry_that_failed_to_set_up(
|
||||
domain=DOMAIN,
|
||||
version=mqtt.CONFIG_ENTRY_VERSION,
|
||||
minor_version=mqtt.CONFIG_ENTRY_MINOR_VERSION,
|
||||
data={mqtt.CONF_BROKER: "test-broker", CONF_PORT: 8883, CONF_PROTOCOL: "5"},
|
||||
data={mqtt.CONF_BROKER: "test-broker", CONF_PORT: 8883},
|
||||
state=ConfigEntryState.SETUP_RETRY,
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
@@ -2666,7 +2630,6 @@ async def test_reconfigure_reloads_entry_that_failed_to_set_up(
|
||||
user_input={
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 8883,
|
||||
CONF_PROTOCOL: "5",
|
||||
OTHER_SETTINGS: {
|
||||
SET_CA_CERT: "custom",
|
||||
SET_CLIENT_CERT: True,
|
||||
@@ -2704,7 +2667,6 @@ async def test_reconfigure_ignores_file_paths_of_disabled_settings(
|
||||
data={
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 8883,
|
||||
CONF_PROTOCOL: "5",
|
||||
}
|
||||
| mock_certificate_files,
|
||||
)
|
||||
@@ -2718,7 +2680,6 @@ async def test_reconfigure_ignores_file_paths_of_disabled_settings(
|
||||
user_input={
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 8883,
|
||||
CONF_PROTOCOL: "5",
|
||||
OTHER_SETTINGS: {
|
||||
SET_CA_CERT: set_ca_cert,
|
||||
SET_CLIENT_CERT: False,
|
||||
@@ -2734,7 +2695,6 @@ async def test_reconfigure_ignores_file_paths_of_disabled_settings(
|
||||
== {
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 8883,
|
||||
CONF_PROTOCOL: "5",
|
||||
mqtt.CONF_TRANSPORT: "tcp",
|
||||
}
|
||||
| expected_ca_settings
|
||||
@@ -2857,7 +2817,6 @@ async def test_certificate_file_path_validation(
|
||||
user_input={
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 8883,
|
||||
CONF_PROTOCOL: "5",
|
||||
OTHER_SETTINGS: other_settings,
|
||||
},
|
||||
)
|
||||
@@ -2870,7 +2829,6 @@ async def test_certificate_file_path_validation(
|
||||
user_input={
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 8883,
|
||||
CONF_PROTOCOL: "5",
|
||||
OTHER_SETTINGS: {
|
||||
SET_CA_CERT: "custom",
|
||||
SET_CLIENT_CERT: True,
|
||||
@@ -2883,7 +2841,6 @@ async def test_certificate_file_path_validation(
|
||||
assert result["data"] == {
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 8883,
|
||||
CONF_PROTOCOL: "5",
|
||||
mqtt.CONF_TRANSPORT: "tcp",
|
||||
CONF_CERTIFICATE_FILE: mock_certificate_files[CONF_CERTIFICATE_FILE],
|
||||
CONF_CLIENT_CERT_FILE: mock_certificate_files[CONF_CLIENT_CERT_FILE],
|
||||
@@ -2924,7 +2881,6 @@ async def test_certificate_file_path_settings_invalid(
|
||||
user_input = {
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 8883,
|
||||
CONF_PROTOCOL: "5",
|
||||
OTHER_SETTINGS: {
|
||||
SET_CA_CERT: "custom",
|
||||
SET_CLIENT_CERT: True,
|
||||
@@ -2982,7 +2938,6 @@ async def test_certificate_file_cannot_be_read(
|
||||
user_input = {
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 8883,
|
||||
CONF_PROTOCOL: "5",
|
||||
OTHER_SETTINGS: {
|
||||
SET_CA_CERT: "custom",
|
||||
SET_CLIENT_CERT: True,
|
||||
@@ -3037,7 +2992,6 @@ async def test_certificate_files_cannot_be_loaded(
|
||||
user_input = {
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 8883,
|
||||
CONF_PROTOCOL: "5",
|
||||
OTHER_SETTINGS: {
|
||||
SET_CA_CERT: "custom",
|
||||
SET_CLIENT_CERT: True,
|
||||
@@ -3161,7 +3115,6 @@ async def test_certificate_file_content_validation(
|
||||
user_input = {
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 8883,
|
||||
CONF_PROTOCOL: "5",
|
||||
OTHER_SETTINGS: {
|
||||
SET_CA_CERT: "custom",
|
||||
SET_CLIENT_CERT: True,
|
||||
@@ -3192,7 +3145,6 @@ async def test_certificate_file_content_validation(
|
||||
== {
|
||||
mqtt.CONF_BROKER: "test-broker",
|
||||
CONF_PORT: 8883,
|
||||
CONF_PROTOCOL: "5",
|
||||
mqtt.CONF_TRANSPORT: "tcp",
|
||||
}
|
||||
| file_paths
|
||||
@@ -3210,7 +3162,6 @@ async def test_certificate_file_content_validation(
|
||||
CONF_USERNAME: "mqtt-user",
|
||||
CONF_PASSWORD: "mqtt-password",
|
||||
CONF_PORT: 1234,
|
||||
CONF_PROTOCOL: "5",
|
||||
mqtt.CONF_TRANSPORT: "websockets",
|
||||
mqtt.CONF_WS_HEADERS: {"header_1": "custom_header1"},
|
||||
mqtt.CONF_WS_PATH: "/some_path",
|
||||
@@ -3253,7 +3204,6 @@ async def test_reconfigure_no_changed_password(
|
||||
CONF_USERNAME: "mqtt-user",
|
||||
CONF_PASSWORD: "mqtt-password",
|
||||
CONF_PORT: 1234,
|
||||
CONF_PROTOCOL: "5",
|
||||
mqtt.CONF_CERTIFICATE: "auto",
|
||||
mqtt.CONF_TRANSPORT: "websockets",
|
||||
mqtt.CONF_WS_HEADERS: {"header_1": "custom_header1"},
|
||||
|
||||
@@ -20,7 +20,7 @@ from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
default_entry_data = {"broker": "mock-broker", "protocol": "5"}
|
||||
default_entry_data = {"broker": "mock-broker"}
|
||||
default_entry_options = {"birth_message": {}}
|
||||
|
||||
|
||||
@@ -146,7 +146,6 @@ async def test_entry_diagnostics(
|
||||
(
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
mqtt.CONF_PROTOCOL: "5",
|
||||
CONF_PASSWORD: "hunter2",
|
||||
CONF_USERNAME: "my_user",
|
||||
},
|
||||
|
||||
@@ -6,7 +6,6 @@ from copy import deepcopy
|
||||
from datetime import datetime, timedelta
|
||||
from functools import partial
|
||||
import json
|
||||
import logging
|
||||
import time
|
||||
from typing import Any, TypedDict
|
||||
from unittest.mock import ANY, MagicMock, Mock, mock_open, patch
|
||||
@@ -49,8 +48,6 @@ from homeassistant.components.sensor import SensorDeviceClass
|
||||
from homeassistant.config_entries import ConfigEntryDisabler, ConfigEntryState
|
||||
from homeassistant.const import (
|
||||
ATTR_ASSUMED_STATE,
|
||||
CONF_PORT,
|
||||
CONF_PROTOCOL,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
__version__ as HA_VERSION,
|
||||
@@ -2232,7 +2229,7 @@ async def test_unload_config_entry(
|
||||
"""Test unloading the MQTT entry."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={mqtt.CONF_BROKER: "test-broker", CONF_PROTOCOL: "5"},
|
||||
data={mqtt.CONF_BROKER: "test-broker"},
|
||||
version=mqtt.CONFIG_ENTRY_VERSION,
|
||||
minor_version=mqtt.CONFIG_ENTRY_MINOR_VERSION,
|
||||
)
|
||||
@@ -2989,133 +2986,6 @@ async def test_yaml_config_with_active_mqtt_config_entry(
|
||||
assert issue is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mqtt_config_entry_data",
|
||||
[
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
},
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PORT: 1883,
|
||||
},
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "3.1.1",
|
||||
CONF_PORT: 1883,
|
||||
},
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "3.1",
|
||||
CONF_PORT: 1883,
|
||||
},
|
||||
],
|
||||
ids=[
|
||||
"entry_without_protocol_without_port",
|
||||
"entry_without_protocol_with_port",
|
||||
"entry_with_protocol_3.1.1",
|
||||
"entry_with_protocol_3.1",
|
||||
],
|
||||
)
|
||||
async def test_mqtt_protocol_successful_migration_to_v5(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the silent MQTT protocol migration is successful."""
|
||||
assert await async_setup_component(hass, "repairs", {})
|
||||
|
||||
events = async_capture_events(hass, ir.EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED)
|
||||
|
||||
with caplog.at_level(logging.INFO):
|
||||
await mqtt_mock_entry()
|
||||
assert len(events) == 0
|
||||
assert (
|
||||
"The MQTT protocol version was successfully updated to version 5"
|
||||
in caplog.text
|
||||
)
|
||||
entry = hass.config_entries.async_entries(DOMAIN)[0]
|
||||
assert entry.data[mqtt.CONF_PROTOCOL] == mqtt.PROTOCOL_5
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mock_v5_protocol_check", [False])
|
||||
@pytest.mark.parametrize(
|
||||
("mqtt_config_entry_data", "current_protocol"),
|
||||
[
|
||||
(
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
},
|
||||
"3.1.1",
|
||||
),
|
||||
(
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PORT: 1883,
|
||||
},
|
||||
"3.1.1",
|
||||
),
|
||||
(
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "3.1.1",
|
||||
CONF_PORT: 1883,
|
||||
},
|
||||
"3.1.1",
|
||||
),
|
||||
(
|
||||
{
|
||||
mqtt.CONF_BROKER: "mock-broker",
|
||||
CONF_PROTOCOL: "3.1",
|
||||
CONF_PORT: 1883,
|
||||
},
|
||||
"3.1",
|
||||
),
|
||||
],
|
||||
ids=[
|
||||
"entry_without_protocol_without_port",
|
||||
"entry_without_protocol_with_port",
|
||||
"entry_with_protocol_3.1.1",
|
||||
"entry_with_protocol_3.1",
|
||||
],
|
||||
)
|
||||
async def test_mqtt_protocol_failed_migration_to_v5(
|
||||
hass: HomeAssistant,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
current_protocol: str,
|
||||
) -> None:
|
||||
"""Test failed silent MQTT protocol migration creates a repair issue."""
|
||||
assert await async_setup_component(hass, "repairs", {})
|
||||
|
||||
events = async_capture_events(hass, ir.EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED)
|
||||
|
||||
await mqtt_mock_entry()
|
||||
assert len(events) == 1
|
||||
assert events[0].data["issue_id"] == "protocol_5_migration"
|
||||
|
||||
assert len(issue_registry.issues) == 1
|
||||
issue = issue_registry.async_get_issue(DOMAIN, "protocol_5_migration")
|
||||
assert issue is not None
|
||||
assert issue.translation_key == "protocol_5_migration"
|
||||
assert issue.translation_placeholders == {
|
||||
"broker": "mock-broker",
|
||||
"protocol": current_protocol,
|
||||
}
|
||||
assert (
|
||||
"The MQTT protocol version was successfully updated to version 5"
|
||||
not in caplog.text
|
||||
)
|
||||
entry = hass.config_entries.async_entries(DOMAIN)[0]
|
||||
assert issue.config_entry_id == entry.entry_id
|
||||
assert entry.data.get(mqtt.CONF_PROTOCOL, mqtt.PROTOCOL_311) == current_protocol
|
||||
|
||||
await hass.config_entries.async_remove(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert issue_registry.async_get_issue(DOMAIN, "protocol_5_migration") is None
|
||||
|
||||
|
||||
INVALID_SENSOR_1 = {
|
||||
"name": "test_1",
|
||||
"state_topic": "test-topic",
|
||||
|
||||
@@ -335,7 +335,7 @@ async def test_default_entity_and_device_name(
|
||||
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={mqtt.CONF_BROKER: "mock-broker", mqtt.CONF_PROTOCOL: "5"},
|
||||
data={mqtt.CONF_BROKER: "mock-broker"},
|
||||
version=mqtt.CONFIG_ENTRY_VERSION,
|
||||
minor_version=mqtt.CONFIG_ENTRY_MINOR_VERSION,
|
||||
)
|
||||
|
||||
@@ -52,7 +52,7 @@ from homeassistant.config_entries import (
|
||||
ConfigSubentry,
|
||||
ConfigSubentryData,
|
||||
)
|
||||
from homeassistant.const import CONF_PROTOCOL, SERVICE_RELOAD
|
||||
from homeassistant.const import SERVICE_RELOAD
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
from homeassistant.helpers import device_registry as dr, issue_registry as ir
|
||||
@@ -289,7 +289,7 @@ async def _async_setup_entry(
|
||||
"""Set up the MQTT entry with the client certificate settings."""
|
||||
entry: MockConfigEntry = hass.config_entries.async_entries(DOMAIN)[0]
|
||||
hass.config_entries.async_update_entry(
|
||||
entry, data={CONF_BROKER: "mock-broker", CONF_PROTOCOL: "5"} | data
|
||||
entry, data={CONF_BROKER: "mock-broker"} | data
|
||||
)
|
||||
await mqtt_mock_entry()
|
||||
return entry
|
||||
|
||||
Reference in New Issue
Block a user