core/tests/components/mqtt/conftest.py

39 lines
1.1 KiB
Python
Raw Normal View History

"""Test fixtures for mqtt component."""
from collections.abc import Generator
from random import getrandbits
Allow MQTT device based auto discovery (#109030) * Add MQTT device based auto discovery * Respect override of component options over shared ones * Add state_topic, command_topic, qos and encoding as shared options * Add shared option test * Rename device.py to schemas.py * Remove unused legacy `platform` attribute to avoid confusion * Split validation device and origin info * Require `origin` info on device based discovery * Log origin info for only once for device discovery * Fix tests and linters * ruff * speed up _replace_all_abbreviations * Fix imports and merging errors - add slots attr * Fix unrelated const changes * More unrelated changes * join string * fix merge * Undo move * Adjust logger statement * fix task storm to load platforms * Revert "fix task storm to load platforms" This reverts commit 8f12a5f2511ab872880a186f5a4605c8bae80c7d. * bail if logging is disabled * Correct mixup object_id and node_id * Auto migrate entities to device discovery * Add device discovery test for device_trigger * Add migration support for non entity platforms * Use helper to remove discovery payload * Fix tests after update branch * Add discovery migration test * Refactor * Repair after rebase * Fix discovery is broken after migration * Improve comments * More comment improvements * Split long lines * Add comment to indicate payload dict can be empty * typo * Add walrus and update comment * Add tag to migration test * Join try blocks * Refactor * Cleanup not used attribute * Refactor * Move _replace_all_abbreviations out of try block --------- Co-authored-by: J. Nick Koston <nick@koston.org>
2024-05-29 09:12:05 +00:00
from unittest.mock import AsyncMock, patch
import pytest
from tests.components.light.conftest import mock_light_profiles # noqa: F401
@pytest.fixture(autouse=True)
def patch_hass_config(mock_hass_config: None) -> None:
2023-03-16 15:54:26 +00:00
"""Patch configuration.yaml."""
@pytest.fixture
def temp_dir_prefix() -> str:
"""Set an alternate temp dir prefix."""
return "test"
@pytest.fixture
def mock_temp_dir(temp_dir_prefix: str) -> Generator[None, None, str]:
"""Mock the certificate temp directory."""
with patch(
# Patch temp dir name to avoid tests fail running in parallel
"homeassistant.components.mqtt.util.TEMP_DIR_NAME",
f"home-assistant-mqtt-{temp_dir_prefix}-{getrandbits(10):03x}",
) as mocked_temp_dir:
yield mocked_temp_dir
Allow MQTT device based auto discovery (#109030) * Add MQTT device based auto discovery * Respect override of component options over shared ones * Add state_topic, command_topic, qos and encoding as shared options * Add shared option test * Rename device.py to schemas.py * Remove unused legacy `platform` attribute to avoid confusion * Split validation device and origin info * Require `origin` info on device based discovery * Log origin info for only once for device discovery * Fix tests and linters * ruff * speed up _replace_all_abbreviations * Fix imports and merging errors - add slots attr * Fix unrelated const changes * More unrelated changes * join string * fix merge * Undo move * Adjust logger statement * fix task storm to load platforms * Revert "fix task storm to load platforms" This reverts commit 8f12a5f2511ab872880a186f5a4605c8bae80c7d. * bail if logging is disabled * Correct mixup object_id and node_id * Auto migrate entities to device discovery * Add device discovery test for device_trigger * Add migration support for non entity platforms * Use helper to remove discovery payload * Fix tests after update branch * Add discovery migration test * Refactor * Repair after rebase * Fix discovery is broken after migration * Improve comments * More comment improvements * Split long lines * Add comment to indicate payload dict can be empty * typo * Add walrus and update comment * Add tag to migration test * Join try blocks * Refactor * Cleanup not used attribute * Refactor * Move _replace_all_abbreviations out of try block --------- Co-authored-by: J. Nick Koston <nick@koston.org>
2024-05-29 09:12:05 +00:00
@pytest.fixture
def tag_mock() -> Generator[AsyncMock, None, None]:
"""Fixture to mock tag."""
with patch("homeassistant.components.tag.async_scan_tag") as mock_tag:
yield mock_tag