diff --git a/tests/components/mqtt/test_alarm_control_panel.py b/tests/components/mqtt/test_alarm_control_panel.py index 020d361a052..a7e5678a3b7 100644 --- a/tests/components/mqtt/test_alarm_control_panel.py +++ b/tests/components/mqtt/test_alarm_control_panel.py @@ -1,6 +1,7 @@ """The tests the MQTT alarm control panel component.""" import copy import json +from typing import Any from unittest.mock import patch import pytest @@ -9,6 +10,7 @@ from homeassistant.components import alarm_control_panel, mqtt from homeassistant.components.mqtt.alarm_control_panel import ( MQTT_ALARM_ATTRIBUTES_BLOCKED, ) +from homeassistant.components.mqtt.models import PublishPayloadType from homeassistant.const import ( ATTR_CODE, ATTR_ENTITY_ID, @@ -58,7 +60,6 @@ from .test_common import ( help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_unload_config_entry_with_platform, help_test_update_with_json_attrs_bad_json, @@ -172,10 +173,7 @@ async def test_fail_setup_without_state_or_command_topic( hass: HomeAssistant, config, valid ) -> None: """Test for failing setup with no state or command topic.""" - assert ( - help_test_validate_platform_config(hass, alarm_control_panel.DOMAIN, config) - == valid - ) + assert help_test_validate_platform_config(hass, config) == valid @pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) @@ -722,30 +720,35 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + alarm_control_panel.DOMAIN: [ + { + "name": "Test 1", + "state_topic": "test-topic", + "command_topic": "command-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Test 2", + "state_topic": "test-topic", + "command_topic": "command-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one alarm per unique_id.""" - config = { - mqtt.DOMAIN: { - alarm_control_panel.DOMAIN: [ - { - "name": "Test 1", - "state_topic": "test-topic", - "command_topic": "command-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Test 2", - "state_topic": "test-topic", - "command_topic": "command-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, alarm_control_panel.DOMAIN, config + hass, mqtt_mock_entry_no_yaml_config, alarm_control_panel.DOMAIN ) @@ -888,16 +891,14 @@ async def test_discovery_broken( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, - caplog: pytest.LogCaptureFixture, - topic, - value, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + topic: str, + value: str, ) -> None: """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_with_yaml_config, - caplog, + mqtt_mock_entry_no_yaml_config, alarm_control_panel.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][alarm_control_panel.DOMAIN], topic, @@ -954,14 +955,11 @@ async def test_entity_device_info_remove( async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, - mqtt_mock_entry_with_yaml_config, - alarm_control_panel.DOMAIN, - DEFAULT_CONFIG, + hass, mqtt_mock_entry_no_yaml_config, alarm_control_panel.DOMAIN, DEFAULT_CONFIG ) @@ -1016,15 +1014,15 @@ async def test_entity_debug_info_message( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, - service, - topic, - parameters, - payload, - template, - tpl_par, - tpl_output, + service: str, + topic: str, + parameters: dict[str, Any], + payload: str, + template: str | None, + tpl_par: str, + tpl_output: PublishPayloadType, ) -> None: """Test publishing MQTT payload with different encoding.""" domain = alarm_control_panel.DOMAIN @@ -1032,7 +1030,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, caplog, domain, config, @@ -1056,10 +1054,13 @@ async def test_reloadable( await help_test_reloadable(hass, mqtt_client_mock, domain, config) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = alarm_control_panel.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_binary_sensor.py b/tests/components/mqtt/test_binary_sensor.py index 49417c3142e..3e224a4136a 100644 --- a/tests/components/mqtt/test_binary_sensor.py +++ b/tests/components/mqtt/test_binary_sensor.py @@ -3,6 +3,7 @@ import copy from datetime import datetime, timedelta import json from pathlib import Path +from typing import Any from unittest.mock import patch from freezegun.api import FrozenDateTimeFactory @@ -43,7 +44,6 @@ from .test_common import ( help_test_reloadable, help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_unload_config_entry_with_platform, help_test_update_with_json_attrs_bad_json, @@ -781,28 +781,33 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + binary_sensor.DOMAIN: [ + { + "name": "Test 1", + "state_topic": "test-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Test 2", + "state_topic": "test-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one sensor per unique_id.""" - config = { - mqtt.DOMAIN: { - binary_sensor.DOMAIN: [ - { - "name": "Test 1", - "state_topic": "test-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Test 2", - "state_topic": "test-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, binary_sensor.DOMAIN, config + hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN ) @@ -909,18 +914,16 @@ async def test_discovery_update_binary_sensor_template( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, - caplog: pytest.LogCaptureFixture, - topic, - value, - attribute, - attribute_value, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + topic: str, + value: str, + attribute: str | None, + attribute_value: Any, ) -> None: """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_with_yaml_config, - caplog, + mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][binary_sensor.DOMAIN], topic, @@ -1021,14 +1024,11 @@ async def test_entity_device_info_remove( async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, - mqtt_mock_entry_with_yaml_config, - binary_sensor.DOMAIN, - DEFAULT_CONFIG, + hass, mqtt_mock_entry_no_yaml_config, binary_sensor.DOMAIN, DEFAULT_CONFIG ) @@ -1162,10 +1162,13 @@ async def test_skip_restoring_state_with_over_due_expire_trigger( assert state.state == STATE_UNAVAILABLE -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = binary_sensor.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_button.py b/tests/components/mqtt/test_button.py index bfbee72bd1f..cdb3d0fbf38 100644 --- a/tests/components/mqtt/test_button.py +++ b/tests/components/mqtt/test_button.py @@ -1,5 +1,6 @@ """The tests for the MQTT button platform.""" import copy +from typing import Any from unittest.mock import patch import pytest @@ -35,7 +36,6 @@ from .test_common import ( help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_unload_config_entry_with_platform, help_test_update_with_json_attrs_bad_json, @@ -277,29 +277,32 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + button.DOMAIN: [ + { + "name": "Test 1", + "command_topic": "command-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Test 2", + "command_topic": "command-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one button per unique_id.""" - config = { - mqtt.DOMAIN: { - button.DOMAIN: [ - { - "name": "Test 1", - "command_topic": "command-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Test 2", - "command_topic": "command-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, button.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, button.DOMAIN) async def test_discovery_removal_button( @@ -497,13 +500,13 @@ async def test_valid_device_class( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, - service, - topic, - parameters, - payload, - template, + service: str, + topic: str, + parameters: dict[str, Any], + payload: str, + template: str | None, ) -> None: """Test publishing MQTT payload with different encoding.""" domain = button.DOMAIN @@ -511,7 +514,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, caplog, domain, config, @@ -533,10 +536,13 @@ async def test_reloadable( await help_test_reloadable(hass, mqtt_client_mock, domain, config) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = button.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_camera.py b/tests/components/mqtt/test_camera.py index 4ff15f8d32d..90020bce489 100644 --- a/tests/components/mqtt/test_camera.py +++ b/tests/components/mqtt/test_camera.py @@ -33,7 +33,6 @@ from .test_common import ( help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_unload_config_entry_with_platform, help_test_update_with_json_attrs_bad_json, @@ -271,29 +270,32 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + camera.DOMAIN: [ + { + "name": "Test 1", + "topic": "test-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Test 2", + "topic": "test-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one camera per unique_id.""" - config = { - mqtt.DOMAIN: { - camera.DOMAIN: [ - { - "name": "Test 1", - "topic": "test-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Test 2", - "topic": "test-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, camera.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, camera.DOMAIN) async def test_discovery_removal_camera( @@ -394,12 +396,12 @@ async def test_entity_device_info_remove( async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, camera.DOMAIN, DEFAULT_CONFIG, ["test_topic"], @@ -440,10 +442,13 @@ async def test_reloadable( await help_test_reloadable(hass, mqtt_client_mock, domain, config) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = camera.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_climate.py b/tests/components/mqtt/test_climate.py index 0ea9588992c..9a9a9d81e8e 100644 --- a/tests/components/mqtt/test_climate.py +++ b/tests/components/mqtt/test_climate.py @@ -1,6 +1,7 @@ """The tests for the mqtt climate component.""" import copy import json +from typing import Any from unittest.mock import call, patch import pytest @@ -54,7 +55,6 @@ from .test_common import ( help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_unload_config_entry_with_platform, help_test_update_with_json_attrs_bad_json, @@ -1562,31 +1562,34 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + climate.DOMAIN: [ + { + "name": "Test 1", + "mode_state_topic": "test_topic1/state", + "mode_command_topic": "test_topic1/command", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Test 2", + "mode_state_topic": "test_topic2/state", + "mode_command_topic": "test_topic2/command", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one climate per unique_id.""" - config = { - mqtt.DOMAIN: { - climate.DOMAIN: [ - { - "name": "Test 1", - "mode_state_topic": "test_topic1/state", - "mode_command_topic": "test_topic1/command", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Test 2", - "mode_state_topic": "test_topic2/state", - "mode_command_topic": "test_topic2/command", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, climate.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, climate.DOMAIN) @pytest.mark.parametrize( @@ -1609,19 +1612,17 @@ async def test_unique_id( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, - caplog: pytest.LogCaptureFixture, - topic, - value, - attribute, - attribute_value, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + topic: str, + value: str, + attribute: str | None, + attribute_value: Any, ) -> None: """Test handling of incoming encoded payload.""" config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][climate.DOMAIN]) await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_with_yaml_config, - caplog, + mqtt_mock_entry_no_yaml_config, climate.DOMAIN, config, topic, @@ -1727,7 +1728,7 @@ async def test_entity_device_info_remove( async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" config = { @@ -1741,7 +1742,7 @@ async def test_entity_id_update_subscriptions( } await help_test_entity_id_update_subscriptions( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, climate.DOMAIN, config, ["test-topic", "avty-topic"], @@ -1919,13 +1920,13 @@ async def test_precision_whole( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, - service, - topic, - parameters, - payload, - template, + service: str, + topic: str, + parameters: dict[str, Any], + payload: str, + template: str | None, ) -> None: """Test publishing MQTT payload with different encoding.""" domain = climate.DOMAIN @@ -1936,7 +1937,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, caplog, domain, config, @@ -2016,10 +2017,13 @@ async def test_reloadable( await help_test_reloadable(hass, mqtt_client_mock, domain, config) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = climate.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_common.py b/tests/components/mqtt/test_common.py index 88d993ef5d6..f5a4648e34c 100644 --- a/tests/components/mqtt/test_common.py +++ b/tests/components/mqtt/test_common.py @@ -17,6 +17,7 @@ from homeassistant.components.mqtt import debug_info from homeassistant.components.mqtt.config_integration import PLATFORM_CONFIG_SCHEMA_BASE from homeassistant.components.mqtt.const import MQTT_DISCONNECTED from homeassistant.components.mqtt.mixins import MQTT_ATTRIBUTES_BLOCKED +from homeassistant.components.mqtt.models import PublishPayloadType from homeassistant.config import async_log_exception from homeassistant.config_entries import ConfigEntryState from homeassistant.const import ( @@ -73,7 +74,7 @@ MQTT_YAML_SCHEMA = vol.Schema({mqtt.DOMAIN: PLATFORM_CONFIG_SCHEMA_BASE}) def help_test_validate_platform_config( - hass: HomeAssistant, domain: str, config: ConfigType + hass: HomeAssistant, config: ConfigType ) -> ConfigType | None: """Test the schema validation.""" try: @@ -82,7 +83,7 @@ def help_test_validate_platform_config( return True except vol.Error as exc: # log schema exceptions - async_log_exception(exc, domain, config, hass) + async_log_exception(exc, mqtt.DOMAIN, config, hass) return False @@ -394,10 +395,10 @@ async def help_test_default_availability_list_single( {"topic": "availability-topic1"}, ] config[mqtt.DOMAIN][domain]["availability_topic"] = "availability-topic" - help_test_validate_platform_config(hass, domain, config) + help_test_validate_platform_config(hass, config) assert ( - f"Invalid config for [{domain}]: two or more values in the same group of exclusion 'availability'" + "Invalid config for [mqtt]: two or more values in the same group of exclusion 'availability'" in caplog.text ) @@ -698,14 +699,12 @@ async def help_test_discovery_update_attr( async def help_test_unique_id( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, domain: str, - config: ConfigType, ) -> None: """Test unique id option only creates one entity per unique_id.""" - assert await async_setup_component(hass, mqtt.DOMAIN, config) + await mqtt_mock_entry_no_yaml_config() await hass.async_block_till_done() - await mqtt_mock_entry_with_yaml_config() assert len(hass.states.async_entity_ids(domain)) == 1 @@ -854,15 +853,14 @@ async def help_test_discovery_broken( async def help_test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, - caplog: pytest.LogCaptureFixture, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, domain: str, config: ConfigType, topic: str, value: Any, attribute: str | None = None, attribute_value: Any = None, - init_payload: str | None = None, + init_payload: tuple[str, str] | None = None, skip_raw_test: bool = False, ) -> None: """Test handling of incoming encoded payload.""" @@ -929,13 +927,17 @@ async def help_test_encoding_subscribable_topics( init_payload_value_utf8 = init_payload[1].encode("utf-8") init_payload_value_utf16 = init_payload[1].encode("utf-16") - await hass.async_block_till_done() - - assert await async_setup_component( - hass, mqtt.DOMAIN, {mqtt.DOMAIN: {domain: [config1, config2, config3]}} + await mqtt_mock_entry_no_yaml_config() + async_fire_mqtt_message( + hass, f"homeassistant/{domain}/item1/config", json.dumps(config1) + ) + async_fire_mqtt_message( + hass, f"homeassistant/{domain}/item2/config", json.dumps(config2) + ) + async_fire_mqtt_message( + hass, f"homeassistant/{domain}/item3/config", json.dumps(config3) ) await hass.async_block_till_done() - await mqtt_mock_entry_with_yaml_config() expected_result = attribute_value or value @@ -1124,7 +1126,7 @@ async def help_test_entity_device_info_update( async def help_test_entity_id_update_subscriptions( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, domain: str, config: ConfigType, topics: list[str] | None = None, @@ -1142,13 +1144,10 @@ async def help_test_entity_id_update_subscriptions( assert len(topics) > 0 entity_registry = er.async_get(hass) - assert await async_setup_component( - hass, - mqtt.DOMAIN, - config, + mqtt_mock = await help_setup_component( + hass, mqtt_mock_entry_no_yaml_config, domain, config, True ) - await hass.async_block_till_done() - mqtt_mock = await mqtt_mock_entry_with_yaml_config() + assert mqtt_mock is not None state = hass.states.get(f"{domain}.test") assert state is not None @@ -1632,7 +1631,7 @@ async def help_test_entity_category( async def help_test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, domain: str, config: ConfigType, @@ -1642,7 +1641,7 @@ async def help_test_publishing_with_custom_encoding( payload: str, template: str | None, tpl_par: str = "value", - tpl_output: str | None = None, + tpl_output: PublishPayloadType = None, ) -> None: """Test a service with publishing MQTT payload with different encoding.""" # prepare config for tests @@ -1676,14 +1675,16 @@ async def help_test_publishing_with_custom_encoding( if parameters: service_data[test_id].update(parameters) - # setup test entities - assert await async_setup_component( - hass, - mqtt.DOMAIN, - {mqtt.DOMAIN: {domain: setup_config}}, - ) + # setup test entities using discovery + mqtt_mock = await mqtt_mock_entry_no_yaml_config() + item: int = 0 + for component_config in setup_config: + conf = json.dumps(component_config) + item += 1 + async_fire_mqtt_message( + hass, f"homeassistant/{domain}/component_{item}/config", conf + ) await hass.async_block_till_done() - mqtt_mock = await mqtt_mock_entry_with_yaml_config() # 1) test with default encoding await hass.services.async_call( @@ -1692,6 +1693,7 @@ async def help_test_publishing_with_custom_encoding( service_data["test1"], blocking=True, ) + await hass.async_block_till_done() mqtt_mock.async_publish.assert_any_call("cmd/test1", str(payload), 0, False) mqtt_mock.async_publish.reset_mock() @@ -1816,8 +1818,7 @@ async def help_test_reloadable( # We should call await mqtt.async_setup_entry(hass, entry) when async_setup # is removed (this is planned with #87987). Until then we set up the mqtt component # to test reload after the async_setup setup has set the initial config - await async_setup_component(hass, mqtt.DOMAIN, old_config) - await hass.async_block_till_done() + await help_setup_component(hass, None, domain, old_config, use_discovery=False) assert hass.states.get(f"{domain}.test_old_1") assert hass.states.get(f"{domain}.test_old_2") @@ -1852,23 +1853,6 @@ async def help_test_reloadable( assert hass.states.get(f"{domain}.test_new_3") -async def help_test_setup_manual_entity_from_yaml( - hass: HomeAssistant, config: ConfigType -) -> None: - """Help to test setup from yaml through configuration entry.""" - # until `async_setup` does the initial config setup, we need to use - # async_setup_component to test with other yaml config - assert await async_setup_component(hass, mqtt.DOMAIN, config) - # Mock config entry - entry = MockConfigEntry(domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "test-broker"}) - entry.add_to_hass(hass) - - with patch("paho.mqtt.client.Client") as mock_client: - mock_client().connect = lambda *args: 0 - assert await hass.config_entries.async_setup(entry.entry_id) - await hass.async_block_till_done() - - async def help_test_unload_config_entry(hass: HomeAssistant) -> None: """Test unloading the MQTT config entry.""" mqtt_config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0] @@ -1892,9 +1876,9 @@ async def help_test_unload_config_entry_with_platform( config_setup: dict[str, dict[str, Any]] = copy.deepcopy(config) config_setup[mqtt.DOMAIN][domain]["name"] = "config_setup" config_name = config_setup - # To be replaced with entry setup when `async_setup` is removed. - assert await async_setup_component(hass, mqtt.DOMAIN, config_setup) - await hass.async_block_till_done() + await help_setup_component( + hass, mqtt_mock_entry_no_yaml_config, domain, config_setup + ) # prepare setup through discovery discovery_setup = copy.deepcopy(config[mqtt.DOMAIN][domain]) diff --git a/tests/components/mqtt/test_cover.py b/tests/components/mqtt/test_cover.py index a20781cad12..a09edcd25e0 100644 --- a/tests/components/mqtt/test_cover.py +++ b/tests/components/mqtt/test_cover.py @@ -1,4 +1,5 @@ """The tests for the MQTT cover platform.""" +from typing import Any from unittest.mock import patch import pytest @@ -69,7 +70,6 @@ from .test_common import ( help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_unload_config_entry_with_platform, help_test_update_with_json_attrs_bad_json, @@ -2666,29 +2666,32 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + cover.DOMAIN: [ + { + "name": "Test 1", + "state_topic": "test-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Test 2", + "state_topic": "test-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique_id option only creates one cover per id.""" - config = { - mqtt.DOMAIN: { - cover.DOMAIN: [ - { - "name": "Test 1", - "state_topic": "test-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Test 2", - "state_topic": "test-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, cover.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN) async def test_discovery_removal_cover( @@ -2787,11 +2790,11 @@ async def test_entity_device_info_remove( async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_with_yaml_config, cover.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG ) @@ -3469,13 +3472,13 @@ async def test_tilt_status_template_without_tilt_status_topic_topic( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, - service, - topic, - parameters, - payload, - template, + service: str, + topic: str, + parameters: dict[str, Any], + payload: str, + template: str | None, ) -> None: """Test publishing MQTT payload with different encoding.""" domain = cover.DOMAIN @@ -3484,7 +3487,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, caplog, domain, config, @@ -3517,18 +3520,16 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, - caplog: pytest.LogCaptureFixture, - topic, - value, - attribute, - attribute_value, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + topic: str, + value: str, + attribute: str | None, + attribute_value: Any, ) -> None: """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_with_yaml_config, - caplog, + mqtt_mock_entry_no_yaml_config, cover.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][cover.DOMAIN], topic, @@ -3539,10 +3540,13 @@ async def test_encoding_subscribable_topics( ) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = cover.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_device_tracker.py b/tests/components/mqtt/test_device_tracker.py index bc3371f6e51..a8c45f8cd75 100644 --- a/tests/components/mqtt/test_device_tracker.py +++ b/tests/components/mqtt/test_device_tracker.py @@ -4,17 +4,13 @@ from unittest.mock import patch import pytest from homeassistant.components import device_tracker, mqtt -from homeassistant.components.device_tracker import legacy from homeassistant.components.mqtt.const import DOMAIN as MQTT_DOMAIN from homeassistant.const import STATE_HOME, STATE_NOT_HOME, STATE_UNKNOWN, Platform from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.setup import async_setup_component -from .test_common import ( - help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, -) +from .test_common import help_test_setting_blocked_attribute_via_mqtt_json_message from tests.common import async_fire_mqtt_message from tests.typing import MqttMockHAClientGenerator, WebSocketGenerator @@ -589,18 +585,21 @@ async def test_setting_blocked_attribute_via_mqtt_json_message( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + device_tracker.DOMAIN: {"name": "jan", "state_topic": "/location/jan"} + } + } + ], +) async def test_setup_with_modern_schema( - hass: HomeAssistant, mock_device_tracker_conf: list[legacy.Device] + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test setup using the modern schema.""" + await mqtt_mock_entry_no_yaml_config() dev_id = "jan" entity_id = f"{device_tracker.DOMAIN}.{dev_id}" - topic = "/location/jan" - - config = { - mqtt.DOMAIN: {device_tracker.DOMAIN: {"name": dev_id, "state_topic": topic}} - } - - await help_test_setup_manual_entity_from_yaml(hass, config) - assert hass.states.get(entity_id) is not None diff --git a/tests/components/mqtt/test_fan.py b/tests/components/mqtt/test_fan.py index 4d13eb5c8bb..41ff43aba87 100644 --- a/tests/components/mqtt/test_fan.py +++ b/tests/components/mqtt/test_fan.py @@ -1,5 +1,6 @@ """Test MQTT fans.""" import copy +from typing import Any from unittest.mock import patch import pytest @@ -56,7 +57,6 @@ from .test_common import ( help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_unload_config_entry_with_platform, help_test_update_with_json_attrs_bad_json, @@ -1371,12 +1371,11 @@ async def test_sending_mqtt_commands_and_explicit_optimistic( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, - caplog: pytest.LogCaptureFixture, - topic, - value, - attribute, - attribute_value, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + topic: str, + value: str, + attribute: str | None, + attribute_value: Any, ) -> None: """Test handling of incoming encoded payload.""" config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][fan.DOMAIN]) @@ -1386,8 +1385,7 @@ async def test_encoding_subscribable_topics( config[CONF_OSCILLATION_COMMAND_TOPIC] = "fan/some_oscillation_command_topic" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_with_yaml_config, - caplog, + mqtt_mock_entry_no_yaml_config, fan.DOMAIN, config, topic, @@ -1779,31 +1777,34 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + fan.DOMAIN: [ + { + "name": "Test 1", + "state_topic": "test-topic", + "command_topic": "test_topic", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Test 2", + "state_topic": "test-topic", + "command_topic": "test_topic", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique_id option only creates one fan per id.""" - config = { - mqtt.DOMAIN: { - fan.DOMAIN: [ - { - "name": "Test 1", - "state_topic": "test-topic", - "command_topic": "test_topic", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Test 2", - "state_topic": "test-topic", - "command_topic": "test_topic", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, fan.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN) async def test_discovery_removal_fan( @@ -1903,11 +1904,11 @@ async def test_entity_device_info_remove( async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_with_yaml_config, fan.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry_no_yaml_config, fan.DOMAIN, DEFAULT_CONFIG ) @@ -1975,13 +1976,13 @@ async def test_entity_debug_info_message( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, - service, - topic, - parameters, - payload, - template, + service: str, + topic: str, + parameters: dict[str, Any], + payload: str, + template: str | None, ) -> None: """Test publishing MQTT payload with different encoding.""" domain = fan.DOMAIN @@ -1991,7 +1992,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, caplog, domain, config, @@ -2013,10 +2014,13 @@ async def test_reloadable( await help_test_reloadable(hass, mqtt_client_mock, domain, config) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = fan.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_humidifier.py b/tests/components/mqtt/test_humidifier.py index bba468a4ab3..89afe0a3972 100644 --- a/tests/components/mqtt/test_humidifier.py +++ b/tests/components/mqtt/test_humidifier.py @@ -1,5 +1,6 @@ """Test MQTT humidifiers.""" import copy +from typing import Any from unittest.mock import patch import pytest @@ -58,7 +59,6 @@ from .test_common import ( help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_unload_config_entry_with_platform, help_test_update_with_json_attrs_bad_json, @@ -752,12 +752,11 @@ async def test_sending_mqtt_commands_and_explicit_optimistic( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, - caplog: pytest.LogCaptureFixture, - topic, - value, - attribute, - attribute_value, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + topic: str, + value: str, + attribute: str | None, + attribute_value: Any, ) -> None: """Test handling of incoming encoded payload.""" config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][humidifier.DOMAIN]) @@ -765,8 +764,7 @@ async def test_encoding_subscribable_topics( config[CONF_MODE_COMMAND_TOPIC] = "humidifier/some_mode_command_topic" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_with_yaml_config, - caplog, + mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, config, topic, @@ -1136,33 +1134,36 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + humidifier.DOMAIN: [ + { + "name": "Test 1", + "state_topic": "test-topic", + "command_topic": "test_topic", + "target_humidity_command_topic": "humidity-command-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Test 2", + "state_topic": "test-topic", + "command_topic": "test_topic", + "target_humidity_command_topic": "humidity-command-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique_id option only creates one fan per id.""" - config = { - mqtt.DOMAIN: { - humidifier.DOMAIN: [ - { - "name": "Test 1", - "state_topic": "test-topic", - "command_topic": "test_topic", - "target_humidity_command_topic": "humidity-command-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Test 2", - "state_topic": "test-topic", - "command_topic": "test_topic", - "target_humidity_command_topic": "humidity-command-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, humidifier.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN) async def test_discovery_removal_humidifier( @@ -1274,11 +1275,11 @@ async def test_entity_device_info_remove( async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_with_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG ) @@ -1339,13 +1340,13 @@ async def test_entity_debug_info_message( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, - service, - topic, - parameters, - payload, - template, + service: str, + topic: str, + parameters: dict[str, Any], + payload: str, + template: str | None, ) -> None: """Test publishing MQTT payload with different encoding.""" domain = humidifier.DOMAIN @@ -1355,7 +1356,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, caplog, domain, config, @@ -1377,10 +1378,13 @@ async def test_reloadable( await help_test_reloadable(hass, mqtt_client_mock, domain, config) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = humidifier.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_init.py b/tests/components/mqtt/test_init.py index 22090064280..9fbca57e3a9 100644 --- a/tests/components/mqtt/test_init.py +++ b/tests/components/mqtt/test_init.py @@ -42,7 +42,7 @@ from homeassistant.util.dt import utcnow from .test_common import ( help_test_entry_reload_with_new_config, - help_test_setup_manual_entity_from_yaml, + help_test_validate_platform_config, ) from tests.common import ( @@ -1867,8 +1867,7 @@ async def test_setup_manual_mqtt_with_platform_key( } } } - with pytest.raises(AssertionError): - await help_test_setup_manual_entity_from_yaml(hass, config) + help_test_validate_platform_config(hass, config) assert ( "Invalid config for [mqtt]: [platform] is an invalid option for [mqtt]" in caplog.text @@ -1881,8 +1880,7 @@ async def test_setup_manual_mqtt_with_invalid_config( ) -> None: """Test set up a manual MQTT item with an invalid config.""" config = {mqtt.DOMAIN: {"light": {"name": "test"}}} - with pytest.raises(AssertionError): - await help_test_setup_manual_entity_from_yaml(hass, config) + help_test_validate_platform_config(hass, config) assert ( "Invalid config for [mqtt]: required key not provided @ data['mqtt']['light'][0]['command_topic']." " Got None. (See ?, line ?)" in caplog.text @@ -1895,7 +1893,7 @@ async def test_setup_manual_mqtt_empty_platform( ) -> None: """Test set up a manual MQTT platform without items.""" config: ConfigType = {mqtt.DOMAIN: {"light": []}} - await help_test_setup_manual_entity_from_yaml(hass, config) + help_test_validate_platform_config(hass, config) assert "voluptuous.error.MultipleInvalid" not in caplog.text @@ -3407,12 +3405,12 @@ async def test_disabling_and_enabling_entry( ) async def test_setup_manual_items_with_unique_ids( hass: HomeAssistant, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, - hass_config: ConfigType, unique: bool, ) -> None: """Test setup manual items is generating unique id's.""" - await help_test_setup_manual_entity_from_yaml(hass, hass_config) + await mqtt_mock_entry_no_yaml_config() assert hass.states.get("light.test1") is not None assert (hass.states.get("light.test2") is not None) == unique @@ -3480,19 +3478,20 @@ async def test_remove_unknown_conf_entry_options( ], ) async def test_link_config_entry( - hass: HomeAssistant, hass_config: ConfigType, caplog: pytest.LogCaptureFixture + hass: HomeAssistant, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + caplog: pytest.LogCaptureFixture, ) -> None: """Test manual and dynamically setup entities are linked to the config entry.""" + # set up manual item + await mqtt_mock_entry_no_yaml_config() + + # set up item through discovery config_discovery = { "name": "test_discovery", "unique_id": "test_discovery_unique456", "command_topic": "test-topic_discovery", } - - # set up manual item - await help_test_setup_manual_entity_from_yaml(hass, hass_config) - - # set up item through discovery async_fire_mqtt_message( hass, "homeassistant/light/bla/config", json.dumps(config_discovery) ) @@ -3541,18 +3540,3 @@ async def test_link_config_entry( ) await hass.async_block_till_done() assert _check_entities() == 2 - - -@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR]) -@pytest.mark.parametrize( - "config_manual", - [ - {"mqtt": {"sensor": []}}, - {"mqtt": {"broker": "test"}}, - ], -) -async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, config_manual: ConfigType -) -> None: - """Test setup with empty platform keys.""" - await help_test_setup_manual_entity_from_yaml(hass, config_manual) diff --git a/tests/components/mqtt/test_legacy_vacuum.py b/tests/components/mqtt/test_legacy_vacuum.py index 7bd03bd3929..42077fee0a7 100644 --- a/tests/components/mqtt/test_legacy_vacuum.py +++ b/tests/components/mqtt/test_legacy_vacuum.py @@ -1,6 +1,7 @@ """The tests for the Legacy Mqtt vacuum platform.""" from copy import deepcopy import json +from typing import Any from unittest.mock import patch import pytest @@ -56,7 +57,6 @@ from .test_common import ( help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_update_with_json_attrs_bad_json, help_test_update_with_json_attrs_not_dict, @@ -745,29 +745,32 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + vacuum.DOMAIN: [ + { + "name": "Test 1", + "command_topic": "test_topic", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Test 2", + "command_topic": "test_topic", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one vacuum per unique_id.""" - config = { - mqtt.DOMAIN: { - vacuum.DOMAIN: [ - { - "name": "Test 1", - "command_topic": "test_topic", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Test 2", - "command_topic": "test_topic", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN) async def test_discovery_removal_vacuum( @@ -866,7 +869,7 @@ async def test_entity_device_info_remove( async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" config = { @@ -882,7 +885,7 @@ async def test_entity_id_update_subscriptions( } await help_test_entity_id_update_subscriptions( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, config, ["test-topic", "avty-topic"], @@ -964,13 +967,13 @@ async def test_entity_debug_info_message( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, - service, - topic, - parameters, - payload, - template, + service: str, + topic: str, + parameters: dict[str, Any], + payload: str, + template: str | None, ) -> None: """Test publishing MQTT payload with different encoding.""" domain = vacuum.DOMAIN @@ -985,7 +988,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, caplog, domain, config, @@ -1030,12 +1033,11 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, - caplog: pytest.LogCaptureFixture, - topic, - value, - attribute, - attribute_value, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + topic: str, + value: str, + attribute: str | None, + attribute_value: Any, ) -> None: """Test handling of incoming encoded payload.""" domain = vacuum.DOMAIN @@ -1056,8 +1058,7 @@ async def test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_with_yaml_config, - caplog, + mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, config, topic, @@ -1068,8 +1069,11 @@ async def test_encoding_subscribable_topics( ) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = vacuum.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.mqtttest") diff --git a/tests/components/mqtt/test_light.py b/tests/components/mqtt/test_light.py index ed57482f7fd..7d0c0333b7e 100644 --- a/tests/components/mqtt/test_light.py +++ b/tests/components/mqtt/test_light.py @@ -169,6 +169,7 @@ mqtt: """ import copy +from typing import Any from unittest.mock import call, patch import pytest @@ -186,6 +187,7 @@ from homeassistant.components.mqtt.light.schema_basic import ( CONF_XY_COMMAND_TOPIC, MQTT_LIGHT_ATTRIBUTES_BLOCKED, ) +from homeassistant.components.mqtt.models import PublishPayloadType from homeassistant.const import ( ATTR_ASSUMED_STATE, STATE_OFF, @@ -219,7 +221,6 @@ from .test_common import ( help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_unload_config_entry_with_platform, help_test_update_with_json_attrs_bad_json, @@ -2247,31 +2248,34 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + light.DOMAIN: [ + { + "name": "Test 1", + "state_topic": "test-topic", + "command_topic": "test_topic", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Test 2", + "state_topic": "test-topic", + "command_topic": "test_topic", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one light per unique_id.""" - config = { - mqtt.DOMAIN: { - light.DOMAIN: [ - { - "name": "Test 1", - "state_topic": "test-topic", - "command_topic": "test_topic", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Test 2", - "state_topic": "test-topic", - "command_topic": "test_topic", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN) async def test_discovery_removal_light( @@ -2859,11 +2863,11 @@ async def test_entity_device_info_remove( async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG ) @@ -2999,15 +3003,15 @@ async def test_max_mireds( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, - service, - topic, - parameters, - payload, - template, - tpl_par, - tpl_output, + service: str, + topic: str, + parameters: dict[str, Any], + payload: str, + template: str | None, + tpl_par: str, + tpl_output: PublishPayloadType, ) -> None: """Test publishing MQTT payload with different encoding.""" domain = light.DOMAIN @@ -3019,7 +3023,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, caplog, domain, config, @@ -3075,13 +3079,12 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, - caplog: pytest.LogCaptureFixture, - topic, - value, - attribute, - attribute_value, - init_payload, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + topic: str, + value: str, + attribute: str | None, + attribute_value: Any, + init_payload: tuple[str, str] | None, ) -> None: """Test handling of incoming encoded payload.""" config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][light.DOMAIN]) @@ -3098,8 +3101,7 @@ async def test_encoding_subscribable_topics( await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_with_yaml_config, - caplog, + mqtt_mock_entry_no_yaml_config, light.DOMAIN, config, topic, @@ -3118,13 +3120,13 @@ async def test_encoding_subscribable_topics( ) async def test_encoding_subscribable_topics_brightness( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, - topic, - value, - attribute, - attribute_value, - init_payload, + topic: str, + value: str, + attribute: str, + attribute_value: int, + init_payload: tuple[str, str] | None, ) -> None: """Test handling of incoming encoded payload for a brightness only light.""" config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][light.DOMAIN]) @@ -3132,8 +3134,7 @@ async def test_encoding_subscribable_topics_brightness( await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_with_yaml_config, - caplog, + mqtt_mock_entry_no_yaml_config, light.DOMAIN, config, topic, @@ -3298,10 +3299,13 @@ async def test_sending_mqtt_xy_command_with_template( assert state.attributes["xy_color"] == (0.151, 0.343) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = light.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_light_json.py b/tests/components/mqtt/test_light_json.py index 9bf0ef7a7f3..db39cea7844 100644 --- a/tests/components/mqtt/test_light_json.py +++ b/tests/components/mqtt/test_light_json.py @@ -79,6 +79,7 @@ light: brightness_scale: 99 """ import copy +from typing import Any from unittest.mock import call, patch import pytest @@ -87,6 +88,7 @@ from homeassistant.components import light, mqtt from homeassistant.components.mqtt.light.schema_basic import ( MQTT_LIGHT_ATTRIBUTES_BLOCKED, ) +from homeassistant.components.mqtt.models import PublishPayloadType from homeassistant.const import ( ATTR_ASSUMED_STATE, ATTR_SUPPORTED_FEATURES, @@ -122,7 +124,6 @@ from .test_common import ( help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_update_with_json_attrs_bad_json, help_test_update_with_json_attrs_not_dict, @@ -1996,33 +1997,36 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + light.DOMAIN: [ + { + "name": "Test 1", + "schema": "json", + "state_topic": "test-topic", + "command_topic": "test_topic", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Test 2", + "schema": "json", + "state_topic": "test-topic", + "command_topic": "test_topic", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one light per unique_id.""" - config = { - mqtt.DOMAIN: { - light.DOMAIN: [ - { - "name": "Test 1", - "schema": "json", - "state_topic": "test-topic", - "command_topic": "test_topic", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Test 2", - "schema": "json", - "state_topic": "test-topic", - "command_topic": "test_topic", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN) async def test_discovery_removal( @@ -2167,11 +2171,11 @@ async def test_entity_device_info_remove( async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG ) @@ -2247,15 +2251,15 @@ async def test_max_mireds( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, - service, - topic, - parameters, - payload, - template, - tpl_par, - tpl_output, + service: str, + topic: str, + parameters: dict[str, Any], + payload: str, + template: str | None, + tpl_par: str, + tpl_output: PublishPayloadType, ) -> None: """Test publishing MQTT payload with different encoding.""" domain = light.DOMAIN @@ -2265,7 +2269,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, caplog, domain, config, @@ -2303,13 +2307,12 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, - caplog: pytest.LogCaptureFixture, - topic, - value, - attribute, - attribute_value, - init_payload, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + topic: str, + value: str, + attribute: str | None, + attribute_value: Any, + init_payload: tuple[str, str] | None, ) -> None: """Test handling of incoming encoded payload.""" config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][light.DOMAIN]) @@ -2324,8 +2327,7 @@ async def test_encoding_subscribable_topics( ] await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_with_yaml_config, - caplog, + mqtt_mock_entry_no_yaml_config, light.DOMAIN, config, topic, @@ -2337,8 +2339,11 @@ async def test_encoding_subscribable_topics( ) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = light.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_light_template.py b/tests/components/mqtt/test_light_template.py index e2e1b127c1c..c8018d4847f 100644 --- a/tests/components/mqtt/test_light_template.py +++ b/tests/components/mqtt/test_light_template.py @@ -25,6 +25,7 @@ If your light doesn't support color temp feature, omit `color_temp_template`. If your light doesn't support RGB feature, omit `(red|green|blue)_template`. """ import copy +from typing import Any from unittest.mock import patch import pytest @@ -33,6 +34,7 @@ from homeassistant.components import light, mqtt from homeassistant.components.mqtt.light.schema_basic import ( MQTT_LIGHT_ATTRIBUTES_BLOCKED, ) +from homeassistant.components.mqtt.models import PublishPayloadType from homeassistant.const import ( ATTR_ASSUMED_STATE, ATTR_SUPPORTED_FEATURES, @@ -67,7 +69,6 @@ from .test_common import ( help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_unload_config_entry_with_platform, help_test_update_with_json_attrs_bad_json, @@ -964,37 +965,40 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + light.DOMAIN: [ + { + "name": "Test 1", + "schema": "template", + "state_topic": "test-topic", + "command_topic": "test_topic", + "command_on_template": "on,{{ transition }}", + "command_off_template": "off,{{ transition|d }}", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Test 2", + "schema": "template", + "state_topic": "test-topic2", + "command_topic": "test_topic2", + "command_on_template": "on,{{ transition }}", + "command_off_template": "off,{{ transition|d }}", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one light per unique_id.""" - config = { - mqtt.DOMAIN: { - light.DOMAIN: [ - { - "name": "Test 1", - "schema": "template", - "state_topic": "test-topic", - "command_topic": "test_topic", - "command_on_template": "on,{{ transition }}", - "command_off_template": "off,{{ transition|d }}", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Test 2", - "schema": "template", - "state_topic": "test-topic2", - "command_topic": "test_topic2", - "command_on_template": "on,{{ transition }}", - "command_off_template": "off,{{ transition|d }}", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN) async def test_discovery_removal( @@ -1127,11 +1131,11 @@ async def test_entity_device_info_remove( async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG ) @@ -1219,15 +1223,15 @@ async def test_max_mireds( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, - service, - topic, - parameters, - payload, - template, - tpl_par, - tpl_output, + service: str, + topic: str, + parameters: dict[str, Any], + payload: str, + template: str | None, + tpl_par: str, + tpl_output: PublishPayloadType, ) -> None: """Test publishing MQTT payload with different encoding.""" domain = light.DOMAIN @@ -1237,7 +1241,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, caplog, domain, config, @@ -1269,12 +1273,11 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, - caplog: pytest.LogCaptureFixture, - topic, - value, - attribute, - attribute_value, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + topic: str, + value: str, + attribute: str | None, + attribute_value: Any, init_payload, ) -> None: """Test handling of incoming encoded payload.""" @@ -1282,8 +1285,7 @@ async def test_encoding_subscribable_topics( config["state_template"] = "{{ value }}" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_with_yaml_config, - caplog, + mqtt_mock_entry_no_yaml_config, light.DOMAIN, config, topic, @@ -1294,10 +1296,13 @@ async def test_encoding_subscribable_topics( ) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = light.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_lock.py b/tests/components/mqtt/test_lock.py index a99ad745570..0c8b6680c55 100644 --- a/tests/components/mqtt/test_lock.py +++ b/tests/components/mqtt/test_lock.py @@ -1,5 +1,5 @@ """The tests for the MQTT lock platform.""" -from pathlib import Path +from typing import Any from unittest.mock import patch import pytest @@ -50,7 +50,6 @@ from .test_common import ( help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_unload_config_entry_with_platform, help_test_update_with_json_attrs_bad_json, @@ -762,31 +761,34 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + lock.DOMAIN: [ + { + "name": "Test 1", + "state_topic": "test-topic", + "command_topic": "test_topic", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Test 2", + "state_topic": "test-topic", + "command_topic": "test_topic", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one lock per unique_id.""" - config = { - mqtt.DOMAIN: { - lock.DOMAIN: [ - { - "name": "Test 1", - "state_topic": "test-topic", - "command_topic": "test_topic", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Test 2", - "state_topic": "test-topic", - "command_topic": "test_topic", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN) async def test_discovery_removal_lock( @@ -899,11 +901,11 @@ async def test_entity_device_info_remove( async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_with_yaml_config, lock.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG ) @@ -944,13 +946,13 @@ async def test_entity_debug_info_message( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, - service, - topic, - parameters, - payload, - template, + service: str, + topic: str, + parameters: dict[str, Any], + payload: str, + template: str | None, ) -> None: """Test publishing MQTT payload with different encoding.""" domain = lock.DOMAIN @@ -958,7 +960,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, caplog, domain, config, @@ -988,18 +990,16 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, - caplog: pytest.LogCaptureFixture, - topic, - value, - attribute, - attribute_value, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + topic: str, + value: str, + attribute: str | None, + attribute_value: Any, ) -> None: """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_with_yaml_config, - caplog, + mqtt_mock_entry_no_yaml_config, lock.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][lock.DOMAIN], topic, @@ -1009,12 +1009,13 @@ async def test_encoding_subscribable_topics( ) +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) async def test_setup_manual_entity_from_yaml( - hass: HomeAssistant, caplog: pytest.LogCaptureFixture, tmp_path: Path + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = lock.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_number.py b/tests/components/mqtt/test_number.py index b005b75a8ac..eb2a6402284 100644 --- a/tests/components/mqtt/test_number.py +++ b/tests/components/mqtt/test_number.py @@ -1,5 +1,6 @@ """The tests for mqtt number component.""" import json +from typing import Any from unittest.mock import patch import pytest @@ -54,7 +55,6 @@ from .test_common import ( help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_unload_config_entry_with_platform, help_test_update_with_json_attrs_bad_json, @@ -559,31 +559,34 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + number.DOMAIN: [ + { + "name": "Test 1", + "state_topic": "test-topic", + "command_topic": "test-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Test 2", + "state_topic": "test-topic", + "command_topic": "test-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one number per unique_id.""" - config = { - mqtt.DOMAIN: { - number.DOMAIN: [ - { - "name": "Test 1", - "state_topic": "test-topic", - "command_topic": "test-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Test 2", - "state_topic": "test-topic", - "command_topic": "test-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, number.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN) async def test_discovery_removal_number( @@ -696,11 +699,11 @@ async def test_entity_device_info_remove( async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_with_yaml_config, number.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG ) @@ -938,13 +941,13 @@ async def test_mqtt_payload_out_of_range_error( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, - service, - topic, - parameters, - payload, - template, + service: str, + topic: str, + parameters: dict[str, Any], + payload: str, + template: str | None, ) -> None: """Test publishing MQTT payload with different encoding.""" domain = NUMBER_DOMAIN @@ -952,7 +955,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, caplog, domain, config, @@ -983,18 +986,16 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, - caplog: pytest.LogCaptureFixture, - topic, - value, - attribute, - attribute_value, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + topic: str, + value: str, + attribute: str | None, + attribute_value: Any, ) -> None: """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_with_yaml_config, - caplog, + mqtt_mock_entry_no_yaml_config, number.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][number.DOMAIN], topic, @@ -1004,10 +1005,13 @@ async def test_encoding_subscribable_topics( ) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = number.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_scene.py b/tests/components/mqtt/test_scene.py index 3662cd6a1ca..3da5fd4f36a 100644 --- a/tests/components/mqtt/test_scene.py +++ b/tests/components/mqtt/test_scene.py @@ -19,7 +19,6 @@ from .test_common import ( help_test_discovery_update, help_test_discovery_update_unchanged, help_test_reloadable, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_unload_config_entry_with_platform, ) @@ -148,29 +147,32 @@ async def test_custom_availability_payload( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + scene.DOMAIN: [ + { + "name": "Test 1", + "command_topic": "command-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Test 2", + "command_topic": "command-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one scene per unique_id.""" - config = { - mqtt.DOMAIN: { - scene.DOMAIN: [ - { - "name": "Test 1", - "command_topic": "command-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Test 2", - "command_topic": "command-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, scene.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, scene.DOMAIN) async def test_discovery_removal_scene( @@ -252,10 +254,13 @@ async def test_reloadable( await help_test_reloadable(hass, mqtt_client_mock, domain, config) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = scene.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_select.py b/tests/components/mqtt/test_select.py index 6e885f0bff7..3a639ecf08f 100644 --- a/tests/components/mqtt/test_select.py +++ b/tests/components/mqtt/test_select.py @@ -1,6 +1,7 @@ """The tests for mqtt select component.""" import copy import json +from typing import Any from unittest.mock import patch import pytest @@ -46,7 +47,6 @@ from .test_common import ( help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_unload_config_entry_with_platform, help_test_update_with_json_attrs_bad_json, @@ -436,33 +436,36 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + select.DOMAIN: [ + { + "name": "Test 1", + "state_topic": "test-topic", + "command_topic": "test-topic", + "unique_id": "TOTALLY_UNIQUE", + "options": ["milk", "beer"], + }, + { + "name": "Test 2", + "state_topic": "test-topic", + "command_topic": "test-topic", + "unique_id": "TOTALLY_UNIQUE", + "options": ["milk", "beer"], + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one select per unique_id.""" - config = { - mqtt.DOMAIN: { - select.DOMAIN: [ - { - "name": "Test 1", - "state_topic": "test-topic", - "command_topic": "test-topic", - "unique_id": "TOTALLY_UNIQUE", - "options": ["milk", "beer"], - }, - { - "name": "Test 2", - "state_topic": "test-topic", - "command_topic": "test-topic", - "unique_id": "TOTALLY_UNIQUE", - "options": ["milk", "beer"], - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, select.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN) async def test_discovery_removal_select( @@ -573,11 +576,11 @@ async def test_entity_device_info_remove( async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_with_yaml_config, select.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry_no_yaml_config, select.DOMAIN, DEFAULT_CONFIG ) @@ -683,13 +686,13 @@ async def test_mqtt_payload_not_an_option_warning( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, - service, - topic, - parameters, - payload, - template, + service: str, + topic: str, + parameters: dict[str, Any], + payload: str, + template: str | None, ) -> None: """Test publishing MQTT payload with different encoding.""" domain = select.DOMAIN @@ -698,7 +701,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, caplog, domain, config, @@ -729,20 +732,18 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, - caplog: pytest.LogCaptureFixture, - topic, - value, - attribute, - attribute_value, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + topic: str, + value: str, + attribute: str | None, + attribute_value: Any, ) -> None: """Test handling of incoming encoded payload.""" config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][select.DOMAIN]) config["options"] = ["milk", "beer"] await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_with_yaml_config, - caplog, + mqtt_mock_entry_no_yaml_config, select.DOMAIN, config, topic, @@ -752,10 +753,13 @@ async def test_encoding_subscribable_topics( ) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = select.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_sensor.py b/tests/components/mqtt/test_sensor.py index eb1e8fbdeb6..6889069c8ca 100644 --- a/tests/components/mqtt/test_sensor.py +++ b/tests/components/mqtt/test_sensor.py @@ -3,6 +3,7 @@ import copy from datetime import datetime, timedelta import json from pathlib import Path +from typing import Any from unittest.mock import MagicMock, patch from freezegun.api import FrozenDateTimeFactory @@ -56,7 +57,6 @@ from .test_common import ( help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_unload_config_entry_with_platform, help_test_update_with_json_attrs_bad_json, @@ -943,29 +943,32 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + sensor.DOMAIN: [ + { + "name": "Test 1", + "state_topic": "test-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Test 2", + "state_topic": "test-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one sensor per unique_id.""" - config = { - mqtt.DOMAIN: { - sensor.DOMAIN: [ - { - "name": "Test 1", - "state_topic": "test-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Test 2", - "state_topic": "test-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN) async def test_discovery_removal_sensor( @@ -1123,11 +1126,11 @@ async def test_entity_device_info_remove( async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_with_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG ) @@ -1378,18 +1381,16 @@ async def test_skip_restoring_state_with_over_due_expire_trigger( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, - caplog: pytest.LogCaptureFixture, - topic, - value, - attribute, - attribute_value, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + topic: str, + value: str, + attribute: str | None, + attribute_value: Any, ) -> None: """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_with_yaml_config, - caplog, + mqtt_mock_entry_no_yaml_config, sensor.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][sensor.DOMAIN], topic, @@ -1400,10 +1401,13 @@ async def test_encoding_subscribable_topics( ) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = sensor.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_siren.py b/tests/components/mqtt/test_siren.py index b288acdd15b..9837a3cc8a6 100644 --- a/tests/components/mqtt/test_siren.py +++ b/tests/components/mqtt/test_siren.py @@ -44,7 +44,6 @@ from .test_common import ( help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_unload_config_entry_with_platform, help_test_update_with_json_attrs_bad_json, @@ -641,31 +640,34 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + siren.DOMAIN: [ + { + "name": "Test 1", + "state_topic": "test-topic", + "command_topic": "command-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Test 2", + "state_topic": "test-topic", + "command_topic": "command-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one siren per unique_id.""" - config = { - mqtt.DOMAIN: { - siren.DOMAIN: [ - { - "name": "Test 1", - "state_topic": "test-topic", - "command_topic": "command-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Test 2", - "state_topic": "test-topic", - "command_topic": "command-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, siren.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN) async def test_discovery_removal_siren( @@ -924,11 +926,11 @@ async def test_entity_device_info_remove( async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_with_yaml_config, siren.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG ) @@ -976,13 +978,13 @@ async def test_entity_debug_info_message( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, - service, - topic, - parameters, - payload, - template, + service: str, + topic: str, + parameters: dict[str, Any], + payload: str, + template: str | None, ) -> None: """Test publishing MQTT payload with command templates and different encoding.""" domain = siren.DOMAIN @@ -991,7 +993,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, caplog, domain, config, @@ -1021,18 +1023,16 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, - caplog: pytest.LogCaptureFixture, - topic, - value, - attribute, - attribute_value, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + topic: str, + value: str, + attribute: str | None, + attribute_value: Any, ) -> None: """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_with_yaml_config, - caplog, + mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN], topic, @@ -1042,10 +1042,13 @@ async def test_encoding_subscribable_topics( ) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = siren.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_state_vacuum.py b/tests/components/mqtt/test_state_vacuum.py index 5164a747c82..a5c83813100 100644 --- a/tests/components/mqtt/test_state_vacuum.py +++ b/tests/components/mqtt/test_state_vacuum.py @@ -1,6 +1,7 @@ """The tests for the State vacuum Mqtt platform.""" from copy import deepcopy import json +from typing import Any from unittest.mock import patch import pytest @@ -53,7 +54,6 @@ from .test_common import ( help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_update_with_json_attrs_bad_json, help_test_update_with_json_attrs_not_dict, @@ -482,31 +482,34 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + vacuum.DOMAIN: [ + { + "schema": "state", + "name": "Test 1", + "command_topic": "command-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "schema": "state", + "name": "Test 2", + "command_topic": "command-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one vacuum per unique_id.""" - config = { - mqtt.DOMAIN: { - vacuum.DOMAIN: [ - { - "schema": "state", - "name": "Test 1", - "command_topic": "command-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "schema": "state", - "name": "Test 2", - "command_topic": "command-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN) async def test_discovery_removal_vacuum( @@ -605,11 +608,11 @@ async def test_entity_device_info_remove( async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_with_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 + hass, mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG_2 ) @@ -679,13 +682,13 @@ async def test_entity_debug_info_message( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, - service, - topic, - parameters, - payload, - template, + service: str, + topic: str, + parameters: dict[str, Any], + payload: str, + template: str | None, ) -> None: """Test publishing MQTT payload with different encoding.""" domain = vacuum.DOMAIN @@ -705,7 +708,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, caplog, domain, config, @@ -746,18 +749,16 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, - caplog: pytest.LogCaptureFixture, - topic, - value, - attribute, - attribute_value, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + topic: str, + value: str, + attribute: str | None, + attribute_value: Any, ) -> None: """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_with_yaml_config, - caplog, + mqtt_mock_entry_no_yaml_config, vacuum.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][vacuum.DOMAIN], topic, @@ -768,8 +769,11 @@ async def test_encoding_subscribable_topics( ) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = vacuum.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.mqtttest") diff --git a/tests/components/mqtt/test_switch.py b/tests/components/mqtt/test_switch.py index 4d604247222..83580edf003 100644 --- a/tests/components/mqtt/test_switch.py +++ b/tests/components/mqtt/test_switch.py @@ -1,5 +1,6 @@ """The tests for the MQTT switch platform.""" import copy +from typing import Any from unittest.mock import patch import pytest @@ -39,7 +40,6 @@ from .test_common import ( help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_unload_config_entry_with_platform, help_test_update_with_json_attrs_bad_json, @@ -403,31 +403,34 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + switch.DOMAIN: [ + { + "name": "Test 1", + "state_topic": "test-topic", + "command_topic": "command-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Test 2", + "state_topic": "test-topic", + "command_topic": "command-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one switch per unique_id.""" - config = { - mqtt.DOMAIN: { - switch.DOMAIN: [ - { - "name": "Test 1", - "state_topic": "test-topic", - "command_topic": "command-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Test 2", - "state_topic": "test-topic", - "command_topic": "command-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, switch.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN) async def test_discovery_removal_switch( @@ -602,11 +605,11 @@ async def test_entity_device_info_remove( async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_with_yaml_config, switch.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG ) @@ -653,13 +656,13 @@ async def test_entity_debug_info_message( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, - service, - topic, - parameters, - payload, - template, + service: str, + topic: str, + parameters: dict[str, Any], + payload: str, + template: str | None, ) -> None: """Test publishing MQTT payload with different encoding.""" domain = switch.DOMAIN @@ -667,7 +670,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, caplog, domain, config, @@ -697,18 +700,16 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, - caplog: pytest.LogCaptureFixture, - topic, - value, - attribute, - attribute_value, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + topic: str, + value: str, + attribute: str | None, + attribute_value: Any, ) -> None: """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_with_yaml_config, - caplog, + mqtt_mock_entry_no_yaml_config, switch.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][switch.DOMAIN], topic, @@ -718,10 +719,13 @@ async def test_encoding_subscribable_topics( ) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = switch.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_text.py b/tests/components/mqtt/test_text.py index 1477240740e..d12a03a9fa1 100644 --- a/tests/components/mqtt/test_text.py +++ b/tests/components/mqtt/test_text.py @@ -1,6 +1,7 @@ """The tests for the MQTT text platform.""" from __future__ import annotations +from typing import Any from unittest.mock import patch import pytest @@ -38,7 +39,6 @@ from .test_common import ( help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, help_test_setting_blocked_attribute_via_mqtt_json_message, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_unload_config_entry_with_platform, help_test_update_with_json_attrs_bad_json, @@ -454,31 +454,34 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + text.DOMAIN: [ + { + "name": "Test 1", + "state_topic": "test-topic", + "command_topic": "command-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Test 2", + "state_topic": "test-topic", + "command_topic": "command-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one text per unique_id.""" - config = { - mqtt.DOMAIN: { - text.DOMAIN: [ - { - "name": "Test 1", - "state_topic": "test-topic", - "command_topic": "command-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Test 2", - "state_topic": "test-topic", - "command_topic": "command-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, text.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN) async def test_discovery_removal_text( @@ -627,11 +630,11 @@ async def test_entity_device_info_remove( async def test_entity_id_update_subscriptions( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test MQTT subscriptions are managed when entity_id is updated.""" await help_test_entity_id_update_subscriptions( - hass, mqtt_mock_entry_with_yaml_config, text.DOMAIN, DEFAULT_CONFIG + hass, mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG ) @@ -667,13 +670,13 @@ async def test_entity_debug_info_message( ) async def test_publishing_with_custom_encoding( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, caplog: pytest.LogCaptureFixture, - service, - topic, - parameters, - payload, - template, + service: str, + topic: str, + parameters: dict[str, Any], + payload: str, + template: str | None, ) -> None: """Test publishing MQTT payload with different encoding.""" domain = text.DOMAIN @@ -681,7 +684,7 @@ async def test_publishing_with_custom_encoding( await help_test_publishing_with_custom_encoding( hass, - mqtt_mock_entry_with_yaml_config, + mqtt_mock_entry_no_yaml_config, caplog, domain, config, @@ -711,18 +714,16 @@ async def test_reloadable( ) async def test_encoding_subscribable_topics( hass: HomeAssistant, - mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator, - caplog: pytest.LogCaptureFixture, - topic, - value, - attribute, - attribute_value, + mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator, + topic: str, + value: str, + attribute: str | None, + attribute_value: Any, ) -> None: """Test handling of incoming encoded payload.""" await help_test_encoding_subscribable_topics( hass, - mqtt_mock_entry_with_yaml_config, - caplog, + mqtt_mock_entry_no_yaml_config, text.DOMAIN, DEFAULT_CONFIG[mqtt.DOMAIN][text.DOMAIN], topic, @@ -732,10 +733,13 @@ async def test_encoding_subscribable_topics( ) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = text.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test") diff --git a/tests/components/mqtt/test_update.py b/tests/components/mqtt/test_update.py index e300550e138..200a3ca6dd8 100644 --- a/tests/components/mqtt/test_update.py +++ b/tests/components/mqtt/test_update.py @@ -34,7 +34,6 @@ from .test_common import ( help_test_reloadable, help_test_setting_attribute_via_mqtt_json_message, help_test_setting_attribute_with_template, - help_test_setup_manual_entity_from_yaml, help_test_unique_id, help_test_unload_config_entry_with_platform, help_test_update_with_json_attrs_bad_json, @@ -529,31 +528,34 @@ async def test_discovery_update_attr( ) +@pytest.mark.parametrize( + "hass_config", + [ + { + mqtt.DOMAIN: { + update.DOMAIN: [ + { + "name": "Bear", + "state_topic": "installed-topic", + "latest_version_topic": "latest-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + { + "name": "Milk", + "state_topic": "installed-topic", + "latest_version_topic": "latest-topic", + "unique_id": "TOTALLY_UNIQUE", + }, + ] + } + } + ], +) async def test_unique_id( - hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator ) -> None: """Test unique id option only creates one update per unique_id.""" - config = { - mqtt.DOMAIN: { - update.DOMAIN: [ - { - "name": "Bear", - "state_topic": "installed-topic", - "latest_version_topic": "latest-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - { - "name": "Milk", - "state_topic": "installed-topic", - "latest_version_topic": "latest-topic", - "unique_id": "TOTALLY_UNIQUE", - }, - ] - } - } - await help_test_unique_id( - hass, mqtt_mock_entry_with_yaml_config, update.DOMAIN, config - ) + await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, update.DOMAIN) async def test_discovery_removal_update( @@ -670,10 +672,13 @@ async def test_entity_id_update_discovery_update( ) -async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG]) +async def test_setup_manual_entity_from_yaml( + hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator +) -> None: """Test setup manual configured MQTT entity.""" + await mqtt_mock_entry_no_yaml_config() platform = update.DOMAIN - await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG) assert hass.states.get(f"{platform}.test")