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
29 changed files with 1749 additions and 984 deletions

View File

@@ -1,5 +1,6 @@
"""The tests for the MQTT siren platform."""
import copy
from pathlib import Path
from unittest.mock import patch
import pytest
@@ -51,6 +52,7 @@ from .test_common import (
)
from tests.common import async_fire_mqtt_message
from tests.typing import MqttMockHAClientGenerator
DEFAULT_CONFIG = {
mqtt.DOMAIN: {siren.DOMAIN: {"name": "test", "command_topic": "test-topic"}}
@@ -80,7 +82,7 @@ async def async_turn_off(hass, entity_id=ENTITY_MATCH_ALL) -> None:
async def test_controlling_state_via_topic(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the controlling state via topic."""
assert await async_setup_component(
@@ -117,7 +119,7 @@ async def test_controlling_state_via_topic(
async def test_sending_mqtt_commands_and_optimistic(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the sending MQTT commands in optimistic mode."""
assert await async_setup_component(
@@ -161,7 +163,9 @@ async def test_sending_mqtt_commands_and_optimistic(
async def test_controlling_state_via_topic_and_json_message(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
hass: HomeAssistant,
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test the controlling state via topic and JSON message."""
assert await async_setup_component(
@@ -202,7 +206,9 @@ async def test_controlling_state_via_topic_and_json_message(
async def test_controlling_state_and_attributes_with_json_message_without_template(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
hass: HomeAssistant,
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test the controlling state via topic and JSON message without a value template."""
assert await async_setup_component(
@@ -282,7 +288,7 @@ async def test_controlling_state_and_attributes_with_json_message_without_templa
async def test_filtering_not_supported_attributes_optimistic(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test setting attributes with support flags optimistic."""
config = {
@@ -367,7 +373,7 @@ async def test_filtering_not_supported_attributes_optimistic(
async def test_filtering_not_supported_attributes_via_state(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test setting attributes with support flags via state."""
config = {
@@ -446,7 +452,7 @@ async def test_filtering_not_supported_attributes_via_state(
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(
@@ -455,7 +461,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(
@@ -464,7 +470,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 = {
@@ -491,7 +497,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 = {
@@ -518,7 +524,7 @@ async def test_custom_availability_payload(
async def test_custom_state_payload(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the state payload."""
assert await async_setup_component(
@@ -557,7 +563,7 @@ async def test_custom_state_payload(
async def test_setting_attribute_via_mqtt_json_message(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_via_mqtt_json_message(
@@ -566,7 +572,7 @@ async def test_setting_attribute_via_mqtt_json_message(
async def test_setting_blocked_attribute_via_mqtt_json_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_blocked_attribute_via_mqtt_json_message(
@@ -575,7 +581,7 @@ async def test_setting_blocked_attribute_via_mqtt_json_message(
async def test_setting_attribute_with_template(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the setting of attribute via MQTT with JSON payload."""
await help_test_setting_attribute_with_template(
@@ -584,7 +590,9 @@ async def test_setting_attribute_with_template(
async def test_update_with_json_attrs_not_dict(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
hass: HomeAssistant,
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_not_dict(
@@ -597,7 +605,9 @@ async def test_update_with_json_attrs_not_dict(
async def test_update_with_json_attrs_bad_json(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
hass: HomeAssistant,
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test attributes get extracted from a JSON result."""
await help_test_update_with_json_attrs_bad_json(
@@ -610,7 +620,9 @@ async def test_update_with_json_attrs_bad_json(
async def test_discovery_update_attr(
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 MQTTAttributes."""
await help_test_discovery_update_attr(
@@ -648,7 +660,9 @@ async def test_unique_id(hass: HomeAssistant, mqtt_mock_entry_with_yaml_config)
async def test_discovery_removal_siren(
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 siren."""
data = (
@@ -662,7 +676,9 @@ async def test_discovery_removal_siren(
async def test_discovery_update_siren_topic_template(
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 siren."""
config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN])
@@ -699,7 +715,9 @@ async def test_discovery_update_siren_topic_template(
async def test_discovery_update_siren_template(
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 siren."""
config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN])
@@ -734,7 +752,9 @@ async def test_discovery_update_siren_template(
async def test_command_templates(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
hass: HomeAssistant,
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test siren with command templates optimistic."""
config1 = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN])
@@ -816,7 +836,9 @@ async def test_command_templates(
async def test_discovery_update_unchanged_siren(
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 siren."""
data1 = (
@@ -840,7 +862,9 @@ async def test_discovery_update_unchanged_siren(
@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" }'
@@ -855,7 +879,7 @@ async def test_discovery_broken(
async def test_entity_device_info_with_connection(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test MQTT siren device registry integration."""
await help_test_entity_device_info_with_connection(
@@ -864,7 +888,7 @@ async def test_entity_device_info_with_connection(
async def test_entity_device_info_with_identifier(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test MQTT siren device registry integration."""
await help_test_entity_device_info_with_identifier(
@@ -873,7 +897,7 @@ async def test_entity_device_info_with_identifier(
async def test_entity_device_info_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test device registry update."""
await help_test_entity_device_info_update(
@@ -882,7 +906,7 @@ async def test_entity_device_info_update(
async def test_entity_device_info_remove(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test device registry remove."""
await help_test_entity_device_info_remove(
@@ -891,7 +915,7 @@ async def test_entity_device_info_remove(
async def test_entity_id_update_subscriptions(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test MQTT subscriptions are managed when entity_id is updated."""
await help_test_entity_id_update_subscriptions(
@@ -900,7 +924,7 @@ async def test_entity_id_update_subscriptions(
async def test_entity_id_update_discovery_update(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test MQTT discovery update when entity_id is updated."""
await help_test_entity_id_update_discovery_update(
@@ -909,7 +933,7 @@ async def test_entity_id_update_discovery_update(
async def test_entity_debug_info_message(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test MQTT debug info."""
await help_test_entity_debug_info_message(
@@ -943,8 +967,8 @@ async def test_entity_debug_info_message(
)
async def test_publishing_with_custom_encoding(
hass: HomeAssistant,
mqtt_mock_entry_with_yaml_config,
caplog,
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
service,
topic,
parameters,
@@ -971,7 +995,10 @@ async def test_publishing_with_custom_encoding(
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 = siren.DOMAIN
@@ -989,8 +1016,8 @@ async def test_reloadable(
)
async def test_encoding_subscribable_topics(
hass: HomeAssistant,
mqtt_mock_entry_with_yaml_config,
caplog,
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
topic,
value,
attribute,
@@ -1018,7 +1045,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 = siren.DOMAIN