Cleanup mqtt PLATFORMS constant and CI-test platform filters (#112847)

This commit is contained in:
Jan Bouwhuis 2024-03-09 23:48:54 +01:00 committed by GitHub
parent 8ea093ca3b
commit caaa03536b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
40 changed files with 20 additions and 403 deletions

View file

@ -84,7 +84,6 @@ from .const import ( # noqa: F401
DOMAIN,
MQTT_CONNECTED,
MQTT_DISCONNECTED,
PLATFORMS,
RELOADABLE_PLATFORMS,
TEMPLATE_ERRORS,
)

View file

@ -142,34 +142,6 @@ MQTT_DISCONNECTED = "mqtt_disconnected"
PAYLOAD_EMPTY_JSON = "{}"
PAYLOAD_NONE = "None"
PLATFORMS = [
Platform.ALARM_CONTROL_PANEL,
Platform.BINARY_SENSOR,
Platform.BUTTON,
Platform.CAMERA,
Platform.CLIMATE,
Platform.COVER,
Platform.DEVICE_TRACKER,
Platform.EVENT,
Platform.FAN,
Platform.HUMIDIFIER,
Platform.IMAGE,
Platform.LAWN_MOWER,
Platform.LIGHT,
Platform.LOCK,
Platform.NUMBER,
Platform.SCENE,
Platform.SELECT,
Platform.SENSOR,
Platform.SIREN,
Platform.SWITCH,
Platform.TEXT,
Platform.UPDATE,
Platform.VACUUM,
Platform.VALVE,
Platform.WATER_HEATER,
]
RELOADABLE_PLATFORMS = [
Platform.ALARM_CONTROL_PANEL,
Platform.BINARY_SENSOR,

View file

@ -35,7 +35,6 @@ from homeassistant.const import (
STATE_ALARM_PENDING,
STATE_ALARM_TRIGGERED,
STATE_UNKNOWN,
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
@ -135,15 +134,6 @@ DEFAULT_CONFIG_REMOTE_CODE_TEXT = {
}
@pytest.fixture(autouse=True)
def alarm_control_panel_platform_only():
"""Only setup the alarm_control_panel platform to speed up tests."""
with patch(
"homeassistant.components.mqtt.PLATFORMS", [Platform.ALARM_CONTROL_PANEL]
):
yield
@pytest.mark.parametrize(
("hass_config", "valid"),
[

View file

@ -18,7 +18,6 @@ from homeassistant.const import (
STATE_ON,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
Platform,
)
from homeassistant.core import HomeAssistant, State, callback
from homeassistant.helpers.typing import ConfigType
@ -72,13 +71,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def binary_sensor_platform_only():
"""Only setup the binary_sensor platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]):
yield
@pytest.mark.parametrize(
"hass_config",
[

View file

@ -7,12 +7,7 @@ from unittest.mock import patch
import pytest
from homeassistant.components import button, mqtt
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_FRIENDLY_NAME,
STATE_UNKNOWN,
Platform,
)
from homeassistant.const import ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME, STATE_UNKNOWN
from homeassistant.core import HomeAssistant
from .test_common import (
@ -50,13 +45,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def button_platform_only():
"""Only setup the button platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BUTTON]):
yield
@pytest.mark.freeze_time("2021-11-08 13:31:44+00:00")
@pytest.mark.parametrize(
"hass_config",

View file

@ -9,7 +9,6 @@ import pytest
from homeassistant.components import camera, mqtt
from homeassistant.components.mqtt.camera import MQTT_CAMERA_ATTRIBUTES_BLOCKED
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from .test_common import (
@ -49,13 +48,6 @@ from tests.typing import (
DEFAULT_CONFIG = {mqtt.DOMAIN: {camera.DOMAIN: {"name": "test", "topic": "test_topic"}}}
@pytest.fixture(autouse=True)
def camera_platform_only():
"""Only setup the camera platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.CAMERA]):
yield
@pytest.mark.parametrize(
"hass_config",
[{mqtt.DOMAIN: {camera.DOMAIN: {"topic": "test/camera", "name": "Test Camera"}}}],

View file

@ -32,7 +32,7 @@ from homeassistant.components.mqtt.climate import (
MQTT_CLIMATE_ATTRIBUTES_BLOCKED,
VALUE_TEMPLATE_KEYS,
)
from homeassistant.const import ATTR_TEMPERATURE, Platform, UnitOfTemperature
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceValidationError
@ -99,13 +99,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def climate_platform_only():
"""Only setup the climate platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.CLIMATE]):
yield
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_params(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator

View file

@ -43,7 +43,6 @@ from homeassistant.const import (
STATE_OPEN,
STATE_OPENING,
STATE_UNKNOWN,
Platform,
)
from homeassistant.core import HomeAssistant
@ -86,13 +85,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def cover_platform_only():
"""Only setup the cover platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.COVER]):
yield
@pytest.mark.parametrize(
"hass_config",
[

View file

@ -1,14 +1,13 @@
"""The tests for the MQTT device_tracker platform."""
from datetime import UTC, datetime
from unittest.mock import patch
from freezegun.api import FrozenDateTimeFactory
import pytest
from homeassistant.components import device_tracker, mqtt
from homeassistant.components.mqtt.const import DOMAIN as MQTT_DOMAIN
from homeassistant.const import STATE_HOME, STATE_NOT_HOME, STATE_UNKNOWN, Platform
from homeassistant.const import STATE_HOME, STATE_NOT_HOME, STATE_UNKNOWN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.setup import async_setup_component
@ -37,13 +36,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def device_tracker_platform_only():
"""Only setup the device_tracker platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.DEVICE_TRACKER]):
yield
async def test_discover_device_tracker(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,

View file

@ -1,7 +1,6 @@
"""The tests for MQTT device triggers."""
import json
from unittest.mock import patch
import pytest
from pytest_unordered import unordered
@ -9,7 +8,6 @@ from pytest_unordered import unordered
import homeassistant.components.automation as automation
from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.mqtt import _LOGGER, DOMAIN, debug_info
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import device_registry as dr
@ -37,16 +35,6 @@ def calls(hass: HomeAssistant) -> list[ServiceCall]:
return async_mock_service(hass, "test", "automation")
@pytest.fixture(autouse=True)
def binary_sensor_and_sensor_only():
"""Only setup the binary_sensor and sensor platform to speed up tests."""
with patch(
"homeassistant.components.mqtt.PLATFORMS",
[Platform.BINARY_SENSOR, Platform.SENSOR],
):
yield
async def test_get_triggers(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,

View file

@ -1,12 +1,11 @@
"""Test MQTT diagnostics."""
import json
from unittest.mock import ANY, patch
from unittest.mock import ANY
import pytest
from homeassistant.components import mqtt
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
@ -23,16 +22,6 @@ default_config = {
}
@pytest.fixture(autouse=True)
def device_tracker_sensor_only():
"""Only setup the device_tracker and sensor platforms to speed up tests."""
with patch(
"homeassistant.components.mqtt.PLATFORMS",
[Platform.DEVICE_TRACKER, Platform.SENSOR],
):
yield
async def test_entry_diagnostics(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,

View file

@ -69,7 +69,6 @@ async def test_subscribing_config_topic(
assert discovery_topic + "/+/+/+/config" in topics
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
@pytest.mark.parametrize(
("topic", "log"),
[
@ -103,7 +102,6 @@ async def test_invalid_topic(
caplog.clear()
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_invalid_json(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -124,7 +122,9 @@ async def test_invalid_json(
assert not mock_dispatcher_send.called
@pytest.mark.parametrize("domain", [*list(mqtt.PLATFORMS), "device_automation", "tag"])
@pytest.mark.parametrize(
"domain", ["tag", "device_automation", Platform.SENSOR, Platform.LIGHT]
)
@pytest.mark.no_fail_on_log_exception
async def test_discovery_schema_error(
hass: HomeAssistant,
@ -147,7 +147,6 @@ async def test_discovery_schema_error(
assert "AttributeError: Attribute abc not found" in caplog.text
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.ALARM_CONTROL_PANEL])
async def test_invalid_config(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -191,7 +190,6 @@ async def test_only_valid_components(
assert not mock_dispatcher_send.called
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_correct_config_discovery(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -212,7 +210,6 @@ async def test_correct_config_discovery(
assert ("binary_sensor", "bla") in hass.data["mqtt"].discovery_already_discovered
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_discovery_integration_info(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -265,7 +262,6 @@ async def test_discovery_integration_info(
'{ "name": "Beer", "state_topic": "test-topic", "o": {"sw": "bla2mqtt"} }',
],
)
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_discovery_with_invalid_integration_info(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -289,7 +285,6 @@ async def test_discovery_with_invalid_integration_info(
)
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.FAN])
async def test_discover_fan(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -310,7 +305,6 @@ async def test_discover_fan(
assert ("fan", "bla") in hass.data["mqtt"].discovery_already_discovered
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.CLIMATE])
async def test_discover_climate(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -334,7 +328,6 @@ async def test_discover_climate(
assert ("climate", "bla") in hass.data["mqtt"].discovery_already_discovered
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.ALARM_CONTROL_PANEL])
async def test_discover_alarm_control_panel(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -525,7 +518,6 @@ async def test_discovery_with_object_id(
assert (domain, "object bla") in hass.data["mqtt"].discovery_already_discovered
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_discovery_incl_nodeid(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -548,7 +540,6 @@ async def test_discovery_incl_nodeid(
].discovery_already_discovered
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_non_duplicate_discovery(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -577,7 +568,6 @@ async def test_non_duplicate_discovery(
assert "Component has already been discovered: binary_sensor bla" in caplog.text
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_removal(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -599,7 +589,6 @@ async def test_removal(
assert state is None
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_rediscover(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -630,7 +619,6 @@ async def test_rediscover(
assert state is not None
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_rapid_rediscover(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -683,7 +671,6 @@ async def test_rapid_rediscover(
assert events[4].data["old_state"] is None
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_rapid_rediscover_unique(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -746,7 +733,6 @@ async def test_rapid_rediscover_unique(
assert events[3].data["old_state"] is None
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_rapid_reconfigure(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -802,7 +788,6 @@ async def test_rapid_reconfigure(
assert events[2].data["new_state"].attributes["friendly_name"] == "Wine"
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_duplicate_removal(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -888,7 +873,6 @@ async def test_cleanup_device(
)
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
async def test_cleanup_device_mqtt(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
@ -934,7 +918,6 @@ async def test_cleanup_device_mqtt(
mqtt_mock.async_publish.assert_not_called()
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
async def test_cleanup_device_multiple_config_entries(
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
@ -1126,7 +1109,6 @@ async def test_cleanup_device_multiple_config_entries_mqtt(
mqtt_mock.async_publish.assert_not_called()
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH])
async def test_discovery_expansion(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -1189,7 +1171,6 @@ async def test_discovery_expansion(
assert state and state.state == STATE_UNAVAILABLE
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH])
async def test_discovery_expansion_2(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -1234,7 +1215,6 @@ async def test_discovery_expansion_2(
assert state.state == STATE_UNKNOWN
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH])
async def test_discovery_expansion_3(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -1319,7 +1299,6 @@ async def test_discovery_expansion_without_encoding_and_value_template_1(
assert state and state.state == STATE_UNAVAILABLE
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH])
async def test_discovery_expansion_without_encoding_and_value_template_2(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -1433,7 +1412,6 @@ async def test_missing_discover_abbreviations(
assert not missing
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH])
async def test_no_implicit_state_topic_switch(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -1458,7 +1436,6 @@ async def test_no_implicit_state_topic_switch(
assert state and state.state == STATE_UNKNOWN
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
@pytest.mark.parametrize(
"mqtt_config_entry_data",
[
@ -1490,7 +1467,6 @@ async def test_complex_discovery_topic_prefix(
].discovery_already_discovered
@patch("homeassistant.components.mqtt.PLATFORMS", [])
@patch("homeassistant.components.mqtt.client.INITIAL_SUBSCRIBE_COOLDOWN", 0.0)
@patch("homeassistant.components.mqtt.client.SUBSCRIBE_COOLDOWN", 0.0)
@patch("homeassistant.components.mqtt.client.UNSUBSCRIBE_COOLDOWN", 0.0)
@ -1540,7 +1516,6 @@ async def test_mqtt_integration_discovery_subscribe_unsubscribe(
mqtt_client_mock.unsubscribe.assert_called_once_with(["comp/discovery/#"])
@patch("homeassistant.components.mqtt.PLATFORMS", [])
@patch("homeassistant.components.mqtt.client.INITIAL_SUBSCRIBE_COOLDOWN", 0.0)
@patch("homeassistant.components.mqtt.client.SUBSCRIBE_COOLDOWN", 0.0)
@patch("homeassistant.components.mqtt.client.UNSUBSCRIBE_COOLDOWN", 0.0)
@ -1583,7 +1558,6 @@ async def test_mqtt_discovery_unsubscribe_once(
mqtt_client_mock.unsubscribe.assert_called_once_with(["comp/discovery/#"])
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
async def test_clear_config_topic_disabled_entity(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -1658,7 +1632,6 @@ async def test_clear_config_topic_disabled_entity(
)
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
async def test_clean_up_registry_monitoring(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -1713,7 +1686,6 @@ async def test_clean_up_registry_monitoring(
assert len(hooks) == 0
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
async def test_unique_id_collission_has_priority(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -1760,7 +1732,6 @@ async def test_unique_id_collission_has_priority(
assert entity_registry.async_get("sensor.abc123_sbfspot_12345_2") is None
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
async def test_update_with_bad_config_not_breaks_discovery(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None:

View file

@ -9,7 +9,7 @@ import pytest
from homeassistant.components import event, mqtt
from homeassistant.components.mqtt.event import MQTT_EVENT_ATTRIBUTES_BLOCKED
from homeassistant.const import STATE_UNKNOWN, Platform
from homeassistant.const import STATE_UNKNOWN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
@ -65,13 +65,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def event_platform_only():
"""Only setup the event platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.EVENT]):
yield
@pytest.mark.freeze_time("2023-08-01 00:00:00+00:00")
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setting_event_value_via_mqtt_message(

View file

@ -33,7 +33,6 @@ from homeassistant.const import (
STATE_OFF,
STATE_ON,
STATE_UNKNOWN,
Platform,
)
from homeassistant.core import HomeAssistant
@ -83,13 +82,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def fan_platform_only():
"""Only setup the fan platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.FAN]):
yield
@pytest.mark.parametrize("hass_config", [{mqtt.DOMAIN: {fan.DOMAIN: {"name": "test"}}}])
async def test_fail_setup_if_no_command_topic(
hass: HomeAssistant,

View file

@ -34,7 +34,6 @@ from homeassistant.const import (
STATE_OFF,
STATE_ON,
STATE_UNKNOWN,
Platform,
)
from homeassistant.core import HomeAssistant
@ -84,13 +83,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def humidifer_platform_only():
"""Only setup the humidifer platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.HUMIDIFIER]):
yield
async def async_turn_on(
hass: HomeAssistant,
entity_id=ENTITY_MATCH_ALL,

View file

@ -11,7 +11,7 @@ import pytest
import respx
from homeassistant.components import image, mqtt
from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN, Platform
from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN
from homeassistant.core import HomeAssistant
from .test_common import (
@ -54,13 +54,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def image_platform_only():
"""Only setup the image platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.IMAGE]):
yield
@pytest.mark.freeze_time("2023-04-01 00:00:00+00:00")
@pytest.mark.parametrize(
"hass_config",

View file

@ -1,7 +1,6 @@
"""The tests for the MQTT component."""
import asyncio
from collections.abc import Generator
from copy import deepcopy
from datetime import datetime, timedelta
from functools import partial
@ -32,7 +31,6 @@ from homeassistant.const import (
SERVICE_RELOAD,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
Platform,
UnitOfTemperature,
)
import homeassistant.core as ha
@ -92,16 +90,6 @@ class RecordCallsPartial(partial[Any]):
__name__ = "RecordCallPartialTest"
@pytest.fixture(autouse=True)
def sensor_platforms_only() -> Generator[None, None, None]:
"""Only setup the sensor platforms to speed up tests."""
with patch(
"homeassistant.components.mqtt.PLATFORMS",
[Platform.SENSOR, Platform.BINARY_SENSOR],
):
yield
@pytest.fixture(autouse=True)
def mock_storage(hass_storage: dict[str, Any]) -> None:
"""Autouse hass_storage for the TestCase tests."""
@ -168,7 +156,6 @@ async def test_mqtt_disconnects_on_home_assistant_stop(
assert mqtt_client_mock.loop_stop.call_count == 1
@patch("homeassistant.components.mqtt.PLATFORMS", [])
async def test_mqtt_await_ack_at_disconnect(
hass: HomeAssistant,
) -> None:
@ -312,7 +299,6 @@ async def test_command_template_value(hass: HomeAssistant) -> None:
assert cmd_tpl.async_render(None, variables=variables) == "beer"
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SELECT])
@pytest.mark.parametrize(
"config",
[
@ -2162,7 +2148,6 @@ async def test_handle_message_callback(
}
],
)
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.LIGHT])
async def test_setup_manual_mqtt_with_platform_key(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -2177,7 +2162,6 @@ async def test_setup_manual_mqtt_with_platform_key(
@pytest.mark.parametrize("hass_config", [{mqtt.DOMAIN: {"light": {"name": "test"}}}])
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.LIGHT])
async def test_setup_manual_mqtt_with_invalid_config(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -2188,7 +2172,6 @@ async def test_setup_manual_mqtt_with_invalid_config(
assert "required key not provided" in caplog.text
@patch("homeassistant.components.mqtt.PLATFORMS", [])
@pytest.mark.parametrize(
("mqtt_config_entry_data", "protocol"),
[
@ -2229,7 +2212,6 @@ async def test_setup_mqtt_client_protocol(
@patch("homeassistant.components.mqtt.client.TIMEOUT_ACK", 0.2)
@patch("homeassistant.components.mqtt.PLATFORMS", [])
async def test_handle_mqtt_timeout_on_callback(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
@ -2300,7 +2282,6 @@ async def test_setup_raises_config_entry_not_ready_if_no_connect_broker(
({"broker": "test-broker", "certificate": "auto", "tls_insecure": True}, True),
],
)
@patch("homeassistant.components.mqtt.PLATFORMS", [])
async def test_setup_uses_certificate_on_certificate_set_to_auto_and_insecure(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -2921,7 +2902,6 @@ async def test_mqtt_ws_get_device_debug_info(
assert response["result"] == expected_result
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.CAMERA])
async def test_mqtt_ws_get_device_debug_info_binary(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
@ -3575,7 +3555,6 @@ async def test_unload_config_entry(
assert "No ACK from MQTT server" not in caplog.text
@patch("homeassistant.components.mqtt.PLATFORMS", [])
async def test_publish_or_subscribe_without_valid_config_entry(
hass: HomeAssistant, record_calls: MessageCallbackType
) -> None:
@ -3588,10 +3567,6 @@ async def test_publish_or_subscribe_without_valid_config_entry(
await mqtt.async_subscribe(hass, "some-topic", record_calls, qos=0)
@patch(
"homeassistant.components.mqtt.PLATFORMS",
[Platform.ALARM_CONTROL_PANEL, Platform.LIGHT],
)
@pytest.mark.parametrize(
"hass_config",
[
@ -3666,7 +3641,6 @@ async def test_disabling_and_enabling_entry(
assert hass.states.get("alarm_control_panel.test") is not None
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.LIGHT])
@pytest.mark.parametrize(
("hass_config", "unique"),
[

View file

@ -16,12 +16,7 @@ from homeassistant.components.lawn_mower import (
LawnMowerEntityFeature,
)
from homeassistant.components.mqtt.lawn_mower import MQTT_LAWN_MOWER_ATTRIBUTES_BLOCKED
from homeassistant.const import (
ATTR_ASSUMED_STATE,
ATTR_ENTITY_ID,
STATE_UNKNOWN,
Platform,
)
from homeassistant.const import ATTR_ASSUMED_STATE, ATTR_ENTITY_ID, STATE_UNKNOWN
from homeassistant.core import HomeAssistant, State
from .test_common import (
@ -79,13 +74,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def lawn_mower_platform_only():
"""Only setup the lawn_mower platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.LAWN_MOWER]):
yield
@pytest.mark.parametrize(
"hass_config",
[

View file

@ -5,12 +5,10 @@
# cleanup is planned with HA Core 2025.2
import json
from unittest.mock import patch
import pytest
from homeassistant.components import mqtt, vacuum
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers.typing import DiscoveryInfoType
@ -20,13 +18,6 @@ from tests.typing import MqttMockHAClientGenerator
DEFAULT_CONFIG = {mqtt.DOMAIN: {vacuum.DOMAIN: {"name": "test"}}}
@pytest.fixture(autouse=True)
def vacuum_platform_only():
"""Only setup the vacuum platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.VACUUM]):
yield
@pytest.mark.parametrize(
("hass_config", "removed"),
[

View file

@ -190,13 +190,7 @@ from homeassistant.components.mqtt.light.schema_basic import (
VALUE_TEMPLATE_KEYS,
)
from homeassistant.components.mqtt.models import PublishPayloadType
from homeassistant.const import (
ATTR_ASSUMED_STATE,
STATE_OFF,
STATE_ON,
STATE_UNKNOWN,
Platform,
)
from homeassistant.const import ATTR_ASSUMED_STATE, STATE_OFF, STATE_ON, STATE_UNKNOWN
from homeassistant.core import HomeAssistant, State
from .test_common import (
@ -239,13 +233,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def light_platform_only():
"""Only setup the light platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.LIGHT]):
yield
@pytest.mark.parametrize(
"hass_config", [{mqtt.DOMAIN: {light.DOMAIN: {"name": "test"}}}]
)

View file

@ -96,7 +96,6 @@ from homeassistant.const import (
STATE_OFF,
STATE_ON,
STATE_UNKNOWN,
Platform,
)
from homeassistant.core import HomeAssistant, State
from homeassistant.helpers.json import json_dumps
@ -170,13 +169,6 @@ COLOR_MODES_CONFIG = {
}
@pytest.fixture(autouse=True)
def light_platform_only():
"""Only setup the light platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.LIGHT]):
yield
class JsonValidator:
"""Helper to compare JSON."""

View file

@ -42,7 +42,6 @@ from homeassistant.const import (
STATE_OFF,
STATE_ON,
STATE_UNKNOWN,
Platform,
)
from homeassistant.core import HomeAssistant, State
@ -94,13 +93,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def light_platform_only():
"""Only setup the light platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.LIGHT]):
yield
@pytest.mark.parametrize(
"hass_config",
[

View file

@ -24,7 +24,6 @@ from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_SUPPORTED_FEATURES,
STATE_UNKNOWN,
Platform,
)
from homeassistant.core import HomeAssistant
@ -83,13 +82,6 @@ CONFIG_WITH_STATES = {
}
@pytest.fixture(autouse=True)
def lock_platform_only():
"""Only setup the lock platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.LOCK]):
yield
@pytest.mark.parametrize(
("hass_config", "payload", "lock_state"),
[

View file

@ -10,7 +10,6 @@ from homeassistant.const import (
ATTR_FRIENDLY_NAME,
EVENT_HOMEASSISTANT_STARTED,
EVENT_STATE_CHANGED,
Platform,
)
from homeassistant.core import CoreState, HomeAssistant, callback
from homeassistant.helpers import device_registry as dr, issue_registry as ir
@ -37,7 +36,6 @@ from tests.typing import MqttMockHAClientGenerator, MqttMockPahoClient
}
],
)
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
async def test_availability_with_shared_state_topic(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
@ -296,7 +294,6 @@ async def test_availability_with_shared_state_topic(
"entity_name_startswith_device_name2",
],
)
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
@patch("homeassistant.components.mqtt.client.DISCOVERY_COOLDOWN", 0.0)
async def test_default_entity_and_device_name(
hass: HomeAssistant,
@ -340,7 +337,6 @@ async def test_default_entity_and_device_name(
assert len(events) == 0
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
async def test_name_attribute_is_set_or_not(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,

View file

@ -26,7 +26,6 @@ from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_MODE,
ATTR_UNIT_OF_MEASUREMENT,
Platform,
UnitOfTemperature,
)
from homeassistant.core import HomeAssistant, State
@ -71,13 +70,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def number_platform_only():
"""Only setup the number platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.NUMBER]):
yield
@pytest.mark.parametrize(
("hass_config", "device_class", "unit_of_measurement", "values"),
[

View file

@ -7,7 +7,7 @@ from unittest.mock import patch
import pytest
from homeassistant.components import mqtt, scene
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON, STATE_UNKNOWN, Platform
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON, STATE_UNKNOWN
from homeassistant.core import HomeAssistant, State
from .test_common import (
@ -51,13 +51,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def scene_platform_only():
"""Only setup the scene platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SCENE]):
yield
@pytest.mark.parametrize(
"hass_config",
[

View file

@ -16,12 +16,7 @@ from homeassistant.components.select import (
DOMAIN as SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
)
from homeassistant.const import (
ATTR_ASSUMED_STATE,
ATTR_ENTITY_ID,
STATE_UNKNOWN,
Platform,
)
from homeassistant.const import ATTR_ASSUMED_STATE, ATTR_ENTITY_ID, STATE_UNKNOWN
from homeassistant.core import HomeAssistant, State
from homeassistant.helpers.typing import ConfigType
@ -71,13 +66,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def select_platform_only():
"""Only setup the select platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SELECT]):
yield
def _test_run_select_setup_params(
topic: str,
) -> Generator[tuple[ConfigType, str], None]:

View file

@ -17,7 +17,6 @@ from homeassistant.const import (
EVENT_STATE_CHANGED,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
Platform,
UnitOfTemperature,
)
from homeassistant.core import Event, HomeAssistant, State, callback
@ -81,13 +80,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def sensor_platform_only():
"""Only setup the sensor platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR]):
yield
@pytest.mark.parametrize(
"hass_config",
[

View file

@ -17,7 +17,6 @@ from homeassistant.const import (
STATE_OFF,
STATE_ON,
STATE_UNKNOWN,
Platform,
)
from homeassistant.core import HomeAssistant
@ -60,13 +59,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def siren_platform_only():
"""Only setup the siren platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SIREN]):
yield
async def async_turn_on(
hass: HomeAssistant,
entity_id: str = ENTITY_MATCH_ALL,

View file

@ -1,6 +1,6 @@
"""The tests for the MQTT subscription component."""
from unittest.mock import ANY, patch
from unittest.mock import ANY
import pytest
@ -15,13 +15,6 @@ from tests.common import async_fire_mqtt_message
from tests.typing import MqttMockHAClientGenerator
@pytest.fixture(autouse=True)
def no_platforms():
"""Skip platform setup to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", []):
yield
async def test_subscribe_topics(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,

View file

@ -13,7 +13,6 @@ from homeassistant.const import (
STATE_OFF,
STATE_ON,
STATE_UNKNOWN,
Platform,
)
from homeassistant.core import HomeAssistant, State
@ -57,13 +56,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def switch_platform_only():
"""Only setup the switch platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH]):
yield
@pytest.mark.parametrize(
("hass_config", "device_class"),
[

View file

@ -9,7 +9,6 @@ import pytest
from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.mqtt.const import DOMAIN as MQTT_DOMAIN
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from homeassistant.setup import async_setup_component
@ -47,13 +46,6 @@ DEFAULT_TAG_SCAN_JSON = (
)
@pytest.fixture(autouse=True)
def binary_sensor_only() -> Generator[None, None, None]:
"""Only setup the binary_sensor platform to speed up test."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]):
yield
@pytest.fixture
def tag_mock() -> Generator[AsyncMock, None, None]:
"""Fixture to mock tag."""

View file

@ -8,12 +8,7 @@ from unittest.mock import patch
import pytest
from homeassistant.components import mqtt, text
from homeassistant.const import (
ATTR_ASSUMED_STATE,
ATTR_ENTITY_ID,
STATE_UNKNOWN,
Platform,
)
from homeassistant.const import ATTR_ASSUMED_STATE, ATTR_ENTITY_ID, STATE_UNKNOWN
from homeassistant.core import HomeAssistant
from .test_common import (
@ -55,13 +50,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def text_platform_only():
"""Only setup the text platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.TEXT]):
yield
async def async_set_value(
hass: HomeAssistant, entity_id: str, value: str | None
) -> None:

View file

@ -1,6 +1,6 @@
"""The tests for the MQTT automation."""
from unittest.mock import ANY, patch
from unittest.mock import ANY
import pytest
@ -23,13 +23,6 @@ def calls(hass: HomeAssistant):
return async_mock_service(hass, "test", "automation")
@pytest.fixture(autouse=True)
def no_platforms():
"""Skip platform setup to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", []):
yield
@pytest.fixture(autouse=True)
async def setup_comp(hass: HomeAssistant, mqtt_mock_entry):
"""Initialize components."""

View file

@ -7,13 +7,7 @@ import pytest
from homeassistant.components import mqtt, update
from homeassistant.components.update import DOMAIN as UPDATE_DOMAIN, SERVICE_INSTALL
from homeassistant.const import (
ATTR_ENTITY_ID,
STATE_OFF,
STATE_ON,
STATE_UNKNOWN,
Platform,
)
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON, STATE_UNKNOWN
from homeassistant.core import HomeAssistant
from .test_common import (
@ -58,13 +52,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def update_platform_only():
"""Only setup the update platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.UPDATE]):
yield
@pytest.mark.parametrize(
("hass_config", "device_class"),
[

View file

@ -134,7 +134,6 @@ async def test_return_default_get_file_path(
assert await hass.async_add_executor_job(_get_file_path, tempdir)
@patch("homeassistant.components.mqtt.PLATFORMS", [])
async def test_waiting_for_client_not_loaded(
hass: HomeAssistant,
mqtt_client_mock: MqttMockPahoClient,
@ -172,7 +171,6 @@ async def test_waiting_for_client_not_loaded(
unsub()
@patch("homeassistant.components.mqtt.PLATFORMS", [])
async def test_waiting_for_client_loaded(
hass: HomeAssistant,
mqtt_mock: MqttMockHAClient,

View file

@ -32,7 +32,7 @@ from homeassistant.components.vacuum import (
STATE_CLEANING,
STATE_DOCKED,
)
from homeassistant.const import CONF_NAME, ENTITY_MATCH_ALL, STATE_UNKNOWN, Platform
from homeassistant.const import CONF_NAME, ENTITY_MATCH_ALL, STATE_UNKNOWN
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
@ -103,13 +103,6 @@ CONFIG_ALL_SERVICES = help_custom_config(
)
@pytest.fixture(autouse=True)
def vacuum_platform_only():
"""Only setup the vacuum platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.VACUUM]):
yield
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_default_supported_features(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator

View file

@ -27,7 +27,6 @@ from homeassistant.const import (
STATE_OPEN,
STATE_OPENING,
STATE_UNKNOWN,
Platform,
)
from homeassistant.core import HomeAssistant
@ -87,13 +86,6 @@ DEFAULT_CONFIG_REPORTS_POSITION = {
}
@pytest.fixture(autouse=True)
def valve_platform_only():
"""Only setup the valve platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.VALVE]):
yield
@pytest.mark.parametrize(
"hass_config",
[

View file

@ -25,7 +25,7 @@ from homeassistant.components.water_heater import (
STATE_PERFORMANCE,
WaterHeaterEntityFeature,
)
from homeassistant.const import ATTR_TEMPERATURE, STATE_OFF, Platform, UnitOfTemperature
from homeassistant.const import ATTR_TEMPERATURE, STATE_OFF, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.util.unit_conversion import TemperatureConverter
@ -96,13 +96,6 @@ DEFAULT_CONFIG = {
}
@pytest.fixture(autouse=True)
def water_heater_platform_only():
"""Only setup the water heater platform to speed up tests."""
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.WATER_HEATER]):
yield
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_setup_params(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator

View file

@ -935,8 +935,7 @@ async def mqtt_mock(
mqtt_mock_entry: MqttMockHAClientGenerator,
) -> AsyncGenerator[MqttMockHAClient, None]:
"""Fixture to mock MQTT component."""
with patch("homeassistant.components.mqtt.PLATFORMS", []):
return await mqtt_mock_entry()
return await mqtt_mock_entry()
@asynccontextmanager