mirror of
https://github.com/home-assistant/core.git
synced 2025-08-01 03:35:09 +02:00
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:
@@ -25,6 +25,7 @@ If your light doesn't support color temp feature, omit `color_temp_template`.
|
||||
If your light doesn't support RGB feature, omit `(red|green|blue)_template`.
|
||||
"""
|
||||
import copy
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@@ -76,6 +77,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: {
|
||||
@@ -126,7 +128,9 @@ def light_platform_only():
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_setup_fails(hass: HomeAssistant, caplog, test_config) -> None:
|
||||
async def test_setup_fails(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, test_config
|
||||
) -> None:
|
||||
"""Test that setup fails with missing required configuration items."""
|
||||
assert not await async_setup_component(
|
||||
hass,
|
||||
@@ -168,7 +172,7 @@ async def test_rgb_light(hass: HomeAssistant, mqtt_mock_entry_with_yaml_config)
|
||||
|
||||
|
||||
async def test_state_change_via_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
|
||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test state change via topic."""
|
||||
assert await async_setup_component(
|
||||
@@ -223,7 +227,7 @@ async def test_state_change_via_topic(
|
||||
|
||||
|
||||
async def test_state_brightness_color_effect_temp_change_via_topic(
|
||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
|
||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test state, bri, color, effect, color temp change."""
|
||||
assert await async_setup_component(
|
||||
@@ -334,7 +338,7 @@ async def test_state_brightness_color_effect_temp_change_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 of command in optimistic mode."""
|
||||
fake_state = State(
|
||||
@@ -476,7 +480,7 @@ async def test_sending_mqtt_commands_and_optimistic(
|
||||
|
||||
|
||||
async def test_sending_mqtt_commands_non_optimistic_brightness_template(
|
||||
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."""
|
||||
assert await async_setup_component(
|
||||
@@ -701,7 +705,7 @@ async def test_flash(hass: HomeAssistant, mqtt_mock_entry_with_yaml_config) -> N
|
||||
|
||||
|
||||
async def test_transition(
|
||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
|
||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test for transition time being sent when included."""
|
||||
assert await async_setup_component(
|
||||
@@ -745,7 +749,7 @@ async def test_transition(
|
||||
|
||||
|
||||
async def test_invalid_values(
|
||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config
|
||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test that invalid values are ignored."""
|
||||
assert await async_setup_component(
|
||||
@@ -842,7 +846,7 @@ async def test_invalid_values(
|
||||
|
||||
|
||||
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(
|
||||
@@ -851,7 +855,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(
|
||||
@@ -860,7 +864,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(
|
||||
@@ -869,7 +873,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(
|
||||
@@ -878,7 +882,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(
|
||||
@@ -887,7 +891,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(
|
||||
@@ -900,7 +904,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(
|
||||
@@ -909,7 +913,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(
|
||||
@@ -922,7 +928,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(
|
||||
@@ -935,7 +943,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(
|
||||
@@ -979,7 +989,9 @@ async def test_unique_id(hass: HomeAssistant, mqtt_mock_entry_with_yaml_config)
|
||||
|
||||
|
||||
async def test_discovery_removal(
|
||||
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 mqtt_json lights."""
|
||||
data = (
|
||||
@@ -995,7 +1007,9 @@ async def test_discovery_removal(
|
||||
|
||||
|
||||
async def test_discovery_update_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."""
|
||||
config1 = {
|
||||
@@ -1020,7 +1034,9 @@ async def test_discovery_update_light(
|
||||
|
||||
|
||||
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 = (
|
||||
@@ -1046,7 +1062,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" }'
|
||||
@@ -1064,7 +1082,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(
|
||||
@@ -1073,7 +1091,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(
|
||||
@@ -1082,7 +1100,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(
|
||||
@@ -1091,7 +1109,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(
|
||||
@@ -1100,7 +1118,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(
|
||||
@@ -1109,7 +1127,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(
|
||||
@@ -1118,7 +1136,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."""
|
||||
config = {
|
||||
@@ -1143,7 +1161,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 = {
|
||||
@@ -1192,8 +1210,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,
|
||||
@@ -1225,7 +1243,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
|
||||
@@ -1243,8 +1264,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,
|
||||
@@ -1276,7 +1297,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
|
||||
|
Reference in New Issue
Block a user