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

@ -169,6 +169,7 @@ mqtt:
"""
import copy
from pathlib import Path
from unittest.mock import call, patch
import pytest
@ -228,6 +229,7 @@ from .test_common import (
from tests.common import async_fire_mqtt_message, mock_restore_cache
from tests.components.light import common
from tests.typing import MqttMockHAClientGenerator
DEFAULT_CONFIG = {
mqtt.DOMAIN: {light.DOMAIN: {"name": "test", "command_topic": "test-topic"}}
@ -253,7 +255,7 @@ async def test_fail_setup_if_no_command_topic(hass: HomeAssistant, caplog) -> No
async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test if there is no color and brightness if no topic."""
assert await async_setup_component(
@ -312,7 +314,7 @@ async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(
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 of the state via topic."""
config = {
@ -433,7 +435,9 @@ async def test_controlling_state_via_topic(
async def test_invalid_state_via_topic(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config, caplog
hass: HomeAssistant,
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test handling of empty data via topic."""
config = {
@ -559,7 +563,7 @@ async def test_invalid_state_via_topic(
async def test_brightness_controlling_scale(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the brightness controlling scale."""
assert await async_setup_component(
@ -609,7 +613,7 @@ async def test_brightness_controlling_scale(
async def test_brightness_from_rgb_controlling_scale(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the brightness controlling scale."""
assert await async_setup_component(
@ -651,7 +655,7 @@ async def test_brightness_from_rgb_controlling_scale(
async def test_controlling_state_via_topic_with_templates(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the setting of the state with a template."""
config = {
@ -753,7 +757,7 @@ async def test_controlling_state_via_topic_with_templates(
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 of command in optimistic mode."""
config = {
@ -942,7 +946,7 @@ async def test_sending_mqtt_commands_and_optimistic(
async def test_sending_mqtt_rgb_command_with_template(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the sending of RGB command with template."""
config = {
@ -981,7 +985,7 @@ async def test_sending_mqtt_rgb_command_with_template(
async def test_sending_mqtt_rgbw_command_with_template(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the sending of RGBW command with template."""
config = {
@ -1020,7 +1024,7 @@ async def test_sending_mqtt_rgbw_command_with_template(
async def test_sending_mqtt_rgbww_command_with_template(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the sending of RGBWW command with template."""
config = {
@ -1059,7 +1063,7 @@ async def test_sending_mqtt_rgbww_command_with_template(
async def test_sending_mqtt_color_temp_command_with_template(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the sending of Color Temp command with template."""
config = {
@ -1097,7 +1101,7 @@ async def test_sending_mqtt_color_temp_command_with_template(
async def test_on_command_first(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test on command being sent before brightness."""
config = {
@ -1135,7 +1139,7 @@ async def test_on_command_first(
async def test_on_command_last(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test on command being sent after brightness."""
config = {
@ -1172,7 +1176,7 @@ async def test_on_command_last(
async def test_on_command_brightness(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test on command being sent as only brightness."""
config = {
@ -1229,7 +1233,7 @@ async def test_on_command_brightness(
async def test_on_command_brightness_scaled(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test brightness scale."""
config = {
@ -1301,7 +1305,7 @@ async def test_on_command_brightness_scaled(
async def test_on_command_rgb(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test on command in RGB brightness mode."""
config = {
@ -1393,7 +1397,7 @@ async def test_on_command_rgb(
async def test_on_command_rgbw(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test on command in RGBW brightness mode."""
config = {
@ -1485,7 +1489,7 @@ async def test_on_command_rgbw(
async def test_on_command_rgbww(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test on command in RGBWW brightness mode."""
config = {
@ -1577,7 +1581,7 @@ async def test_on_command_rgbww(
async def test_on_command_rgb_template(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test on command in RGB brightness mode with RGB template."""
config = {
@ -1616,7 +1620,7 @@ async def test_on_command_rgb_template(
async def test_on_command_rgbw_template(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test on command in RGBW brightness mode with RGBW template."""
config = {
@ -1654,7 +1658,7 @@ async def test_on_command_rgbw_template(
async def test_on_command_rgbww_template(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test on command in RGBWW brightness mode with RGBWW template."""
config = {
@ -1693,7 +1697,7 @@ async def test_on_command_rgbww_template(
async def test_on_command_white(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test sending commands for RGB + white light."""
config = {
@ -1772,7 +1776,7 @@ async def test_on_command_white(
async def test_explicit_color_mode(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test explicit color mode over mqtt."""
config = {
@ -1922,7 +1926,7 @@ async def test_explicit_color_mode(
async def test_explicit_color_mode_templated(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test templated explicit color mode over mqtt."""
config = {
@ -2005,7 +2009,7 @@ async def test_explicit_color_mode_templated(
async def test_white_state_update(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test state updates for RGB + white light."""
config = {
@ -2108,7 +2112,7 @@ async def test_effect(hass: HomeAssistant, mqtt_mock_entry_with_yaml_config) ->
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(
@ -2117,7 +2121,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(
@ -2126,7 +2130,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."""
await help_test_default_availability_payload(
@ -2135,7 +2139,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."""
await help_test_custom_availability_payload(
@ -2144,7 +2148,7 @@ async def test_custom_availability_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(
@ -2153,7 +2157,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(
@ -2166,7 +2170,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(
@ -2175,7 +2179,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(
@ -2188,7 +2194,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(
@ -2201,7 +2209,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(
@ -2239,7 +2249,9 @@ async def test_unique_id(hass: HomeAssistant, mqtt_mock_entry_with_yaml_config)
async def test_discovery_removal_light(
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 light."""
data = (
@ -2253,7 +2265,9 @@ async def test_discovery_removal_light(
async def test_discovery_ignores_extra_keys(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config, caplog
hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test discovery ignores extra keys that are not blocked."""
await mqtt_mock_entry_no_yaml_config()
@ -2269,7 +2283,9 @@ async def test_discovery_ignores_extra_keys(
async def test_discovery_update_light_topic_and_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 light."""
config1 = {
@ -2524,7 +2540,9 @@ async def test_discovery_update_light_topic_and_template(
async def test_discovery_update_light_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 light."""
config1 = {
@ -2737,7 +2755,9 @@ async def test_discovery_update_light_template(
async def test_discovery_update_unchanged_light(
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 light."""
data1 = (
@ -2760,7 +2780,9 @@ async def test_discovery_update_unchanged_light(
@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" }'
@ -2775,7 +2797,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 light device registry integration."""
await help_test_entity_device_info_with_connection(
@ -2784,7 +2806,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 light device registry integration."""
await help_test_entity_device_info_with_identifier(
@ -2793,7 +2815,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(
@ -2802,7 +2824,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(
@ -2811,7 +2833,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(
@ -2820,7 +2842,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(
@ -2829,7 +2851,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(
@ -2842,7 +2864,7 @@ async def test_entity_debug_info_message(
async def test_max_mireds(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test setting min_mireds and max_mireds."""
config = {
@ -2951,8 +2973,8 @@ async def test_max_mireds(
)
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,
@ -2986,7 +3008,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 = light.DOMAIN
@ -3028,8 +3053,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,
@ -3071,8 +3096,8 @@ async def test_encoding_subscribable_topics(
)
async def test_encoding_subscribable_topics_brightness(
hass: HomeAssistant,
mqtt_mock_entry_with_yaml_config,
caplog,
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
topic,
value,
attribute,
@ -3098,7 +3123,7 @@ async def test_encoding_subscribable_topics_brightness(
async def test_sending_mqtt_brightness_command_with_template(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the sending of Brightness command with template."""
config = {
@ -3136,7 +3161,7 @@ async def test_sending_mqtt_brightness_command_with_template(
async def test_sending_mqtt_effect_command_with_template(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the sending of Effect command with template."""
config = {
@ -3180,7 +3205,7 @@ async def test_sending_mqtt_effect_command_with_template(
async def test_sending_mqtt_hs_command_with_template(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the sending of HS Color command with template."""
config = {
@ -3216,7 +3241,7 @@ async def test_sending_mqtt_hs_command_with_template(
async def test_sending_mqtt_xy_command_with_template(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the sending of XY Color command with template."""
config = {
@ -3259,7 +3284,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 = light.DOMAIN