mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Prepare MQTT common tests part3 (#90022)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""Test MQTT humidifiers."""
|
||||
import copy
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@@ -58,7 +59,6 @@ from .test_common import (
|
||||
help_test_setting_attribute_via_mqtt_json_message,
|
||||
help_test_setting_attribute_with_template,
|
||||
help_test_setting_blocked_attribute_via_mqtt_json_message,
|
||||
help_test_setup_manual_entity_from_yaml,
|
||||
help_test_unique_id,
|
||||
help_test_unload_config_entry_with_platform,
|
||||
help_test_update_with_json_attrs_bad_json,
|
||||
@@ -752,12 +752,11 @@ async def test_sending_mqtt_commands_and_explicit_optimistic(
|
||||
)
|
||||
async def test_encoding_subscribable_topics(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
topic,
|
||||
value,
|
||||
attribute,
|
||||
attribute_value,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
topic: str,
|
||||
value: str,
|
||||
attribute: str | None,
|
||||
attribute_value: Any,
|
||||
) -> None:
|
||||
"""Test handling of incoming encoded payload."""
|
||||
config = copy.deepcopy(DEFAULT_CONFIG[mqtt.DOMAIN][humidifier.DOMAIN])
|
||||
@@ -765,8 +764,7 @@ async def test_encoding_subscribable_topics(
|
||||
config[CONF_MODE_COMMAND_TOPIC] = "humidifier/some_mode_command_topic"
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_with_yaml_config,
|
||||
caplog,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
humidifier.DOMAIN,
|
||||
config,
|
||||
topic,
|
||||
@@ -1136,33 +1134,36 @@ async def test_discovery_update_attr(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"hass_config",
|
||||
[
|
||||
{
|
||||
mqtt.DOMAIN: {
|
||||
humidifier.DOMAIN: [
|
||||
{
|
||||
"name": "Test 1",
|
||||
"state_topic": "test-topic",
|
||||
"command_topic": "test_topic",
|
||||
"target_humidity_command_topic": "humidity-command-topic",
|
||||
"unique_id": "TOTALLY_UNIQUE",
|
||||
},
|
||||
{
|
||||
"name": "Test 2",
|
||||
"state_topic": "test-topic",
|
||||
"command_topic": "test_topic",
|
||||
"target_humidity_command_topic": "humidity-command-topic",
|
||||
"unique_id": "TOTALLY_UNIQUE",
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test unique_id option only creates one fan per id."""
|
||||
config = {
|
||||
mqtt.DOMAIN: {
|
||||
humidifier.DOMAIN: [
|
||||
{
|
||||
"name": "Test 1",
|
||||
"state_topic": "test-topic",
|
||||
"command_topic": "test_topic",
|
||||
"target_humidity_command_topic": "humidity-command-topic",
|
||||
"unique_id": "TOTALLY_UNIQUE",
|
||||
},
|
||||
{
|
||||
"name": "Test 2",
|
||||
"state_topic": "test-topic",
|
||||
"command_topic": "test_topic",
|
||||
"target_humidity_command_topic": "humidity-command-topic",
|
||||
"unique_id": "TOTALLY_UNIQUE",
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
await help_test_unique_id(
|
||||
hass, mqtt_mock_entry_with_yaml_config, humidifier.DOMAIN, config
|
||||
)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_humidifier(
|
||||
@@ -1274,11 +1275,11 @@ async def test_entity_device_info_remove(
|
||||
|
||||
|
||||
async def test_entity_id_update_subscriptions(
|
||||
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test MQTT subscriptions are managed when entity_id is updated."""
|
||||
await help_test_entity_id_update_subscriptions(
|
||||
hass, mqtt_mock_entry_with_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry_no_yaml_config, humidifier.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
@@ -1339,13 +1340,13 @@ async def test_entity_debug_info_message(
|
||||
)
|
||||
async def test_publishing_with_custom_encoding(
|
||||
hass: HomeAssistant,
|
||||
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
|
||||
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
service,
|
||||
topic,
|
||||
parameters,
|
||||
payload,
|
||||
template,
|
||||
service: str,
|
||||
topic: str,
|
||||
parameters: dict[str, Any],
|
||||
payload: str,
|
||||
template: str | None,
|
||||
) -> None:
|
||||
"""Test publishing MQTT payload with different encoding."""
|
||||
domain = humidifier.DOMAIN
|
||||
@@ -1355,7 +1356,7 @@ async def test_publishing_with_custom_encoding(
|
||||
|
||||
await help_test_publishing_with_custom_encoding(
|
||||
hass,
|
||||
mqtt_mock_entry_with_yaml_config,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
caplog,
|
||||
domain,
|
||||
config,
|
||||
@@ -1377,10 +1378,13 @@ async def test_reloadable(
|
||||
await help_test_reloadable(hass, mqtt_client_mock, domain, config)
|
||||
|
||||
|
||||
async def test_setup_manual_entity_from_yaml(hass: HomeAssistant) -> None:
|
||||
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||
async def test_setup_manual_entity_from_yaml(
|
||||
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
|
||||
) -> None:
|
||||
"""Test setup manual configured MQTT entity."""
|
||||
await mqtt_mock_entry_no_yaml_config()
|
||||
platform = humidifier.DOMAIN
|
||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user