Prepare MQTT common tests part3 (#90022)
This commit is contained in:
parent
23f136e9d6
commit
d865440012
25 changed files with 1023 additions and 969 deletions
|
@ -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 typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
@ -33,6 +34,7 @@ from homeassistant.components import light, mqtt
|
|||
from homeassistant.components.mqtt.light.schema_basic import (
|
||||
MQTT_LIGHT_ATTRIBUTES_BLOCKED,
|
||||
)
|
||||
from homeassistant.components.mqtt.models import PublishPayloadType
|
||||
from homeassistant.const import (
|
||||
ATTR_ASSUMED_STATE,
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
|
@ -67,7 +69,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,
|
||||
|
@ -964,37 +965,40 @@ async def test_discovery_update_attr(
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"hass_config",
|
||||
[
|
||||
{
|
||||
mqtt.DOMAIN: {
|
||||
light.DOMAIN: [
|
||||
{
|
||||
"name": "Test 1",
|
||||
"schema": "template",
|
||||
"state_topic": "test-topic",
|
||||
"command_topic": "test_topic",
|
||||
"command_on_template": "on,{{ transition }}",
|
||||
"command_off_template": "off,{{ transition|d }}",
|
||||
"unique_id": "TOTALLY_UNIQUE",
|
||||
},
|
||||
{
|
||||
"name": "Test 2",
|
||||
"schema": "template",
|
||||
"state_topic": "test-topic2",
|
||||
"command_topic": "test_topic2",
|
||||
"command_on_template": "on,{{ transition }}",
|
||||
"command_off_template": "off,{{ transition|d }}",
|
||||
"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 light per unique_id."""
|
||||
config = {
|
||||
mqtt.DOMAIN: {
|
||||
light.DOMAIN: [
|
||||
{
|
||||
"name": "Test 1",
|
||||
"schema": "template",
|
||||
"state_topic": "test-topic",
|
||||
"command_topic": "test_topic",
|
||||
"command_on_template": "on,{{ transition }}",
|
||||
"command_off_template": "off,{{ transition|d }}",
|
||||
"unique_id": "TOTALLY_UNIQUE",
|
||||
},
|
||||
{
|
||||
"name": "Test 2",
|
||||
"schema": "template",
|
||||
"state_topic": "test-topic2",
|
||||
"command_topic": "test_topic2",
|
||||
"command_on_template": "on,{{ transition }}",
|
||||
"command_off_template": "off,{{ transition|d }}",
|
||||
"unique_id": "TOTALLY_UNIQUE",
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
await help_test_unique_id(
|
||||
hass, mqtt_mock_entry_with_yaml_config, light.DOMAIN, config
|
||||
)
|
||||
await help_test_unique_id(hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN)
|
||||
|
||||
|
||||
async def test_discovery_removal(
|
||||
|
@ -1127,11 +1131,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, light.DOMAIN, DEFAULT_CONFIG
|
||||
hass, mqtt_mock_entry_no_yaml_config, light.DOMAIN, DEFAULT_CONFIG
|
||||
)
|
||||
|
||||
|
||||
|
@ -1219,15 +1223,15 @@ async def test_max_mireds(
|
|||
)
|
||||
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,
|
||||
tpl_par,
|
||||
tpl_output,
|
||||
service: str,
|
||||
topic: str,
|
||||
parameters: dict[str, Any],
|
||||
payload: str,
|
||||
template: str | None,
|
||||
tpl_par: str,
|
||||
tpl_output: PublishPayloadType,
|
||||
) -> None:
|
||||
"""Test publishing MQTT payload with different encoding."""
|
||||
domain = light.DOMAIN
|
||||
|
@ -1237,7 +1241,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,
|
||||
|
@ -1269,12 +1273,11 @@ 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,
|
||||
init_payload,
|
||||
) -> None:
|
||||
"""Test handling of incoming encoded payload."""
|
||||
|
@ -1282,8 +1285,7 @@ async def test_encoding_subscribable_topics(
|
|||
config["state_template"] = "{{ value }}"
|
||||
await help_test_encoding_subscribable_topics(
|
||||
hass,
|
||||
mqtt_mock_entry_with_yaml_config,
|
||||
caplog,
|
||||
mqtt_mock_entry_no_yaml_config,
|
||||
light.DOMAIN,
|
||||
config,
|
||||
topic,
|
||||
|
@ -1294,10 +1296,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 = light.DOMAIN
|
||||
await help_test_setup_manual_entity_from_yaml(hass, DEFAULT_CONFIG)
|
||||
assert hass.states.get(f"{platform}.test")
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue