Speed up mqtt tests (#73423)
Co-authored-by: jbouwh <jan@jbsoft.nl> Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
This commit is contained in:
parent
034c0c0593
commit
51b4d15c8c
29 changed files with 281 additions and 10 deletions
|
@ -30,6 +30,7 @@ from homeassistant.const import (
|
||||||
STATE_ALARM_PENDING,
|
STATE_ALARM_PENDING,
|
||||||
STATE_ALARM_TRIGGERED,
|
STATE_ALARM_TRIGGERED,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -112,6 +113,15 @@ 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
|
||||||
|
|
||||||
|
|
||||||
async def test_fail_setup_without_state_topic(hass, mqtt_mock_entry_no_yaml_config):
|
async def test_fail_setup_without_state_topic(hass, mqtt_mock_entry_no_yaml_config):
|
||||||
"""Test for failing with no state topic."""
|
"""Test for failing with no state topic."""
|
||||||
with assert_setup_component(0, alarm_control_panel.DOMAIN) as config:
|
with assert_setup_component(0, alarm_control_panel.DOMAIN) as config:
|
||||||
|
|
|
@ -13,6 +13,7 @@ from homeassistant.const import (
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -62,6 +63,13 @@ 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
|
||||||
|
|
||||||
|
|
||||||
async def test_setting_sensor_value_expires_availability_topic(
|
async def test_setting_sensor_value_expires_availability_topic(
|
||||||
hass, mqtt_mock_entry_with_yaml_config, caplog
|
hass, mqtt_mock_entry_with_yaml_config, caplog
|
||||||
):
|
):
|
||||||
|
|
|
@ -5,7 +5,12 @@ from unittest.mock import patch
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import button
|
from homeassistant.components import button
|
||||||
from homeassistant.const import ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME, STATE_UNKNOWN
|
from homeassistant.const import (
|
||||||
|
ATTR_ENTITY_ID,
|
||||||
|
ATTR_FRIENDLY_NAME,
|
||||||
|
STATE_UNKNOWN,
|
||||||
|
Platform,
|
||||||
|
)
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .test_common import (
|
from .test_common import (
|
||||||
|
@ -41,6 +46,13 @@ 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.freeze_time("2021-11-08 13:31:44+00:00")
|
||||||
async def test_sending_mqtt_commands(hass, mqtt_mock_entry_with_yaml_config):
|
async def test_sending_mqtt_commands(hass, mqtt_mock_entry_with_yaml_config):
|
||||||
"""Test the sending MQTT commands."""
|
"""Test the sending MQTT commands."""
|
||||||
|
|
|
@ -9,6 +9,7 @@ import pytest
|
||||||
|
|
||||||
from homeassistant.components import camera
|
from homeassistant.components import camera
|
||||||
from homeassistant.components.mqtt.camera import MQTT_CAMERA_ATTRIBUTES_BLOCKED
|
from homeassistant.components.mqtt.camera import MQTT_CAMERA_ATTRIBUTES_BLOCKED
|
||||||
|
from homeassistant.const import Platform
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .test_common import (
|
from .test_common import (
|
||||||
|
@ -46,6 +47,13 @@ DEFAULT_CONFIG = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@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
|
||||||
|
|
||||||
|
|
||||||
async def test_run_camera_setup(
|
async def test_run_camera_setup(
|
||||||
hass, hass_client_no_auth, mqtt_mock_entry_with_yaml_config
|
hass, hass_client_no_auth, mqtt_mock_entry_with_yaml_config
|
||||||
):
|
):
|
||||||
|
|
|
@ -26,7 +26,7 @@ from homeassistant.components.climate.const import (
|
||||||
HVACMode,
|
HVACMode,
|
||||||
)
|
)
|
||||||
from homeassistant.components.mqtt.climate import MQTT_CLIMATE_ATTRIBUTES_BLOCKED
|
from homeassistant.components.mqtt.climate import MQTT_CLIMATE_ATTRIBUTES_BLOCKED
|
||||||
from homeassistant.const import ATTR_TEMPERATURE
|
from homeassistant.const import ATTR_TEMPERATURE, Platform
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .test_common import (
|
from .test_common import (
|
||||||
|
@ -106,6 +106,13 @@ DEFAULT_LEGACY_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
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_params(hass, mqtt_mock_entry_with_yaml_config):
|
async def test_setup_params(hass, mqtt_mock_entry_with_yaml_config):
|
||||||
"""Test the initial parameters."""
|
"""Test the initial parameters."""
|
||||||
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
assert await async_setup_component(hass, CLIMATE_DOMAIN, DEFAULT_CONFIG)
|
||||||
|
|
|
@ -43,6 +43,7 @@ from homeassistant.const import (
|
||||||
STATE_OPEN,
|
STATE_OPEN,
|
||||||
STATE_OPENING,
|
STATE_OPENING,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -83,6 +84,13 @@ 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
|
||||||
|
|
||||||
|
|
||||||
async def test_state_via_state_topic(hass, mqtt_mock_entry_with_yaml_config):
|
async def test_state_via_state_topic(hass, mqtt_mock_entry_with_yaml_config):
|
||||||
"""Test the controlling state via topic."""
|
"""Test the controlling state via topic."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
"""The tests for the MQTT device tracker platform using configuration.yaml."""
|
"""The tests for the MQTT device tracker platform using configuration.yaml."""
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.device_tracker.const import DOMAIN, SOURCE_TYPE_BLUETOOTH
|
from homeassistant.components.device_tracker.const import DOMAIN, SOURCE_TYPE_BLUETOOTH
|
||||||
from homeassistant.const import CONF_PLATFORM, STATE_HOME, STATE_NOT_HOME
|
from homeassistant.const import CONF_PLATFORM, STATE_HOME, STATE_NOT_HOME, Platform
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .test_common import help_test_setup_manual_entity_from_yaml
|
from .test_common import help_test_setup_manual_entity_from_yaml
|
||||||
|
@ -10,6 +12,13 @@ from .test_common import help_test_setup_manual_entity_from_yaml
|
||||||
from tests.common import async_fire_mqtt_message
|
from tests.common import async_fire_mqtt_message
|
||||||
|
|
||||||
|
|
||||||
|
@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
|
||||||
|
|
||||||
|
|
||||||
# Deprecated in HA Core 2022.6
|
# Deprecated in HA Core 2022.6
|
||||||
async def test_legacy_ensure_device_tracker_platform_validation(
|
async def test_legacy_ensure_device_tracker_platform_validation(
|
||||||
hass, mqtt_mock_entry_with_yaml_config
|
hass, mqtt_mock_entry_with_yaml_config
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
"""The tests for the MQTT device_tracker discovery platform."""
|
"""The tests for the MQTT device_tracker discovery platform."""
|
||||||
|
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import device_tracker
|
from homeassistant.components import device_tracker
|
||||||
from homeassistant.components.mqtt.const import DOMAIN as MQTT_DOMAIN
|
from homeassistant.components.mqtt.const import DOMAIN as MQTT_DOMAIN
|
||||||
from homeassistant.components.mqtt.discovery import ALREADY_DISCOVERED
|
from homeassistant.components.mqtt.discovery import ALREADY_DISCOVERED
|
||||||
from homeassistant.const import STATE_HOME, STATE_NOT_HOME, STATE_UNKNOWN
|
from homeassistant.const import STATE_HOME, STATE_NOT_HOME, STATE_UNKNOWN, Platform
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .test_common import help_test_setting_blocked_attribute_via_mqtt_json_message
|
from .test_common import help_test_setting_blocked_attribute_via_mqtt_json_message
|
||||||
|
@ -21,6 +23,13 @@ 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
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def device_reg(hass):
|
def device_reg(hass):
|
||||||
"""Return an empty, loaded, registry."""
|
"""Return an empty, loaded, registry."""
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
"""The tests for MQTT device triggers."""
|
"""The tests for MQTT device triggers."""
|
||||||
import json
|
import json
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import homeassistant.components.automation as automation
|
import homeassistant.components.automation as automation
|
||||||
from homeassistant.components.device_automation import DeviceAutomationType
|
from homeassistant.components.device_automation import DeviceAutomationType
|
||||||
from homeassistant.components.mqtt import _LOGGER, DOMAIN, debug_info
|
from homeassistant.components.mqtt import _LOGGER, DOMAIN, debug_info
|
||||||
|
from homeassistant.const import Platform
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.helpers.trigger import async_initialize_triggers
|
from homeassistant.helpers.trigger import async_initialize_triggers
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -39,6 +41,16 @@ def calls(hass):
|
||||||
return async_mock_service(hass, "test", "automation")
|
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(
|
async def test_get_triggers(
|
||||||
hass, device_reg, entity_reg, mqtt_mock_entry_no_yaml_config
|
hass, device_reg, entity_reg, mqtt_mock_entry_no_yaml_config
|
||||||
):
|
):
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
"""Test MQTT diagnostics."""
|
"""Test MQTT diagnostics."""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from unittest.mock import ANY
|
from unittest.mock import ANY, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import mqtt
|
from homeassistant.components import mqtt
|
||||||
|
from homeassistant.const import Platform
|
||||||
|
|
||||||
from tests.common import async_fire_mqtt_message, mock_device_registry
|
from tests.common import async_fire_mqtt_message, mock_device_registry
|
||||||
from tests.components.diagnostics import (
|
from tests.components.diagnostics import (
|
||||||
|
@ -31,6 +32,16 @@ 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
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def device_reg(hass):
|
def device_reg(hass):
|
||||||
"""Return an empty, loaded, registry."""
|
"""Return an empty, loaded, registry."""
|
||||||
|
|
|
@ -18,6 +18,7 @@ from homeassistant.const import (
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -65,6 +66,7 @@ async def test_subscribing_config_topic(hass, mqtt_mock_entry_no_yaml_config):
|
||||||
assert discovery_topic + "/+/+/+/config" in topics
|
assert discovery_topic + "/+/+/+/config" in topics
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"topic, log",
|
"topic, log",
|
||||||
[
|
[
|
||||||
|
@ -92,6 +94,7 @@ async def test_invalid_topic(hass, mqtt_mock_entry_no_yaml_config, caplog, topic
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||||
async def test_invalid_json(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
async def test_invalid_json(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
"""Test sending in invalid JSON."""
|
"""Test sending in invalid JSON."""
|
||||||
await mqtt_mock_entry_no_yaml_config()
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
|
@ -131,6 +134,7 @@ async def test_only_valid_components(hass, mqtt_mock_entry_no_yaml_config, caplo
|
||||||
assert not mock_dispatcher_send.called
|
assert not mock_dispatcher_send.called
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||||
async def test_correct_config_discovery(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
async def test_correct_config_discovery(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
"""Test sending in correct JSON."""
|
"""Test sending in correct JSON."""
|
||||||
await mqtt_mock_entry_no_yaml_config()
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
|
@ -148,6 +152,7 @@ async def test_correct_config_discovery(hass, mqtt_mock_entry_no_yaml_config, ca
|
||||||
assert ("binary_sensor", "bla") in hass.data[ALREADY_DISCOVERED]
|
assert ("binary_sensor", "bla") in hass.data[ALREADY_DISCOVERED]
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.FAN])
|
||||||
async def test_discover_fan(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
async def test_discover_fan(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
"""Test discovering an MQTT fan."""
|
"""Test discovering an MQTT fan."""
|
||||||
await mqtt_mock_entry_no_yaml_config()
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
|
@ -165,6 +170,7 @@ async def test_discover_fan(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
assert ("fan", "bla") in hass.data[ALREADY_DISCOVERED]
|
assert ("fan", "bla") in hass.data[ALREADY_DISCOVERED]
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.CLIMATE])
|
||||||
async def test_discover_climate(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
async def test_discover_climate(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
"""Test discovering an MQTT climate component."""
|
"""Test discovering an MQTT climate component."""
|
||||||
await mqtt_mock_entry_no_yaml_config()
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
|
@ -184,6 +190,7 @@ async def test_discover_climate(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
assert ("climate", "bla") in hass.data[ALREADY_DISCOVERED]
|
assert ("climate", "bla") in hass.data[ALREADY_DISCOVERED]
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.ALARM_CONTROL_PANEL])
|
||||||
async def test_discover_alarm_control_panel(
|
async def test_discover_alarm_control_panel(
|
||||||
hass, mqtt_mock_entry_no_yaml_config, caplog
|
hass, mqtt_mock_entry_no_yaml_config, caplog
|
||||||
):
|
):
|
||||||
|
@ -365,6 +372,7 @@ async def test_discovery_with_object_id(
|
||||||
assert (domain, "object bla") in hass.data[ALREADY_DISCOVERED]
|
assert (domain, "object bla") in hass.data[ALREADY_DISCOVERED]
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||||
async def test_discovery_incl_nodeid(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
async def test_discovery_incl_nodeid(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
"""Test sending in correct JSON with optional node_id included."""
|
"""Test sending in correct JSON with optional node_id included."""
|
||||||
await mqtt_mock_entry_no_yaml_config()
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
|
@ -382,6 +390,7 @@ async def test_discovery_incl_nodeid(hass, mqtt_mock_entry_no_yaml_config, caplo
|
||||||
assert ("binary_sensor", "my_node_id bla") in hass.data[ALREADY_DISCOVERED]
|
assert ("binary_sensor", "my_node_id bla") in hass.data[ALREADY_DISCOVERED]
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||||
async def test_non_duplicate_discovery(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
async def test_non_duplicate_discovery(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
"""Test for a non duplicate component."""
|
"""Test for a non duplicate component."""
|
||||||
await mqtt_mock_entry_no_yaml_config()
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
|
@ -406,6 +415,7 @@ async def test_non_duplicate_discovery(hass, mqtt_mock_entry_no_yaml_config, cap
|
||||||
assert "Component has already been discovered: binary_sensor bla" in caplog.text
|
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, mqtt_mock_entry_no_yaml_config, caplog):
|
async def test_removal(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
"""Test removal of component through empty discovery message."""
|
"""Test removal of component through empty discovery message."""
|
||||||
await mqtt_mock_entry_no_yaml_config()
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
|
@ -424,6 +434,7 @@ async def test_removal(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
assert state is None
|
assert state is None
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||||
async def test_rediscover(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
async def test_rediscover(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
"""Test rediscover of removed component."""
|
"""Test rediscover of removed component."""
|
||||||
await mqtt_mock_entry_no_yaml_config()
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
|
@ -451,6 +462,7 @@ async def test_rediscover(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
assert state is not None
|
assert state is not None
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||||
async def test_rapid_rediscover(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
async def test_rapid_rediscover(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
"""Test immediate rediscover of removed component."""
|
"""Test immediate rediscover of removed component."""
|
||||||
await mqtt_mock_entry_no_yaml_config()
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
|
@ -500,6 +512,7 @@ async def test_rapid_rediscover(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
assert events[4].data["old_state"] is None
|
assert events[4].data["old_state"] is None
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||||
async def test_rapid_rediscover_unique(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
async def test_rapid_rediscover_unique(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
"""Test immediate rediscover of removed component."""
|
"""Test immediate rediscover of removed component."""
|
||||||
await mqtt_mock_entry_no_yaml_config()
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
|
@ -559,6 +572,7 @@ async def test_rapid_rediscover_unique(hass, mqtt_mock_entry_no_yaml_config, cap
|
||||||
assert events[3].data["old_state"] is None
|
assert events[3].data["old_state"] is None
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||||
async def test_rapid_reconfigure(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
async def test_rapid_reconfigure(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
"""Test immediate reconfigure of added component."""
|
"""Test immediate reconfigure of added component."""
|
||||||
await mqtt_mock_entry_no_yaml_config()
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
|
@ -611,6 +625,7 @@ async def test_rapid_reconfigure(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
assert events[2].data["new_state"].attributes["friendly_name"] == "Wine"
|
assert events[2].data["new_state"].attributes["friendly_name"] == "Wine"
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||||
async def test_duplicate_removal(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
async def test_duplicate_removal(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
"""Test for a non duplicate component."""
|
"""Test for a non duplicate component."""
|
||||||
await mqtt_mock_entry_no_yaml_config()
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
|
@ -688,6 +703,7 @@ async def test_cleanup_device(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
|
||||||
async def test_cleanup_device_mqtt(
|
async def test_cleanup_device_mqtt(
|
||||||
hass, device_reg, entity_reg, mqtt_mock_entry_no_yaml_config
|
hass, device_reg, entity_reg, mqtt_mock_entry_no_yaml_config
|
||||||
):
|
):
|
||||||
|
@ -730,6 +746,7 @@ async def test_cleanup_device_mqtt(
|
||||||
mqtt_mock.async_publish.assert_not_called()
|
mqtt_mock.async_publish.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SENSOR])
|
||||||
async def test_cleanup_device_multiple_config_entries(
|
async def test_cleanup_device_multiple_config_entries(
|
||||||
hass, hass_ws_client, device_reg, entity_reg, mqtt_mock_entry_no_yaml_config
|
hass, hass_ws_client, device_reg, entity_reg, mqtt_mock_entry_no_yaml_config
|
||||||
):
|
):
|
||||||
|
@ -905,6 +922,7 @@ async def test_cleanup_device_multiple_config_entries_mqtt(
|
||||||
mqtt_mock.async_publish.assert_not_called()
|
mqtt_mock.async_publish.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH])
|
||||||
async def test_discovery_expansion(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
async def test_discovery_expansion(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
"""Test expansion of abbreviated discovery payload."""
|
"""Test expansion of abbreviated discovery payload."""
|
||||||
await mqtt_mock_entry_no_yaml_config()
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
|
@ -963,6 +981,7 @@ async def test_discovery_expansion(hass, mqtt_mock_entry_no_yaml_config, caplog)
|
||||||
assert state.state == STATE_UNAVAILABLE
|
assert state.state == STATE_UNAVAILABLE
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH])
|
||||||
async def test_discovery_expansion_2(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
async def test_discovery_expansion_2(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
"""Test expansion of abbreviated discovery payload."""
|
"""Test expansion of abbreviated discovery payload."""
|
||||||
await mqtt_mock_entry_no_yaml_config()
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
|
@ -1003,6 +1022,7 @@ async def test_discovery_expansion_2(hass, mqtt_mock_entry_no_yaml_config, caplo
|
||||||
assert state.state == STATE_UNKNOWN
|
assert state.state == STATE_UNKNOWN
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH])
|
||||||
@pytest.mark.no_fail_on_log_exception
|
@pytest.mark.no_fail_on_log_exception
|
||||||
async def test_discovery_expansion_3(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
async def test_discovery_expansion_3(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
"""Test expansion of broken discovery payload."""
|
"""Test expansion of broken discovery payload."""
|
||||||
|
@ -1084,6 +1104,7 @@ async def test_discovery_expansion_without_encoding_and_value_template_1(
|
||||||
assert state.state == STATE_UNAVAILABLE
|
assert state.state == STATE_UNAVAILABLE
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH])
|
||||||
async def test_discovery_expansion_without_encoding_and_value_template_2(
|
async def test_discovery_expansion_without_encoding_and_value_template_2(
|
||||||
hass, mqtt_mock_entry_no_yaml_config, caplog
|
hass, mqtt_mock_entry_no_yaml_config, caplog
|
||||||
):
|
):
|
||||||
|
@ -1190,6 +1211,7 @@ async def test_missing_discover_abbreviations(
|
||||||
assert not missing
|
assert not missing
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.SWITCH])
|
||||||
async def test_no_implicit_state_topic_switch(
|
async def test_no_implicit_state_topic_switch(
|
||||||
hass, mqtt_mock_entry_no_yaml_config, caplog
|
hass, mqtt_mock_entry_no_yaml_config, caplog
|
||||||
):
|
):
|
||||||
|
@ -1214,6 +1236,7 @@ async def test_no_implicit_state_topic_switch(
|
||||||
assert state.state == STATE_UNKNOWN
|
assert state.state == STATE_UNKNOWN
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"mqtt_config",
|
"mqtt_config",
|
||||||
[
|
[
|
||||||
|
@ -1242,6 +1265,7 @@ async def test_complex_discovery_topic_prefix(
|
||||||
assert ("binary_sensor", "node1 object1") in hass.data[ALREADY_DISCOVERED]
|
assert ("binary_sensor", "node1 object1") in hass.data[ALREADY_DISCOVERED]
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [])
|
||||||
async def test_mqtt_integration_discovery_subscribe_unsubscribe(
|
async def test_mqtt_integration_discovery_subscribe_unsubscribe(
|
||||||
hass, mqtt_client_mock, mqtt_mock_entry_no_yaml_config
|
hass, mqtt_client_mock, mqtt_mock_entry_no_yaml_config
|
||||||
):
|
):
|
||||||
|
@ -1283,6 +1307,7 @@ async def test_mqtt_integration_discovery_subscribe_unsubscribe(
|
||||||
assert not mqtt_client_mock.unsubscribe.called
|
assert not mqtt_client_mock.unsubscribe.called
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [])
|
||||||
async def test_mqtt_discovery_unsubscribe_once(
|
async def test_mqtt_discovery_unsubscribe_once(
|
||||||
hass, mqtt_client_mock, mqtt_mock_entry_no_yaml_config
|
hass, mqtt_client_mock, mqtt_mock_entry_no_yaml_config
|
||||||
):
|
):
|
||||||
|
|
|
@ -28,6 +28,7 @@ from homeassistant.const import (
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -74,6 +75,13 @@ 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
|
||||||
|
|
||||||
|
|
||||||
async def test_fail_setup_if_no_command_topic(
|
async def test_fail_setup_if_no_command_topic(
|
||||||
hass, caplog, mqtt_mock_entry_no_yaml_config
|
hass, caplog, mqtt_mock_entry_no_yaml_config
|
||||||
):
|
):
|
||||||
|
|
|
@ -29,6 +29,7 @@ from homeassistant.const import (
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -75,6 +76,13 @@ 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(
|
async def async_turn_on(
|
||||||
hass,
|
hass,
|
||||||
entity_id=ENTITY_MATCH_ALL,
|
entity_id=ENTITY_MATCH_ALL,
|
||||||
|
|
|
@ -22,6 +22,7 @@ from homeassistant.const import (
|
||||||
EVENT_HOMEASSISTANT_STARTED,
|
EVENT_HOMEASSISTANT_STARTED,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.core import CoreState, HomeAssistant, callback
|
from homeassistant.core import CoreState, HomeAssistant, callback
|
||||||
|
@ -51,6 +52,16 @@ class RecordCallsPartial(partial):
|
||||||
__name__ = "RecordCallPartialTest"
|
__name__ = "RecordCallPartialTest"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def sensor_platforms_only():
|
||||||
|
"""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)
|
@pytest.fixture(autouse=True)
|
||||||
def mock_storage(hass_storage):
|
def mock_storage(hass_storage):
|
||||||
"""Autouse hass_storage for the TestCase tests."""
|
"""Autouse hass_storage for the TestCase tests."""
|
||||||
|
@ -1362,6 +1373,7 @@ async def test_setup_override_configuration(hass, caplog, tmp_path):
|
||||||
assert calls_username_password_set[0][1] == "somepassword"
|
assert calls_username_password_set[0][1] == "somepassword"
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.LIGHT])
|
||||||
async def test_setup_manual_mqtt_with_platform_key(hass, caplog):
|
async def test_setup_manual_mqtt_with_platform_key(hass, caplog):
|
||||||
"""Test set up a manual MQTT item with a platform key."""
|
"""Test set up a manual MQTT item with a platform key."""
|
||||||
config = {"platform": "mqtt", "name": "test", "command_topic": "test-topic"}
|
config = {"platform": "mqtt", "name": "test", "command_topic": "test-topic"}
|
||||||
|
@ -1372,6 +1384,7 @@ async def test_setup_manual_mqtt_with_platform_key(hass, caplog):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.LIGHT])
|
||||||
async def test_setup_manual_mqtt_with_invalid_config(hass, caplog):
|
async def test_setup_manual_mqtt_with_invalid_config(hass, caplog):
|
||||||
"""Test set up a manual MQTT item with an invalid config."""
|
"""Test set up a manual MQTT item with an invalid config."""
|
||||||
config = {"name": "test"}
|
config = {"name": "test"}
|
||||||
|
@ -2013,6 +2026,7 @@ async def test_mqtt_ws_get_device_debug_info(
|
||||||
assert response["result"] == expected_result
|
assert response["result"] == expected_result
|
||||||
|
|
||||||
|
|
||||||
|
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.CAMERA])
|
||||||
async def test_mqtt_ws_get_device_debug_info_binary(
|
async def test_mqtt_ws_get_device_debug_info_binary(
|
||||||
hass, device_reg, hass_ws_client, mqtt_mock_entry_no_yaml_config
|
hass, device_reg, hass_ws_client, mqtt_mock_entry_no_yaml_config
|
||||||
):
|
):
|
||||||
|
|
|
@ -29,7 +29,7 @@ from homeassistant.components.vacuum import (
|
||||||
ATTR_STATUS,
|
ATTR_STATUS,
|
||||||
VacuumEntityFeature,
|
VacuumEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_NAME, CONF_PLATFORM, STATE_OFF, STATE_ON
|
from homeassistant.const import CONF_NAME, CONF_PLATFORM, STATE_OFF, STATE_ON, Platform
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .test_common import (
|
from .test_common import (
|
||||||
|
@ -89,6 +89,13 @@ DEFAULT_CONFIG = {
|
||||||
DEFAULT_CONFIG_2 = {vacuum.DOMAIN: {"platform": "mqtt", "name": "test"}}
|
DEFAULT_CONFIG_2 = {vacuum.DOMAIN: {"platform": "mqtt", "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
|
||||||
|
|
||||||
|
|
||||||
async def test_default_supported_features(hass, mqtt_mock_entry_with_yaml_config):
|
async def test_default_supported_features(hass, mqtt_mock_entry_with_yaml_config):
|
||||||
"""Test that the correct supported features."""
|
"""Test that the correct supported features."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
|
|
|
@ -209,6 +209,7 @@ from homeassistant.const import (
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -251,6 +252,13 @@ 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
|
||||||
|
|
||||||
|
|
||||||
async def test_fail_setup_if_no_command_topic(hass, mqtt_mock_entry_no_yaml_config):
|
async def test_fail_setup_if_no_command_topic(hass, mqtt_mock_entry_no_yaml_config):
|
||||||
"""Test if command fails with command topic."""
|
"""Test if command fails with command topic."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
|
|
|
@ -103,6 +103,7 @@ from homeassistant.const import (
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -150,6 +151,13 @@ 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
|
||||||
|
|
||||||
|
|
||||||
class JsonValidator:
|
class JsonValidator:
|
||||||
"""Helper to compare JSON."""
|
"""Helper to compare JSON."""
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ from homeassistant.const import (
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -90,6 +91,13 @@ 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(
|
@pytest.mark.parametrize(
|
||||||
"test_config",
|
"test_config",
|
||||||
[
|
[
|
||||||
|
|
|
@ -18,6 +18,7 @@ from homeassistant.const import (
|
||||||
ATTR_ASSUMED_STATE,
|
ATTR_ASSUMED_STATE,
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
ATTR_SUPPORTED_FEATURES,
|
ATTR_SUPPORTED_FEATURES,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -58,6 +59,13 @@ DEFAULT_CONFIG = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@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
|
||||||
|
|
||||||
|
|
||||||
async def test_controlling_state_via_topic(hass, mqtt_mock_entry_with_yaml_config):
|
async def test_controlling_state_via_topic(hass, mqtt_mock_entry_with_yaml_config):
|
||||||
"""Test the controlling state via topic."""
|
"""Test the controlling state via topic."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
|
|
|
@ -23,6 +23,7 @@ from homeassistant.const import (
|
||||||
ATTR_ASSUMED_STATE,
|
ATTR_ASSUMED_STATE,
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -64,6 +65,13 @@ 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
|
||||||
|
|
||||||
|
|
||||||
async def test_run_number_setup(hass, mqtt_mock_entry_with_yaml_config):
|
async def test_run_number_setup(hass, mqtt_mock_entry_with_yaml_config):
|
||||||
"""Test that it fetches the given payload."""
|
"""Test that it fetches the given payload."""
|
||||||
topic = "test/number"
|
topic = "test/number"
|
||||||
|
|
|
@ -5,7 +5,7 @@ from unittest.mock import patch
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import scene
|
from homeassistant.components import scene
|
||||||
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON, STATE_UNKNOWN
|
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON, STATE_UNKNOWN, Platform
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -34,6 +34,13 @@ 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
|
||||||
|
|
||||||
|
|
||||||
async def test_sending_mqtt_commands(hass, mqtt_mock_entry_with_yaml_config):
|
async def test_sending_mqtt_commands(hass, mqtt_mock_entry_with_yaml_config):
|
||||||
"""Test the sending MQTT commands."""
|
"""Test the sending MQTT commands."""
|
||||||
fake_state = ha.State("scene.test", STATE_UNKNOWN)
|
fake_state = ha.State("scene.test", STATE_UNKNOWN)
|
||||||
|
|
|
@ -13,7 +13,12 @@ from homeassistant.components.select import (
|
||||||
DOMAIN as SELECT_DOMAIN,
|
DOMAIN as SELECT_DOMAIN,
|
||||||
SERVICE_SELECT_OPTION,
|
SERVICE_SELECT_OPTION,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_ASSUMED_STATE, ATTR_ENTITY_ID, STATE_UNKNOWN
|
from homeassistant.const import (
|
||||||
|
ATTR_ASSUMED_STATE,
|
||||||
|
ATTR_ENTITY_ID,
|
||||||
|
STATE_UNKNOWN,
|
||||||
|
Platform,
|
||||||
|
)
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -59,6 +64,13 @@ 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
|
||||||
|
|
||||||
|
|
||||||
async def test_run_select_setup(hass, mqtt_mock_entry_with_yaml_config):
|
async def test_run_select_setup(hass, mqtt_mock_entry_with_yaml_config):
|
||||||
"""Test that it fetches the given payload."""
|
"""Test that it fetches the given payload."""
|
||||||
topic = "test/select"
|
topic = "test/select"
|
||||||
|
|
|
@ -14,6 +14,7 @@ from homeassistant.const import (
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
TEMP_FAHRENHEIT,
|
TEMP_FAHRENHEIT,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
@ -72,6 +73,13 @@ 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
|
||||||
|
|
||||||
|
|
||||||
async def test_setting_sensor_value_via_mqtt_message(
|
async def test_setting_sensor_value_via_mqtt_message(
|
||||||
hass, mqtt_mock_entry_with_yaml_config
|
hass, mqtt_mock_entry_with_yaml_config
|
||||||
):
|
):
|
||||||
|
|
|
@ -15,6 +15,7 @@ from homeassistant.const import (
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -55,6 +56,13 @@ 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, entity_id=ENTITY_MATCH_ALL, parameters={}) -> None:
|
async def async_turn_on(hass, entity_id=ENTITY_MATCH_ALL, parameters={}) -> None:
|
||||||
"""Turn all or specified siren on."""
|
"""Turn all or specified siren on."""
|
||||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
|
||||||
|
|
|
@ -31,6 +31,7 @@ from homeassistant.const import (
|
||||||
CONF_PLATFORM,
|
CONF_PLATFORM,
|
||||||
ENTITY_MATCH_ALL,
|
ENTITY_MATCH_ALL,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -87,6 +88,13 @@ DEFAULT_CONFIG_2 = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@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
|
||||||
|
|
||||||
|
|
||||||
async def test_default_supported_features(hass, mqtt_mock_entry_with_yaml_config):
|
async def test_default_supported_features(hass, mqtt_mock_entry_with_yaml_config):
|
||||||
"""Test that the correct supported features."""
|
"""Test that the correct supported features."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
"""The tests for the MQTT subscription component."""
|
"""The tests for the MQTT subscription component."""
|
||||||
from unittest.mock import ANY
|
from unittest.mock import ANY, patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.mqtt.subscription import (
|
from homeassistant.components.mqtt.subscription import (
|
||||||
async_prepare_subscribe_topics,
|
async_prepare_subscribe_topics,
|
||||||
|
@ -11,6 +13,13 @@ from homeassistant.core import callback
|
||||||
from tests.common import async_fire_mqtt_message
|
from tests.common import async_fire_mqtt_message
|
||||||
|
|
||||||
|
|
||||||
|
@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, mqtt_mock_entry_no_yaml_config, caplog):
|
async def test_subscribe_topics(hass, mqtt_mock_entry_no_yaml_config, caplog):
|
||||||
"""Test subscription to topics."""
|
"""Test subscription to topics."""
|
||||||
await mqtt_mock_entry_no_yaml_config()
|
await mqtt_mock_entry_no_yaml_config()
|
||||||
|
|
|
@ -11,6 +11,7 @@ from homeassistant.const import (
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
@ -53,6 +54,13 @@ 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
|
||||||
|
|
||||||
|
|
||||||
async def test_controlling_state_via_topic(hass, mqtt_mock_entry_with_yaml_config):
|
async def test_controlling_state_via_topic(hass, mqtt_mock_entry_with_yaml_config):
|
||||||
"""Test the controlling state via topic."""
|
"""Test the controlling state via topic."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
|
|
|
@ -7,6 +7,7 @@ import pytest
|
||||||
|
|
||||||
from homeassistant.components.device_automation import DeviceAutomationType
|
from homeassistant.components.device_automation import DeviceAutomationType
|
||||||
from homeassistant.components.mqtt.const import DOMAIN as MQTT_DOMAIN
|
from homeassistant.components.mqtt.const import DOMAIN as MQTT_DOMAIN
|
||||||
|
from homeassistant.const import Platform
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -42,6 +43,13 @@ DEFAULT_TAG_SCAN_JSON = (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def binary_sensor_only():
|
||||||
|
"""Only setup the binary_sensor platform to speed up test."""
|
||||||
|
with patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR]):
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def device_reg(hass):
|
def device_reg(hass):
|
||||||
"""Return an empty, loaded, registry."""
|
"""Return an empty, loaded, registry."""
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
"""The tests for the MQTT automation."""
|
"""The tests for the MQTT automation."""
|
||||||
from unittest.mock import ANY
|
from unittest.mock import ANY, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -17,6 +17,13 @@ def calls(hass):
|
||||||
return async_mock_service(hass, "test", "automation")
|
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)
|
@pytest.fixture(autouse=True)
|
||||||
async def setup_comp(hass, mqtt_mock_entry_no_yaml_config):
|
async def setup_comp(hass, mqtt_mock_entry_no_yaml_config):
|
||||||
"""Initialize components."""
|
"""Initialize components."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue