mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 02:38:10 +02:00
Prepare MQTT common tests part3 (#90022)
This commit is contained in:
@ -44,7 +44,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,
|
||||
@ -641,31 +640,34 @@ async def test_discovery_update_attr(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"hass_config",
|
||||
[
|
||||
{
|
||||
mqtt.DOMAIN: {
|
||||
siren.DOMAIN: [
|
||||
{
|
||||
"name": "Test 1",
|
||||
"state_topic": "test-topic",
|
||||
"command_topic": "command-topic",
|
||||
"unique_id": "TOTALLY_UNIQUE",
|
||||
},
|
||||
{
|
||||
"name": "Test 2",
|
||||
"state_topic": "test-topic",
|
||||
"command_topic": "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 siren per unique_id."""
|
||||
config = {
|
||||
mqtt.DOMAIN: {
|
||||
siren.DOMAIN: [
|
||||
{
|
||||
"name": "Test 1",
|
||||
"state_topic": "test-topic",
|
||||
"command_topic": "command-topic",
|
||||
"unique_id": "TOTALLY_UNIQUE",
|
||||
},
|
||||
{
|
||||
"name": "Test 2",
|
||||
"state_topic": "test-topic",
|
||||
"command_topic": "command-topic",
|
||||
"unique_id": "TOTALLY_UNIQUE",
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
await help_test_unique_id(
|
||||
hass, mqtt_mock_entry_with_yaml_config, siren.DOMAIN, config
|
||||
)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal_siren(
|
||||
@ -924,11 +926,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, siren.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry_no_yaml_config, siren.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
@ -976,13 +978,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 command templates and different encoding."""
|
||||
domain = siren.DOMAIN
|
||||
@ -991,7 +993,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,
|
||||
@ -1021,18 +1023,16 @@ async def test_reloadable(
|
||||
)
|
||||
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."""
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_with_yaml_config,
|
||||
caplog,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
siren.DOMAIN,
|
||||
DEFAULT_CONFIG[mqtt.DOMAIN][siren.DOMAIN],
|
||||
topic,
|
||||
@ -1042,10 +1042,13 @@ async def test_encoding_subscribable_topics(
|
||||
)
|
||||
|
||||
|
||||
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 = siren.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