Deprecate topic_template and payload_template for mqtt publish action (#122098)

Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
Jan Bouwhuis
2024-07-19 10:10:38 +02:00
committed by GitHub
parent 362c772d67
commit 5b4dd07189
4 changed files with 80 additions and 23 deletions

View File

@ -260,10 +260,12 @@ async def test_service_call_without_topic_does_not_publish(
assert not mqtt_mock.async_publish.called
async def test_service_call_with_topic_and_topic_template_does_not_publish(
# The use of a topic_template in an mqtt publish action call
# has been deprecated with HA Core 2024.8.0 and will be removed with HA Core 2025.2.0
async def test_mqtt_publish_action_call_with_topic_and_topic_template_does_not_publish(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None:
"""Test the service call with topic/topic template.
"""Test the mqtt publish action call with topic/topic template.
If both 'topic' and 'topic_template' are provided then fail.
"""
@ -284,10 +286,12 @@ async def test_service_call_with_topic_and_topic_template_does_not_publish(
assert not mqtt_mock.async_publish.called
async def test_service_call_with_invalid_topic_template_does_not_publish(
# The use of a topic_template in an mqtt publish action call
# has been deprecated with HA Core 2024.8.0 and will be removed with HA Core 2025.2.0
async def test_mqtt_action_call_with_invalid_topic_template_does_not_publish(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None:
"""Test the service call with a problematic topic template."""
"""Test the mqtt publish action call with a problematic topic template."""
mqtt_mock = await mqtt_mock_entry()
with pytest.raises(MqttCommandTemplateException) as exc:
await hass.services.async_call(
@ -307,10 +311,12 @@ async def test_service_call_with_invalid_topic_template_does_not_publish(
assert not mqtt_mock.async_publish.called
async def test_service_call_with_template_topic_renders_template(
# The use of a topic_template in an mqtt publish action call
# has been deprecated with HA Core 2024.8.0 and will be removed with HA Core 2025.2.0
async def test_mqtt_publish_action_call_with_template_topic_renders_template(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None:
"""Test the service call with rendered topic template.
"""Test the mqtt publish action call with rendered topic template.
If 'topic_template' is provided and 'topic' is not, then render it.
"""
@ -331,7 +337,7 @@ async def test_service_call_with_template_topic_renders_template(
async def test_service_call_with_template_topic_renders_invalid_topic(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None:
"""Test the service call with rendered, invalid topic template.
"""Test the action call with rendered, invalid topic template.
If a wildcard topic is rendered, then fail.
"""
@ -354,10 +360,12 @@ async def test_service_call_with_template_topic_renders_invalid_topic(
assert not mqtt_mock.async_publish.called
async def test_service_call_with_invalid_rendered_template_topic_doesnt_render_template(
# The use of a payload_template in an mqtt publish action call
# has been deprecated with HA Core 2024.8.0 and will be removed with HA Core 2025.2.0
async def test_action_call_with_invalid_rendered_payload_template_doesnt_render_template(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None:
"""Test the service call with unrendered template.
"""Test the action call with unrendered payload template.
If both 'payload' and 'payload_template' are provided then fail.
"""
@ -378,10 +386,12 @@ async def test_service_call_with_invalid_rendered_template_topic_doesnt_render_t
assert not mqtt_mock.async_publish.called
async def test_service_call_with_template_payload_renders_template(
# The use of a payload_template in an mqtt publish action call
# has been deprecated with HA Core 2024.8.0 and will be removed with HA Core 2025.2.0
async def test_mqtt_publish_action_call_with_template_payload_renders_template(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None:
"""Test the service call with rendered template.
"""Test the mqtt publish action call with rendered template.
If 'payload_template' is provided and 'payload' is not, then render it.
"""
@ -410,10 +420,12 @@ async def test_service_call_with_template_payload_renders_template(
mqtt_mock.reset_mock()
async def test_service_call_with_bad_template(
# The use of a payload_template in an mqtt publish action call
# has been deprecated with HA Core 2024.8.0 and will be removed with HA Core 2025.2.0
async def test_publish_action_call_with_bad_payload_template(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None:
"""Test the service call with a bad template does not publish."""
"""Test the mqtt publish action call with a bad template does not publish."""
mqtt_mock = await mqtt_mock_entry()
with pytest.raises(MqttCommandTemplateException) as exc:
await hass.services.async_call(
@ -432,10 +444,12 @@ async def test_service_call_with_bad_template(
)
async def test_service_call_with_payload_doesnt_render_template(
# The use of a payload_template in an mqtt publish action call
# has been deprecated with HA Core 2024.8.0 and will be removed with HA Core 2025.2.0
async def test_action_call_with_payload_doesnt_render_template(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None:
"""Test the service call with unrendered template.
"""Test the mqtt publish action call with an unrendered template.
If both 'payload' and 'payload_template' are provided then fail.
"""
@ -1626,10 +1640,12 @@ async def test_debug_info_qos_retain(
} in messages
# The use of a payload_template in an mqtt publish action call
# has been deprecated with HA Core 2024.8.0 and will be removed with HA Core 2025.2.0
async def test_publish_json_from_template(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
) -> None:
"""Test the publishing of call to services."""
"""Test the publishing of call to mqtt publish action."""
mqtt_mock = await mqtt_mock_entry()
test_str = "{'valid': 'python', 'invalid': 'json'}"