Apply MQTT fixture types on platform tests (#87722)

* Apply MQTT fixture types on platform tests

* Add caplog type hint

* Add hass_ws_client type hint

* Add tmp_path type hint

* Add hass_client_no_auth type hint
This commit is contained in:
Jan Bouwhuis 2023-02-09 09:48:22 +01:00 committed by GitHub
parent b0cbe5cb69
commit df76e31cdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 1749 additions and 984 deletions

View file

@ -1,5 +1,6 @@
"""The tests for the MQTT scene platform."""
import copy
from pathlib import Path
from unittest.mock import patch
import pytest
@ -25,6 +26,7 @@ from .test_common import (
)
from tests.common import mock_restore_cache
from tests.typing import MqttMockHAClientGenerator
DEFAULT_CONFIG = {
mqtt.DOMAIN: {
@ -45,7 +47,7 @@ def scene_platform_only():
async def test_sending_mqtt_commands(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the sending MQTT commands."""
fake_state = State("scene.test", STATE_UNKNOWN)
@ -79,7 +81,7 @@ async def test_sending_mqtt_commands(
async def test_availability_when_connection_lost(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test availability after MQTT disconnection."""
await help_test_availability_when_connection_lost(
@ -88,7 +90,7 @@ async def test_availability_when_connection_lost(
async def test_availability_without_topic(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test availability without defined availability topic."""
await help_test_availability_without_topic(
@ -97,7 +99,7 @@ async def test_availability_without_topic(
async def test_default_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test availability by default payload with defined topic."""
config = {
@ -122,7 +124,7 @@ async def test_default_availability_payload(
async def test_custom_availability_payload(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test availability by custom payload with defined topic."""
config = {
@ -170,7 +172,9 @@ async def test_unique_id(hass: HomeAssistant, mqtt_mock_entry_with_yaml_config)
async def test_discovery_removal_scene(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test removal of discovered scene."""
data = '{ "name": "test",' ' "command_topic": "test_topic" }'
@ -180,7 +184,9 @@ async def test_discovery_removal_scene(
async def test_discovery_update_payload(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test update of discovered scene."""
config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][scene.DOMAIN])
@ -201,7 +207,9 @@ async def test_discovery_update_payload(
async def test_discovery_update_unchanged_scene(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test update of discovered scene."""
data1 = '{ "name": "Beer",' ' "command_topic": "test_topic" }'
@ -220,7 +228,9 @@ async def test_discovery_update_unchanged_scene(
@pytest.mark.no_fail_on_log_exception
async def test_discovery_broken(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test handling of bad discovery message."""
data1 = '{ "name": "Beer" }'
@ -231,7 +241,10 @@ async def test_discovery_broken(
async def test_reloadable(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog, tmp_path
hass: HomeAssistant,
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
tmp_path: Path,
) -> None:
"""Test reloading the MQTT platform."""
domain = scene.DOMAIN
@ -249,7 +262,9 @@ async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
async def test_unload_entry(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, tmp_path
hass: HomeAssistant,
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
tmp_path: Path,
) -> None:
"""Test unloading the config entry."""
domain = scene.DOMAIN